ASTNode getParentInWhereClause(ASTNode node) { if (node == null || node == root) { return null; } return (ASTNode) node.getParent(); }
ASTNode getParentInWhereClause(ASTNode node) { if (node == null || node == root) { return null; } return (ASTNode) node.getParent(); }
private ASTNode getQueryASTNode(ASTNode node) { while( node != null && node.getType() != HiveParser.TOK_QUERY ) { node = (ASTNode) node.getParent(); } return node; }
private ASTNode getQueryASTNode(ASTNode node) { while( node != null && node.getType() != HiveParser.TOK_QUERY ) { node = (ASTNode) node.getParent(); } return node; }
private boolean createDynPartSpec(ASTNode ast) { if(ast.getToken().getType() != HiveParser.TOK_CREATETABLE && ast.getToken().getType() != HiveParser.TOK_CREATE_MATERIALIZED_VIEW && ast.getToken().getType() != HiveParser.TOK_ALTER_MATERIALIZED_VIEW && tableHandle.getPartitionKeys().size() > 0 && (ast.getParent() != null && (ast.getParent().getType() == HiveParser.TOK_INSERT_INTO || ast.getParent().getType() == HiveParser.TOK_INSERT) || ast.getParent().getType() == HiveParser.TOK_DESTINATION || ast.getParent().getType() == HiveParser.TOK_ANALYZE)) { return true; } return false; } public TableSpec(Hive db, HiveConf conf, ASTNode ast, boolean allowDynamicPartitionsSpec,
private static void removeASTChild(ASTNode node) { Tree parent = node.getParent(); if (parent != null) { parent.deleteChild(node.getChildIndex()); node.setParent(null); } }
public ASTNode getOriginalSubQueryASTForRewrite() { return (operator.getType() == SubQueryType.NOT_EXISTS || operator.getType() == SubQueryType.NOT_IN ? (ASTNode) originalSQASTOrigin.getUsageNode().getParent() : originalSQASTOrigin.getUsageNode()); }
public ASTNode getOriginalSubQueryASTForRewrite() { return (operator.getType() == SubQueryType.NOT_EXISTS || operator.getType() == SubQueryType.NOT_IN ? (ASTNode) originalSQASTOrigin.getUsageNode().getParent() : originalSQASTOrigin.getUsageNode()); }
/** * Finds all columns and groups by table ref (if there is one). */ private void visit(ASTNode n) { if (n.getType() == HiveParser.TOK_TABLE_OR_COL) { ASTNode parent = (ASTNode) n.getParent(); if (parent != null && parent.getType() == HiveParser.DOT) { //the ref must be a table, so look for column name as right child of DOT if (parent.getParent() != null && parent.getParent().getType() == HiveParser.DOT) { //I don't think this can happen... but just in case throw new IllegalArgumentException("Found unexpected db.table.col reference in " + onClauseAsString); } addColumn2Table(n.getChild(0).getText(), parent.getChild(1).getText()); } else { //must be just a column name unresolvedColumns.add(n.getChild(0).getText()); } } if (n.getChildCount() == 0) { return; } for (Node child : n.getChildren()) { visit((ASTNode)child); } }
public static SubQueryType get(ASTNode opNode) throws SemanticException { if(opNode == null) { return SCALAR; } switch(opNode.getType()) { // opNode's type is always either KW_EXISTS or KW_IN never NOTEXISTS or NOTIN // to figure this out we need to check it's grand parent's parent case HiveParser.KW_EXISTS: if(opNode.getParent().getParent().getParent() != null && opNode.getParent().getParent().getParent().getType() == HiveParser.KW_NOT) { return NOT_EXISTS; } return EXISTS; case HiveParser.TOK_SUBQUERY_OP_NOTEXISTS: return NOT_EXISTS; case HiveParser.KW_IN: if(opNode.getParent().getParent().getParent() != null && opNode.getParent().getParent().getParent().getType() == HiveParser.KW_NOT) { return NOT_IN; } return IN; case HiveParser.TOK_SUBQUERY_OP_NOTIN: return NOT_IN; default: throw new SemanticException(SemanticAnalyzer.generateErrorMessage(opNode, "Operator not supported in SubQuery use.")); } } }
public static SubQueryType get(ASTNode opNode) throws SemanticException { if(opNode == null) { return SCALAR; } switch(opNode.getType()) { // opNode's type is always either KW_EXISTS or KW_IN never NOTEXISTS or NOTIN // to figure this out we need to check it's grand parent's parent case HiveParser.KW_EXISTS: if(opNode.getParent().getParent().getParent() != null && opNode.getParent().getParent().getParent().getType() == HiveParser.KW_NOT) { return NOT_EXISTS; } return EXISTS; case HiveParser.TOK_SUBQUERY_OP_NOTEXISTS: return NOT_EXISTS; case HiveParser.KW_IN: if(opNode.getParent().getParent().getParent() != null && opNode.getParent().getParent().getParent().getType() == HiveParser.KW_NOT) { return NOT_IN; } return IN; case HiveParser.TOK_SUBQUERY_OP_NOTIN: return NOT_IN; default: throw new SemanticException(SemanticAnalyzer.generateErrorMessage(opNode, "Operator not supported in SubQuery use.")); } } }
@Override public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context, ASTNode ast) throws SemanticException { if (ast.getType() == HiveParser.TOK_EXPLAIN) { int childCount = ast.getChildCount(); for (int i = 1; i < childCount; i++) { if (ast.getChild(i).getType() == HiveParser.KW_REOPTIMIZATION) { explainReOptimization = true; ast.deleteChild(i); break; } } if (explainReOptimization && firstExecution()) { Tree execTree = ast.getChild(0); execTree.setParent(ast.getParent()); ast.getParent().setChild(0, execTree); return (ASTNode) execTree; } } return ast; }
/** * finds all columns and groups by table ref (if there is one) */ private void visit(ASTNode n) { if(n.getType() == HiveParser.TOK_TABLE_OR_COL) { ASTNode parent = (ASTNode) n.getParent(); if(parent != null && parent.getType() == HiveParser.DOT) { //the ref must be a table, so look for column name as right child of DOT if(parent.getParent() != null && parent.getParent().getType() == HiveParser.DOT) { //I don't think this can happen... but just in case throw new IllegalArgumentException("Found unexpected db.table.col reference in " + onClauseAsString); } addColumn2Table(n.getChild(0).getText(), parent.getChild(1).getText()); } else { //must be just a column name unresolvedColumns.add(n.getChild(0).getText()); } } if(n.getChildCount() == 0) { return; } for(Node child : n.getChildren()) { visit((ASTNode)child); } } private void analyze() {
parentLoop: while(curNode.getParent() != null) { curNode = (ASTNode) curNode.getParent(); switch (curNode.getType()) { case HiveParser.TOK_SUBQUERY_EXPR: ASTNode insert = (ASTNode) curNode.getParent(); assert insert != null && insert.getType() == HiveParser.TOK_INSERT; ASTNode query = (ASTNode) insert.getParent(); assert query != null && query.getType() == HiveParser.TOK_QUERY;
private void analyzeAlterTableAddConstraint(ASTNode ast, String tableName) throws SemanticException { ASTNode parent = (ASTNode) ast.getParent(); ASTNode child = (ASTNode) ast.getChild(0); List<SQLPrimaryKey> primaryKeys = new ArrayList<SQLPrimaryKey>(); List<SQLForeignKey> foreignKeys = new ArrayList<SQLForeignKey>(); if (child.getToken().getType() == HiveParser.TOK_PRIMARY_KEY) { BaseSemanticAnalyzer.processPrimaryKeys(parent, child, primaryKeys); } else if (child.getToken().getType() == HiveParser.TOK_FOREIGN_KEY) { BaseSemanticAnalyzer.processForeignKeys(parent, child, foreignKeys); } AlterTableDesc alterTblDesc = new AlterTableDesc(tableName, primaryKeys, foreignKeys); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterTblDesc), conf)); }
static void checkForSubqueries(ASTNode node) throws SemanticException { // allow NOT but throw an error for rest if(node.getType() == HiveParser.TOK_SUBQUERY_EXPR && node.getParent().getType() != HiveParser.KW_NOT) { throw new CalciteSubquerySemanticException(ErrorMsg.UNSUPPORTED_SUBQUERY_EXPRESSION.getMsg( "Invalid subquery. Subquery in SELECT could only be top-level expression")); } for(int i=0; i<node.getChildCount(); i++) { checkForSubqueries((ASTNode)node.getChild(i)); } } /*
private void fixUpASTNoAggregateIncrementalRebuild(ASTNode newAST) throws SemanticException { // Replace INSERT OVERWRITE by INSERT INTO // AST tree will have this shape: // TOK_QUERY // TOK_FROM // ... // TOK_INSERT // TOK_DESTINATION <- THIS TOKEN IS REPLACED BY 'TOK_INSERT_INTO' // TOK_TAB // TOK_TABNAME // default.cmv_mat_view // TOK_SELECT // ... ASTNode dest = new ASTSearcher().simpleBreadthFirstSearch(newAST, HiveParser.TOK_QUERY, HiveParser.TOK_INSERT, HiveParser.TOK_DESTINATION); ASTNode newChild = (ASTNode) ParseDriver.adaptor.create( HiveParser.TOK_INSERT_INTO, "TOK_INSERT_INTO"); newChild.addChildren(dest.getChildren()); ASTNode destParent = (ASTNode) dest.getParent(); int childIndex = dest.childIndex; destParent.deleteChild(childIndex); destParent.insertChild(childIndex, newChild); }
private void analyzeAlterTableAddConstraint(ASTNode ast, String tableName) throws SemanticException { ASTNode parent = (ASTNode) ast.getParent(); String[] qualifiedTabName = getQualifiedTableName((ASTNode) parent.getChild(0));
List<PKInfo> pkInfos = new ArrayList<PKInfo>(); Map<String, FieldSchema> nametoFS = new HashMap<String, FieldSchema>(); Tree parent = ast.getParent();
ASTNode sqNode = (ASTNode) expr.getParent().getChild(1);