Search in sources :

Example 1 with ExprParser

use of org.apache.drill.common.expression.parser.ExprParser in project drill by apache.

the class TestBuilder method parsePath.

// modified code from SchemaPath.De class. This should be used sparingly and only in tests if absolutely needed.
public static SchemaPath parsePath(String path) {
    try {
        ExprLexer lexer = new ExprLexer(new ANTLRStringStream(path));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        ExprParser parser = new ExprParser(tokens);
        ExprParser.parse_return ret = parser.parse();
        if (ret.e instanceof SchemaPath) {
            return (SchemaPath) ret.e;
        } else {
            throw new IllegalStateException("Schema path is not a valid format.");
        }
    } catch (RecognitionException e) {
        throw new RuntimeException(e);
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) SchemaPath(org.apache.drill.common.expression.SchemaPath) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser(org.apache.drill.common.expression.parser.ExprParser) RecognitionException(org.antlr.runtime.RecognitionException)

Example 2 with ExprParser

use of org.apache.drill.common.expression.parser.ExprParser in project drill by apache.

the class ExecTest method parseExpr.

protected LogicalExpression parseExpr(String expr) throws RecognitionException {
    final ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    final CommonTokenStream tokens = new CommonTokenStream(lexer);
    final ExprParser parser = new ExprParser(tokens);
    final ExprParser.parse_return ret = parser.parse();
    return ret.e;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser(org.apache.drill.common.expression.parser.ExprParser)

Example 3 with ExprParser

use of org.apache.drill.common.expression.parser.ExprParser in project drill by apache.

the class PhysicalOpUnitTestBase method parseExpr.

@Override
protected LogicalExpression parseExpr(String expr) {
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExprParser parser = new ExprParser(tokens);
    try {
        return parser.parse().e;
    } catch (RecognitionException e) {
        throw new RuntimeException("Error parsing expression: " + expr);
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser(org.apache.drill.common.expression.parser.ExprParser) RecognitionException(org.antlr.runtime.RecognitionException)

Example 4 with ExprParser

use of org.apache.drill.common.expression.parser.ExprParser in project drill by apache.

the class TestEvaluationVisitor method getExpr.

private LogicalExpression getExpr(String expr) throws Exception {
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    //    tokens.fill();
    //    for(Token t : (List<Token>) tokens.getTokens()){
    //      System.out.println(t + "" + t.getType());
    //    }
    //    tokens.rewind();
    ExprParser parser = new ExprParser(tokens);
    parse_return ret = parser.parse();
    return ret.e;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser.parse_return(org.apache.drill.common.expression.parser.ExprParser.parse_return) ExprParser(org.apache.drill.common.expression.parser.ExprParser)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)4 CommonTokenStream (org.antlr.runtime.CommonTokenStream)4 ExprLexer (org.apache.drill.common.expression.parser.ExprLexer)4 ExprParser (org.apache.drill.common.expression.parser.ExprParser)4 RecognitionException (org.antlr.runtime.RecognitionException)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 ExprParser.parse_return (org.apache.drill.common.expression.parser.ExprParser.parse_return)1