/** Add a child to the tree t. If child is a flat tree (a list), make all * in list children of t. Warning: if t has no children, but child does * and child isNil then you can decide it is ok to move children to t via * t.children = child.children; i.e., without copying the array. Just * make sure that this is consistent with have the user will build * ASTs. */ @Override public void addChild(Object t, Object child) { if ( t!=null && child!=null ) { ((Tree)t).addChild((Tree)child); } }
/** Add a child to the tree t. If child is a flat tree (a list), make all * in list children of t. Warning: if t has no children, but child does * and child isNil then you can decide it is ok to move children to t via * t.children = child.children; i.e., without copying the array. Just * make sure that this is consistent with have the user will build * ASTs. */ public void addChild(Object t, Object child) { if ( t!=null && child!=null ) { ((Tree)t).addChild((Tree)child); } }
/** Add a child to the tree t. If child is a flat tree (a list), make all * in list children of t. Warning: if t has no children, but child does * and child isNil then you can decide it is ok to move children to t via * t.children = child.children; i.e., without copying the array. Just * make sure that this is consistent with have the user will build * ASTs. */ @Override public void addChild(Object t, Object child) { if ( t!=null && child!=null ) { ((Tree)t).addChild((Tree)child); } }
/** Add a child to the tree t. If child is a flat tree (a list), make all * in list children of t. Warning: if t has no children, but child does * and child isNil then you can decide it is ok to move children to t via * t.children = child.children; i.e., without copying the array. Just * make sure that this is consistent with have the user will build * ASTs. */ @Override public void addChild(Object t, Object child) { if ( t!=null && child!=null ) { ((Tree)t).addChild((Tree)child); } }
/** Add a child to the tree t. If child is a flat tree (a list), make all * in list children of t. Warning: if t has no children, but child does * and child isNil then you can decide it is ok to move children to t via * t.children = child.children; i.e., without copying the array. Just * make sure that this is consistent with have the user will build * ASTs. */ @Override public void addChild(Object t, Object child) { if ( t!=null && child!=null ) { ((Tree)t).addChild((Tree)child); } }
/** Add a child to the tree t. If child is a flat tree (a list), make all * in list children of t. Warning: if t has no children, but child does * and child isNil then you can decide it is ok to move children to t via * t.children = child.children; i.e., without copying the array. Just * make sure that this is consistent with have the user will build * ASTs. */ @Override public void addChild(Object t, Object child) { if ( t!=null && child!=null ) { ((Tree)t).addChild((Tree)child); } }
private Tree generateUpdateStatementTree(Object updateKey, Object entityName, Object aliasClause, Object setClause, Object whereClause) { Tree result = new CommonTree(); EntityNameTree entityNameTree = (EntityNameTree) entityName; for ( int i = 0; i < entityNameTree.getEntityCount(); i++ ) { Tree updateRoot = new CommonTree( (CommonTree) updateKey ); updateRoot.addChild( new EntityNameTree( entityNameTree, entityNameTree.getEntityName( i ) ) ); if ( aliasClause != null ) { updateRoot.addChild( (Tree) aliasClause ); } updateRoot.addChild( (Tree) setClause ); if ( whereClause != null ) { updateRoot.addChild( (Tree) whereClause ); } result.addChild( updateRoot ); } return result; }
private Tree generateDeleteStatementTree(Object deleteKey, Object entityName, Object aliasClause, Object whereClause) { Tree result = new CommonTree(); EntityNameTree entityNameTree = (EntityNameTree) entityName; for ( int i = 0; i < entityNameTree.getEntityCount(); i++ ) { Tree deleteRoot = new CommonTree( (CommonTree) deleteKey ); deleteRoot.addChild( new EntityNameTree( entityNameTree, entityNameTree.getEntityName( i ) ) ); if ( aliasClause != null ) { deleteRoot.addChild( (Tree) aliasClause ); } if ( whereClause != null ) { deleteRoot.addChild( (Tree) whereClause ); } result.addChild( deleteRoot ); } return result; }
public void bfs(Tree parent){ Iterator<V> ni = neighbors((V) parent.value()); while(ni.hasNext()){ V next = ni.next(); GraphMatrixVertex<V> vert = dict.get(next); if(!vert.isVisited()){ Tree newNode = new Tree(next); parent.addChild(newNode); newNode.bfs(this); } } }
int weight; // this should be you node traversal cost public LinkedList<Tree> bfs(Tree parent){ Iterator<V> ni = neighbors((V) parent.value()); LinkedList bestPath = null; int bestScore = 0xFFFFFFFF; while(ni.hasNext()){ V next = ni.next(); GraphMatrixVertex<V> vert = dict.get(next); if(!vert.isVisited()){ Tree newNode = new Tree(next); parent.addChild(newNode); LinkedList path = newNode.bfs(this); if(newNode.weight < bestScore){ bestScore = weight; bestPath = path; } } } weight = bestScore + this.weight; bestPath.addFirst(this); return path; }
private static Tree addNodeFixed(Tree tree, Label posTag, Label value, int index) { Tree posNode = new LabeledScoredTreeNode(posTag); posNode.setValue(posTag.value()); Tree valueNode = new LabeledScoredTreeNode(value); valueNode.setValue(value.value()); posNode.addChild(valueNode); tree.insertDtr(posNode, index); return tree; }
private Tree getChildList(Tree parent) { // nodes with no token are "nil" nodes in antlr, // which act as lists of children. Tree listNode = new CommonTree(); for (int childIndex = 0; childIndex < parent.getChildCount(); childIndex++) { listNode.addChild(parent.getChild(childIndex)); } return listNode; }
public void addEntityInGroupBy(String entityAlias) { Tree groupBy = queryTree.getAstGroupByNode(); if (groupBy != null) { groupBy.addChild(new PathNode(JPA2Lexer.T_SELECTED_ENTITY, entityAlias)); groupBy.freshenParentAndChildIndexes(); } }
private Tree generateSelecFromTree(Object selectClause, Object fromClause, List aliasList){ Tree result = new CommonTree( new CommonToken( SELECT_FROM, "SELECT_FROM" ) ); Tree selectTree = null; result.addChild( (Tree) fromClause ); if (selectClause == null && aliasList != null && aliasList.size() > 0) { selectTree = new CommonTree( new CommonToken( SELECT, "SELECT") ); Tree selectList = new CommonTree( new CommonToken( SELECT_LIST, "SELECT_LIST" ) ); for ( Iterator iterator = aliasList.iterator(); iterator.hasNext(); ) { String aliasName = (String) iterator.next(); Tree selectElement = new CommonTree( new CommonToken( SELECT_ITEM, "SELECT_ITEM" ) ); Tree aliasElement = new CommonTree( new CommonToken( ALIAS_REF, aliasName ) ); selectElement.addChild( aliasElement ); selectList.addChild( selectElement ); } selectTree.addChild( selectList ); } else { selectTree = (Tree) selectClause; } result.addChild( selectTree ); return result; }
public void addOrderByIdIfNotExists(PathEntityReference idReference) { Tree orderBy = queryTree.getAstTree().getFirstChildWithType(JPA2Lexer.T_ORDER_BY); if (orderBy != null) { return; } orderBy = new OrderByNode(JPA2Lexer.T_ORDER_BY); queryTree.getAstTree().addChild(orderBy); queryTree.getAstTree().freshenParentAndChildIndexes(); orderBy.addChild(new CommonTree(new CommonToken(JPA2Lexer.ORDER, "order"))); orderBy.addChild(new CommonTree(new CommonToken(JPA2Lexer.BY, "by"))); OrderByFieldNode orderByField = new OrderByFieldNode(JPA2Lexer.T_ORDER_BY_FIELD); orderByField.addChild(idReference.createNode()); orderByField.addChild(new CommonTree(new CommonToken(JPA2Lexer.DESC, "asc"))); orderByField.freshenParentAndChildIndexes(); orderBy.addChild(orderByField); orderBy.freshenParentAndChildIndexes(); }
/** * * @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) {
public static ASTNode getDotAST(String tableAlias, String fieldAlias) { ASTNode child = new ASTNode(new CommonToken(DOT, ".")); child.addChild(new ASTNode(new CommonToken(TOK_TABLE_OR_COL, "TOK_TABLE_OR_COL"))); child.getChild(0).addChild(new ASTNode(new CommonToken(Identifier, tableAlias))); child.addChild(new ASTNode(new CommonToken(Identifier, fieldAlias))); return child; }
public static ASTNode getDotAST(String tableAlias, String fieldAlias) { ASTNode child = new ASTNode(new CommonToken(DOT, ".")); child.addChild(new ASTNode(new CommonToken(TOK_TABLE_OR_COL, "TOK_TABLE_OR_COL"))); child.getChild(0).addChild(new ASTNode(new CommonToken(Identifier, tableAlias))); child.addChild(new ASTNode(new CommonToken(Identifier, fieldAlias))); return child; }
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++; } }