Search in sources :

Example 1 with AstNode

use of com.linkedin.pinot.pql.parsers.pql2.ast.AstNode in project pinot by linkedin.

the class TransformExpressionTree method buildTree.

/**
   * Given the root node for AST tree, builds the expression tree, and returns
   * the root node of the expression tree.
   *
   * @param rootNode Root Node of AST tree
   * @return Root node of the Expression tree
   */
public static TransformExpressionTree buildTree(AstNode rootNode) {
    TransformExpressionTree expressionTree;
    if (!rootNode.hasChildren()) {
        return new TransformExpressionTree(rootNode);
    } else {
        expressionTree = new TransformExpressionTree(rootNode);
        expressionTree._children = new ArrayList<>();
        for (AstNode child : rootNode.getChildren()) {
            expressionTree._children.add(buildTree(child));
        }
    }
    return expressionTree;
}
Also used : FunctionCallAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.FunctionCallAstNode) IdentifierAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.IdentifierAstNode) AstNode(com.linkedin.pinot.pql.parsers.pql2.ast.AstNode) LiteralAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.LiteralAstNode)

Example 2 with AstNode

use of com.linkedin.pinot.pql.parsers.pql2.ast.AstNode in project pinot by linkedin.

the class Pql2AstListener method pushNode.

private void pushNode(AstNode node) {
    if (_rootNode == null) {
        _rootNode = node;
    }
    AstNode parentNode = null;
    if (!_nodeStack.isEmpty()) {
        parentNode = _nodeStack.peek();
    }
    if (parentNode != null) {
        parentNode.addChild(node);
    }
    node.setParent(parentNode);
    _nodeStack.push(node);
}
Also used : BetweenPredicateAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.BetweenPredicateAstNode) IdentifierAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.IdentifierAstNode) AstNode(com.linkedin.pinot.pql.parsers.pql2.ast.AstNode) FloatingPointLiteralAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.FloatingPointLiteralAstNode) HavingAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.HavingAstNode) OutputColumnAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.OutputColumnAstNode) OrderByAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.OrderByAstNode) OrderByExpressionAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.OrderByExpressionAstNode) StarExpressionAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.StarExpressionAstNode) LimitAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.LimitAstNode) SelectAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.SelectAstNode) WhereAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.WhereAstNode) IsPredicateAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.IsPredicateAstNode) StringLiteralAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.StringLiteralAstNode) ExpressionParenthesisGroupAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.ExpressionParenthesisGroupAstNode) FunctionCallAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.FunctionCallAstNode) IntegerLiteralAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.IntegerLiteralAstNode) TopAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.TopAstNode) OutputColumnListAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.OutputColumnListAstNode) BooleanOperatorAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.BooleanOperatorAstNode) BinaryMathOpAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.BinaryMathOpAstNode) ComparisonPredicateAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.ComparisonPredicateAstNode) TableNameAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.TableNameAstNode) InPredicateAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.InPredicateAstNode) PredicateParenthesisGroupAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.PredicateParenthesisGroupAstNode) GroupByAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.GroupByAstNode) PredicateListAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.PredicateListAstNode) StarColumnListAstNode(com.linkedin.pinot.pql.parsers.pql2.ast.StarColumnListAstNode)

Example 3 with AstNode

use of com.linkedin.pinot.pql.parsers.pql2.ast.AstNode in project pinot by linkedin.

the class Pql2Compiler method compileToBrokerRequest.

@Override
public BrokerRequest compileToBrokerRequest(String expression) throws Pql2CompilationException {
    try {
        //
        CharStream charStream = new ANTLRInputStream(expression);
        PQL2Lexer lexer = new PQL2Lexer(charStream);
        lexer.setTokenFactory(new CommonTokenFactory(true));
        TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer);
        PQL2Parser parser = new PQL2Parser(tokenStream);
        parser.setErrorHandler(new BailErrorStrategy());
        // Parse
        ParseTree parseTree = parser.root();
        ParseTreeWalker walker = new ParseTreeWalker();
        Pql2AstListener listener = new Pql2AstListener(expression);
        walker.walk(listener, parseTree);
        AstNode rootNode = listener.getRootNode();
        BrokerRequest brokerRequest = new BrokerRequest();
        rootNode.updateBrokerRequest(brokerRequest);
        return brokerRequest;
    } catch (Pql2CompilationException e) {
        throw e;
    } catch (Exception e) {
        throw new Pql2CompilationException(e.getMessage());
    }
}
Also used : TokenStream(org.antlr.v4.runtime.TokenStream) UnbufferedTokenStream(org.antlr.v4.runtime.UnbufferedTokenStream) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) BailErrorStrategy(org.antlr.v4.runtime.BailErrorStrategy) UnbufferedTokenStream(org.antlr.v4.runtime.UnbufferedTokenStream) CharStream(org.antlr.v4.runtime.CharStream) BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) AstNode(com.linkedin.pinot.pql.parsers.pql2.ast.AstNode)

Example 4 with AstNode

use of com.linkedin.pinot.pql.parsers.pql2.ast.AstNode in project mvel by mikebrock.

the class DebugTools method decompile.

private static String decompile(CompiledExpression cExp, boolean nest, DecompileContext context) {
    ASTIterator iter = new ASTLinkedList(cExp.getFirstNode());
    ASTNode tk;
    StringBuffer sbuf = new StringBuffer();
    if (!nest) {
        sbuf.append("Expression Decompile\n-------------\n");
    }
    while (iter.hasMoreNodes()) {
        sbuf.append("(").append(context.node++).append(") ");
        if ((tk = iter.nextNode()) instanceof NestedStatement && ((NestedStatement) tk).getNestedStatement() instanceof CompiledExpression) {
            //noinspection StringConcatenationInsideStringBufferAppend
            sbuf.append("NEST [" + tk.getClass().getSimpleName() + "]: { " + tk.getName() + " }\n");
            sbuf.append(decompile((CompiledExpression) ((NestedStatement) tk).getNestedStatement(), true, context));
        }
        if (tk instanceof Substatement && ((Substatement) tk).getStatement() instanceof CompiledExpression) {
            //noinspection StringConcatenationInsideStringBufferAppend
            sbuf.append("NEST [" + tk.getClass().getSimpleName() + "]: { " + tk.getName() + " }\n");
            sbuf.append(decompile((CompiledExpression) ((Substatement) tk).getStatement(), true, context));
        } else //            }
        if (tk.isDebuggingSymbol()) {
            //noinspection StringConcatenationInsideStringBufferAppend
            sbuf.append("DEBUG_SYMBOL :: " + tk.toString());
        } else if (tk.isLiteral()) {
            sbuf.append("LITERAL :: ").append(tk.getLiteralValue()).append("'");
        } else if (tk.isOperator()) {
            sbuf.append("OPERATOR [").append(getOperatorName(tk.getOperator())).append("]: ").append(tk.getName());
            if (tk.isOperator(Operator.END_OF_STMT))
                sbuf.append("\n");
        } else if (tk.isIdentifier()) {
            sbuf.append("REFERENCE :: ").append(tk.getClass().getSimpleName()).append(":").append(tk.getName());
        } else if (tk instanceof BinaryOperation) {
            BinaryOperation bo = (BinaryOperation) tk;
            sbuf.append("OPERATION [" + getOperatorName(bo.getOperation()) + "] {").append(bo.getLeft().getName()).append("} {").append(bo.getRight().getName()).append("}");
        } else {
            //noinspection StringConcatenationInsideStringBufferAppend
            sbuf.append("NODE [" + tk.getClass().getSimpleName() + "] :: " + tk.getName());
        }
        sbuf.append("\n");
    }
    sbuf.append("==END==");
    return sbuf.toString();
}
Also used : NestedStatement(org.mvel2.ast.NestedStatement) BinaryOperation(org.mvel2.ast.BinaryOperation) ASTLinkedList(org.mvel2.util.ASTLinkedList) ASTNode(org.mvel2.ast.ASTNode) ASTIterator(org.mvel2.util.ASTIterator) Substatement(org.mvel2.ast.Substatement) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 5 with AstNode

use of com.linkedin.pinot.pql.parsers.pql2.ast.AstNode in project mvel by mikebrock.

the class ASTLinkedList method finish.

public void finish() {
    reset();
    ASTNode last = null;
    ASTNode curr;
    while (hasMoreNodes()) {
        if ((curr = nextNode()).isDiscard()) {
            if (last == null) {
                last = firstASTNode = nextNode();
            } else {
                last.nextASTNode = nextNode();
            }
            continue;
        }
        if (!hasMoreNodes())
            break;
        last = curr;
    }
    this.last = last;
    reset();
}
Also used : ASTNode(org.mvel2.ast.ASTNode)

Aggregations

ASTNode (org.mvel2.ast.ASTNode)11 AstNode (com.linkedin.pinot.pql.parsers.pql2.ast.AstNode)5 Interceptor (org.mvel2.integration.Interceptor)4 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)4 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)4 FunctionCallAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.FunctionCallAstNode)3 IdentifierAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.IdentifierAstNode)3 HashMap (java.util.HashMap)3 BetweenPredicateAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.BetweenPredicateAstNode)2 BinaryMathOpAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.BinaryMathOpAstNode)2 BooleanOperatorAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.BooleanOperatorAstNode)2 ComparisonPredicateAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.ComparisonPredicateAstNode)2 ExpressionParenthesisGroupAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.ExpressionParenthesisGroupAstNode)2 FloatingPointLiteralAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.FloatingPointLiteralAstNode)2 GroupByAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.GroupByAstNode)2 HavingAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.HavingAstNode)2 InPredicateAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.InPredicateAstNode)2 IntegerLiteralAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.IntegerLiteralAstNode)2 IsPredicateAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.IsPredicateAstNode)2 LimitAstNode (com.linkedin.pinot.pql.parsers.pql2.ast.LimitAstNode)2