public Set<Dimension> rewriteDenormctx( CandidateFact cfact, Map<Dimension, CandidateDim> dimsToQuery, boolean replaceFact) throws LensException { Set<Dimension> refTbls = new HashSet<>(); if (!tableToRefCols.isEmpty()) { // pick referenced columns for fact if (cfact != null) { pickColumnsForTable(cfact.getName()); } // pick referenced columns for dimensions if (dimsToQuery != null && !dimsToQuery.isEmpty()) { for (CandidateDim cdim : dimsToQuery.values()) { pickColumnsForTable(cdim.getName()); } } // Replace picked reference in all the base trees replaceReferencedColumns(cfact, replaceFact); // Add the picked references to dimsToQuery for (PickedReference picked : pickedRefs) { if (isPickedFor(picked, cfact, dimsToQuery)) { refTbls.add( (Dimension) cubeql.getCubeTableForAlias(picked.getChainRef().getChainName())); cubeql.addColumnsQueried( picked.getChainRef().getChainName(), picked.getChainRef().getRefColumn()); } } } return refTbls; }
private void resolveClause(CubeQueryContext query, ASTNode node) throws LensException { if (node == null) { return; } int nodeType = node.getToken().getType(); if (nodeType == HiveParser.DOT) { String colName = HQLParser.getColName(node).toLowerCase(); if (!pickedReferences.containsKey(colName)) { return; } // No need to create a new node, // replace the table name identifier and column name identifier ASTNode tableNode = (ASTNode) node.getChild(0); ASTNode tabident = HQLParser.findNodeByPath(node, TOK_TABLE_OR_COL, Identifier); PickedReference refered = getPickedReference(colName, tabident.getText().toLowerCase()); if (refered == null) { return; } ASTNode newTableNode = new ASTNode( new CommonToken(HiveParser.Identifier, refered.getChainRef().getChainName())); tableNode.setChild(0, newTableNode); ASTNode newColumnNode = new ASTNode( new CommonToken(HiveParser.Identifier, refered.getChainRef().getRefColumn())); node.setChild(1, newColumnNode); } else { // recurse down for (int i = 0; i < node.getChildCount(); i++) { ASTNode child = (ASTNode) node.getChild(i); resolveClause(query, child); } } }