public static boolean isPartitionLevelStats(ASTNode tree) { boolean isPartitioned = false; ASTNode child = (ASTNode) tree.getChild(0); if (child.getChildCount() > 1) { child = (ASTNode) child.getChild(1); if (child.getToken().getType() == HiveParser.TOK_PARTSPEC) { isPartitioned = true; } } return isPartitioned; }
/** * Performs a descent of the leftmost branch of a tree, stopping when either a * node with a non-null token is found or the leaf level is encountered. * * @param tree * candidate node from which to start searching * * @return node at which descent stopped */ private static ASTNode findRootNonNullToken(ASTNode tree) { while ((tree.getToken() == null) && (tree.getChildCount() > 0)) { tree = (ASTNode) tree.getChild(0); } return tree; }
private String buildTriggerExpression(ASTNode ast) throws SemanticException { if (ast.getType() != HiveParser.TOK_TRIGGER_EXPRESSION || ast.getChildCount() == 0) { throw new SemanticException("Invalid trigger expression."); } StringBuilder builder = new StringBuilder(); for (int i = 0; i < ast.getChildCount(); ++i) { builder.append(ast.getChild(i).getText()); // Don't strip quotes. builder.append(' '); } builder.deleteCharAt(builder.length() - 1); return builder.toString(); }
public static List<PrincipalDesc> analyzePrincipalListDef(ASTNode node) { List<PrincipalDesc> principalList = new ArrayList<PrincipalDesc>(); for (int i = 0; i < node.getChildCount(); i++) { principalList.add(getPrincipalDesc((ASTNode) node.getChild(i))); } return principalList; }
static void addGroupExpressionToFront(ASTNode gBy, ASTNode expr) { ASTNode grpExpr = (ASTNode) ParseDriver.adaptor.create(HiveParser.TOK_GROUPING_SETS_EXPRESSION, "TOK_GROUPING_SETS_EXPRESSION"); grpExpr.addChild(expr); List<ASTNode> newChildren = new ArrayList<ASTNode>(); newChildren.add(expr); int i = gBy.getChildCount() - 1; while ( i >= 0 ) { newChildren.add((ASTNode) gBy.deleteChild(i)); i--; } for(ASTNode child : newChildren ) { gBy.addChild(child); } }
private void initReplStatus(ASTNode ast) { int numChildren = ast.getChildCount(); dbNameOrPattern = PlanUtils.stripQuotes(ast.getChild(0).getText()); if (numChildren > 1) { tblNameOrPattern = PlanUtils.stripQuotes(ast.getChild(1).getText()); } }
public static String getText(ASTNode tree) { if (tree.getChildCount() == 0) { return tree.getText(); } return getText((ASTNode) tree.getChild(tree.getChildCount() - 1)); }
private String buildTriggerActionExpression(ASTNode ast) throws SemanticException { switch (ast.getType()) { case HiveParser.KW_KILL: return "KILL"; case HiveParser.KW_MOVE: if (ast.getChildCount() != 1) { throw new SemanticException("Invalid move to clause in trigger action."); } String poolPath = poolPath(ast.getChild(0)); return "MOVE TO " + poolPath; default: throw new SemanticException("Unknown token in action clause: " + ast.getType()); } }
public static VarcharTypeInfo getVarcharTypeInfo(ASTNode node) throws SemanticException { if (node.getChildCount() != 1) { throw new SemanticException("Bad params for type varchar"); } String lengthStr = node.getChild(0).getText(); return TypeInfoFactory.getVarcharTypeInfo(Integer.parseInt(lengthStr)); }
/** * process stored as directories * * @param child * @return */ protected boolean analyzeStoredAdDirs(ASTNode child) { boolean storedAsDirs = false; if ((child.getChildCount() == 3) && (((ASTNode) child.getChild(2)).getToken().getType() == HiveParser.TOK_STOREDASDIRS)) { storedAsDirs = true; } return storedAsDirs; }
public static List<PrincipalDesc> analyzePrincipalListDef(ASTNode node) { List<PrincipalDesc> principalList = new ArrayList<PrincipalDesc>(); for (int i = 0; i < node.getChildCount(); i++) { principalList.add(getPrincipalDesc((ASTNode) node.getChild(i))); } return principalList; }
private void initReplLoad(ASTNode ast) { int numChildren = ast.getChildCount(); path = PlanUtils.stripQuotes(ast.getChild(0).getText()); if (numChildren > 1) { dbNameOrPattern = PlanUtils.stripQuotes(ast.getChild(1).getText()); } if (numChildren > 2) { tblNameOrPattern = PlanUtils.stripQuotes(ast.getChild(2).getText()); } }
/** * Performs a descent of the leftmost branch of a tree, stopping when either a * node with a non-null token is found or the leaf level is encountered. * * @param tree * candidate node from which to start searching * * @return node at which descent stopped */ private static ASTNode findRootNonNullToken(ASTNode tree) { while ((tree.getToken() == null) && (tree.getChildCount() > 0)) { tree = (ASTNode) tree.getChild(0); } return tree; }
static ASTNode subQueryWhere(ASTNode insertClause) { if (insertClause.getChildCount() > 2 && insertClause.getChild(2).getType() == HiveParser.TOK_WHERE ) { return (ASTNode) insertClause.getChild(2); } return null; }
private static void validateCheckExprAST(ASTNode checkExpr) throws SemanticException { if(checkExpr == null) { return; } if(checkExpr.getType() == HiveParser.TOK_SUBQUERY_EXPR) { throw new SemanticException(ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("Subqueries are not allowed " + "in Check Constraints")); } for(int i=0; i<checkExpr.getChildCount(); i++) { validateCheckExprAST((ASTNode)checkExpr.getChild(i)); } } // recursively go through expression and make sure the following:
public static CharTypeInfo getCharTypeInfo(ASTNode node) throws SemanticException { if (node.getChildCount() != 1) { throw new SemanticException("Bad params for type char"); } String lengthStr = node.getChild(0).getText(); return TypeInfoFactory.getCharTypeInfo(Integer.parseInt(lengthStr)); }
public static boolean isPartitionLevelStats(ASTNode tree) { boolean isPartitioned = false; ASTNode child = (ASTNode) tree.getChild(0); if (child.getChildCount() > 1) { child = (ASTNode) child.getChild(1); if (child.getToken().getType() == HiveParser.TOK_PARTSPEC) { isPartitioned = true; } } return isPartitioned; }
private static void findSubQueries(ASTNode node, List<ASTNode> subQueries) { Deque<ASTNode> stack = new ArrayDeque<ASTNode>(); stack.push(node); while (!stack.isEmpty()) { ASTNode next = stack.pop(); switch(next.getType()) { case HiveParser.TOK_SUBQUERY_EXPR: subQueries.add(next); break; default: int childCount = next.getChildCount(); for(int i = childCount - 1; i >= 0; i--) { stack.push((ASTNode) next.getChild(i)); } } } }
private static void assertConfig(ASTNode replConfigList, int atIndex, String expectedKey, String expectedValue) { ASTNode configOne = (ASTNode) replConfigList.getChild(atIndex); assertEquals("TOK_TABLEPROPERTY", configOne.getText()); assertEquals(2, configOne.getChildCount()); assertEquals(expectedKey, configOne.getChild(0).getText()); assertEquals(expectedValue, configOne.getChild(1).getText()); }
private static int getLine(ASTNode tree) { if (tree.getChildCount() == 0) { return tree.getToken().getLine(); } return getLine((ASTNode) tree.getChild(0)); }