use of org.apache.drill.common.expression.parser.ExprLexer in project drill by axbaretto.
the class SchemaPath method parseFromString.
/**
* Parses input string using the same rules which are used for the field in the query.
* If a string contains dot outside back-ticks, or there are no backticks in the string,
* will be created {@link SchemaPath} with the {@link NameSegment}
* which contains one else {@link NameSegment}, etc.
* If a string contains [] then {@link ArraySegment} will be created.
*
* @param expr input string to be parsed
* @return {@link SchemaPath} instance
*/
public static SchemaPath parseFromString(String expr) {
if (expr == null || expr.isEmpty()) {
return null;
}
try {
ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ExprParser parser = new ExprParser(tokens);
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);
}
}
Aggregations