Refine search
private static RecordPathSegment[] getArgPaths(final Tree argumentListTree, final int minCount, final int maxCount, final String functionName, final boolean absolute) { final int numArgs = argumentListTree.getChildCount(); if (numArgs < minCount || numArgs > maxCount) { throw new RecordPathException("Invalid number of arguments: " + functionName + " function takes at least" + minCount + " arguments, and at most " + maxCount + "arguments, but got " + numArgs); } final List<RecordPathSegment> argPaths = new ArrayList<>(); for (int i=0; i < argumentListTree.getChildCount(); i++) { argPaths.add(buildPath(argumentListTree.getChild(i), null, absolute)); } return argPaths.toArray(new RecordPathSegment[argPaths.size()]); } }
private void toTreeString(final Tree tree, final StringBuilder sb, final int indentLevel) { final String nodeName = tree.getText(); for (int i = 0; i < indentLevel; i++) { sb.append(" "); } sb.append(nodeName); sb.append("\n"); for (int i = 0; i < tree.getChildCount(); i++) { final Tree child = tree.getChild(i); toTreeString(child, sb, indentLevel + 2); } } }
private String poolPath(Tree ast) { StringBuilder builder = new StringBuilder(); builder.append(unescapeIdentifier(ast.getText())); for (int i = 0; i < ast.getChildCount(); ++i) { // DOT is not affected builder.append(unescapeIdentifier(ast.getChild(i).getText())); } return builder.toString(); }
private static RecordPathSegment[] getArgPaths(final Tree argumentListTree, final int expectedCount, final String functionName, final boolean absolute) { final int numArgs = argumentListTree.getChildCount(); if (numArgs != expectedCount) { throw new RecordPathException("Invalid number of arguments: " + functionName + " function takes " + expectedCount + " arguments but got " + numArgs); } final RecordPathSegment[] argPaths = new RecordPathSegment[expectedCount]; for (int i = 0; i < expectedCount; i++) { argPaths[i] = buildPath(argumentListTree.getChild(i), null, absolute); } return argPaths; }
private Evaluator<?> buildFunctionExpressionEvaluator(final Tree tree, final int offset) { if (tree.getChildCount() == 0) { throw new AttributeExpressionLanguageParsingException("EXPRESSION tree node has no children"); } final int firstChildIndex = tree.getChildCount() - offset - 1; if (firstChildIndex == 0) { return buildEvaluator(tree.getChild(0)); } final Tree functionTree = tree.getChild(firstChildIndex); final Evaluator<?> subjectEvaluator = buildFunctionExpressionEvaluator(tree, offset + 1); final Tree functionNameTree = functionTree.getChild(0); final List<Evaluator<?>> argEvaluators = new ArrayList<>(); for (int i = 1; i < functionTree.getChildCount(); i++) { argEvaluators.add(buildEvaluator(functionTree.getChild(i))); } return buildFunctionEvaluator(functionNameTree, subjectEvaluator, argEvaluators); }
private List<Selection> processSelect(final Tree select) { final List<Selection> selections = new ArrayList<>(); for (int i = 0; i < select.getChildCount(); i++) { final Tree selectable = select.getChild(i); final String alias = getSelectedName(selectable); final Evaluator<?> selectionEvaluator = buildReferenceEvaluator(selectable); final Selection selection = new Selection(selectionEvaluator, alias); selections.add(selection); } return selections; }
private String getSelectedName(final Tree selectable) { if (selectable.getChildCount() == 0) { return selectable.getText(); } else if (selectable.getType() == DOT) { return getSelectedName(selectable.getChild(0)) + "." + getSelectedName(selectable.getChild(1)); } else { return selectable.getChild(selectable.getChildCount() - 1).getText(); } }
if (p.getChildCount() != otherP.getChildCount()) { return false; for (int i = p.getChildCount()-1; i >= 0; i--) { Tree t = p.getChild(i); stack.push(t); Tree otherT = otherP.getChild(i); otherStack.push(otherT);
public static RecordPathSegment compile(final Tree pathTree, final RecordPathSegment root, final boolean absolute) { if (pathTree.getType() == FUNCTION) { return buildPath(pathTree, null, absolute); } RecordPathSegment parent = root; for (int i = 0; i < pathTree.getChildCount(); i++) { final Tree child = pathTree.getChild(i); parent = RecordPathCompiler.buildPath(child, parent, absolute); } return parent; }
if (p.getChildCount() != otherP.getChildCount()) { return false; for (int i = p.getChildCount()-1; i >= 0; i--) { Tree t = p.getChild(i); stack.push(t); Tree otherT = otherP.getChild(i); otherStack.push(otherT);
private void processDeclare(final Tree declare) { for (int i = 0; i < declare.getChildCount(); i++) { final Tree declarationTree = declare.getChild(i); final String identifier = declarationTree.getChild(0).getText(); final Tree requiredOrOptionalTree = declarationTree.getChild(1); final boolean required = requiredOrOptionalTree.getType() == REQUIRED; final String segmentName = declarationTree.getChild(2).getText(); final Declaration declaration = new Declaration() { @Override public String getAlias() { return identifier; } @Override public boolean isRequired() { return required; } @Override public Object getDeclaredValue(final HL7Message message) { if (message == null) { return null; } return message.getSegments(segmentName); } }; declarations.add(declaration); } }
if (args.getChildCount() == 1) { String text = args.getChild(0).getText(); if (text.equalsIgnoreCase("None")) { while(curIdx < args.getChildCount()) { curIdx = parseSingleSemiJoinHint(args, curIdx, result);
/** * Get the constraint from the AST and populate the cstrInfos with the required * information. * @param child The node with the constraint token * @param cstrInfos Constraint information * @throws SemanticException */ private static void generateConstraintInfos(ASTNode child, List<ConstraintInfo> cstrInfos) throws SemanticException { ImmutableList.Builder<String> columnNames = ImmutableList.builder(); for (int j = 0; j < child.getChild(0).getChildCount(); j++) { Tree columnName = child.getChild(0).getChild(j); checkColumnName(columnName.getText()); columnNames.add(unescapeIdentifier(columnName.getText().toLowerCase())); } generateConstraintInfos(child, columnNames.build(), cstrInfos, null, null); }
private int parseSingleSemiJoinHint(Tree args, int curIdx, Map<String, List<SemiJoinHint>> result) throws SemanticException { int numEntriesLeft = args.getChildCount() - curIdx; if (numEntriesLeft < 3) { throw new SemanticException("User provided only 1 entry for the hint with alias " + args.getChild(curIdx).getText()); String source = args.getChild(curIdx++).getText(); String colName = args.getChild(curIdx++).getText();
/** * disableMapJoinWithHint * @param hints * @return true if hint to disable hint is provided, else false * @throws SemanticException */ private boolean disableMapJoinWithHint(List<ASTNode> hints) throws SemanticException { if (hints == null || hints.size() == 0) { return false; } for (ASTNode hintNode : hints) { for (Node node : hintNode.getChildren()) { ASTNode hint = (ASTNode) node; if (hint.getChild(0).getType() != HintParser.TOK_MAPJOIN) { continue; } Tree args = hint.getChild(1); if (args.getChildCount() == 1) { String text = args.getChild(0).getText(); if (text.equalsIgnoreCase("None")) { // Hint to disable mapjoin. return true; } } } } return false; }
private List<String> getColumnName(ASTNode tree) throws SemanticException{ switch (tree.getChildCount()) { case 2: return Utilities.getColumnNamesFromFieldSchema(tbl.getCols()); case 3: int numCols = tree.getChild(2).getChildCount(); List<String> colName = new LinkedList<String>(); for (int i = 0; i < numCols; i++) { colName.add(i, new String(getUnescapedName((ASTNode) tree.getChild(2).getChild(i)))); } return colName; default: throw new SemanticException("Internal error. Expected number of children of ASTNode to be" + " either 2 or 3. Found : " + tree.getChildCount()); } }
private List<String> getColumnName(ASTNode tree) throws SemanticException { switch (tree.getChildCount()) { case 2: return Utilities.getColumnNamesFromFieldSchema(tbl.getCols()); case 3: int numCols = tree.getChild(2).getChildCount(); List<String> colName = new ArrayList<String>(numCols); for (int i = 0; i < numCols; i++) { colName.add(getUnescapedName((ASTNode) tree.getChild(2).getChild(i))); } return colName; default: throw new SemanticException("Internal error. Expected number of children of ASTNode to be" + " either 2 or 3. Found : " + tree.getChildCount()); } }
private ASTNode getSubQueryGroupByAST() { ASTNode groupBy = null; if ( subQueryAST.getChild(1).getChildCount() > 3 && subQueryAST.getChild(1).getChild(3).getType() == HiveParser.TOK_GROUPBY ) { groupBy = (ASTNode) subQueryAST.getChild(1).getChild(3); } if ( groupBy != null ) { return groupBy; } groupBy = SubQueryUtils.buildGroupBy(); groupbyAddedToSQ = true; List<ASTNode> newChildren = new ArrayList<ASTNode>(); newChildren.add(groupBy); if ( subQueryAST.getChildCount() > 3) { for( int i = subQueryAST.getChildCount() - 1; i >= 3; i-- ) { ASTNode child = (ASTNode) subQueryAST.getChild(i); newChildren.add(child); } } for(ASTNode child : newChildren ) { subQueryAST.addChild(child); } subQueryDiagnostic.setAddGroupByClause(); return groupBy; }
private void parseStreamTables(QBJoinTree joinTree, QB qb) { List<String> streamAliases = joinTree.getStreamAliases(); for (Node hintNode : qb.getParseInfo().getHints().getChildren()) { ASTNode hint = (ASTNode) hintNode; if (hint.getChild(0).getType() == HintParser.TOK_STREAMTABLE) { for (int i = 0; i < hint.getChild(1).getChildCount(); i++) { if (streamAliases == null) { streamAliases = new ArrayList<String>(); } streamAliases.add(hint.getChild(1).getChild(i).getText()); } } } joinTree.setStreamAliases(streamAliases); }
private void parseStreamTables(QBJoinTree joinTree, QB qb) { List<String> streamAliases = joinTree.getStreamAliases(); for (Node hintNode : qb.getParseInfo().getHints().getChildren()) { ASTNode hint = (ASTNode) hintNode; if (hint.getChild(0).getType() == HintParser.TOK_STREAMTABLE) { for (int i = 0; i < hint.getChild(1).getChildCount(); i++) { if (streamAliases == null) { streamAliases = new ArrayList<String>(); } streamAliases.add(hint.getChild(1).getChild(i).getText()); } } } joinTree.setStreamAliases(streamAliases); }