@Override public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t) { if ( parent!=null ) { ((Tree)parent).replaceChildren(startChildIndex, stopChildIndex, t); } } }
@Override public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t) { if ( parent!=null ) { ((Tree)parent).replaceChildren(startChildIndex, stopChildIndex, t); } } }
@Override public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t) { if ( parent!=null ) { ((Tree)parent).replaceChildren(startChildIndex, stopChildIndex, t); } } }
public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t) { if ( parent!=null ) { ((Tree)parent).replaceChildren(startChildIndex, stopChildIndex, t); } } }
@Override public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t) { if ( parent!=null ) { ((Tree)parent).replaceChildren(startChildIndex, stopChildIndex, t); } } }
@Override public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t) { if ( parent!=null ) { ((Tree)parent).replaceChildren(startChildIndex, stopChildIndex, t); } } }
/** * * @param selectAST Outer query selectAST * @param cubeql Cubequery Context * * Update the final alias in the outer select expressions * 1. Replace queriedAlias with finalAlias if both are not same * 2. If queriedAlias is missing add finalAlias as alias */ static void updateFinalAlias(ASTNode selectAST, CubeQueryContext cubeql) { for (int i = 0; i < selectAST.getChildCount(); i++) { ASTNode selectExpr = (ASTNode) selectAST.getChild(i); ASTNode aliasNode = HQLParser.findNodeByPath(selectExpr, Identifier); String finalAlias = cubeql.getSelectPhrases().get(i).getFinalAlias().replaceAll("`", ""); if (aliasNode != null) { String queryAlias = aliasNode.getText(); if (!queryAlias.equals(finalAlias)) { // replace the alias node ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, finalAlias)); selectAST.getChild(i).replaceChildren(selectExpr.getChildCount() - 1, selectExpr.getChildCount() - 1, newAliasNode); } } else { // add column alias ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, finalAlias)); selectAST.getChild(i).addChild(newAliasNode); } } } static Set<String> getColumnsFromCandidates(Collection<? extends Candidate> scSet) {
/** * * @param selectAST Outer query selectAST * @param cubeql Cubequery Context * * Update the final alias in the outer select expressions * 1. Replace queriedAlias with finalAlias if both are not same * 2. If queriedAlias is missing add finalAlias as alias */ static void updateFinalAlias(ASTNode selectAST, CubeQueryContext cubeql) { for (int i = 0; i < selectAST.getChildCount(); i++) { ASTNode selectExpr = (ASTNode) selectAST.getChild(i); ASTNode aliasNode = HQLParser.findNodeByPath(selectExpr, Identifier); String finalAlias = cubeql.getSelectPhrases().get(i).getFinalAlias().replaceAll("`", ""); if (aliasNode != null) { String queryAlias = aliasNode.getText(); if (!queryAlias.equals(finalAlias)) { // replace the alias node ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, finalAlias)); selectAST.getChild(i).replaceChildren(selectExpr.getChildCount() - 1, selectExpr.getChildCount() - 1, newAliasNode); } } else { // add column alias ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, finalAlias)); selectAST.getChild(i).addChild(newAliasNode); } } } static Set<String> getColumnsFromCandidates(Collection<? extends Candidate> scSet) {
treeNode.replaceChildren(childIndex, childIndex, getChildList(childNode)); childNode = treeNode.getChild(childIndex);
private void updateAnswerableSelectColumns() throws LensException { // update select AST with selected fields int currentChild = 0; for (int i = 0; i < getCubeQueryContext().getSelectAST().getChildCount(); i++) { ASTNode selectExpr = (ASTNode) queryAst.getSelectAST().getChild(currentChild); Set<String> exprCols = HQLParser.getColsInExpr(getCubeQueryContext().getAliasForTableName(getCube()), selectExpr); if (getStorageCandidate().getColumns().containsAll(exprCols)) { ASTNode aliasNode = HQLParser.findNodeByPath(selectExpr, HiveParser.Identifier); String alias = getCubeQueryContext().getSelectPhrases().get(i).getSelectAlias(); if (aliasNode != null) { String queryAlias = aliasNode.getText(); if (!queryAlias.equals(alias)) { // replace the alias node ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, alias)); queryAst.getSelectAST().getChild(currentChild) .replaceChildren(selectExpr.getChildCount() - 1, selectExpr.getChildCount() - 1, newAliasNode); } } else { // add column alias ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, alias)); queryAst.getSelectAST().getChild(currentChild).addChild(newAliasNode); } } else { queryAst.getSelectAST().deleteChild(currentChild); currentChild--; } currentChild++; } }
private void updateAnswerableSelectColumns() throws LensException { // update select AST with selected fields int currentChild = 0; for (int i = 0; i < getCubeQueryContext().getSelectAST().getChildCount(); i++) { ASTNode selectExpr = (ASTNode) queryAst.getSelectAST().getChild(currentChild); Set<String> exprCols = HQLParser.getColsInExpr(getCubeQueryContext().getAliasForTableName(getCube()), selectExpr); if (getStorageCandidate().getColumns().containsAll(exprCols)) { ASTNode aliasNode = HQLParser.findNodeByPath(selectExpr, HiveParser.Identifier); String alias = getCubeQueryContext().getSelectPhrases().get(i).getSelectAlias(); if (aliasNode != null) { String queryAlias = aliasNode.getText(); if (!queryAlias.equals(alias)) { // replace the alias node ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, alias)); queryAst.getSelectAST().getChild(currentChild) .replaceChildren(selectExpr.getChildCount() - 1, selectExpr.getChildCount() - 1, newAliasNode); } } else { // add column alias ASTNode newAliasNode = new ASTNode(new CommonToken(HiveParser.Identifier, alias)); queryAst.getSelectAST().getChild(currentChild).addChild(newAliasNode); } } else { queryAst.getSelectAST().deleteChild(currentChild); currentChild--; } currentChild++; } }