Class PredicateAnalyzer
- java.lang.Object
-
- org.apache.calcite.adapter.elasticsearch.PredicateAnalyzer
-
class PredicateAnalyzer extends java.lang.Object
Query predicate analyzer. Uses visitor pattern to traverse existing expression and convert it toQueryBuilders.QueryBuilder
.Major part of this class have been copied from dremio ES adapter (thanks to their team for improving calcite-ES integration).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
PredicateAnalyzer.CastExpression
SQL cast:cast(col as INTEGER)
(package private) static class
PredicateAnalyzer.CompoundQueryExpression
Builds conjunctions / disjunctions based on existing expressions(package private) static interface
PredicateAnalyzer.Expression
Empty interface; exists only to define type hierarchy(package private) static class
PredicateAnalyzer.ExpressionNotAnalyzableException
Thrown whenRelNode
expression can't be processed (or converted into ES query)(package private) static class
PredicateAnalyzer.LiteralExpression
Literal like'foo' or 42 or true
etc.(package private) static class
PredicateAnalyzer.NamedFieldExpression
Used for bind variablesprivate static class
PredicateAnalyzer.NotLikeConverter
Converts expressions of the form NOT(LIKE(...)) into NOT_LIKE(...)private static class
PredicateAnalyzer.PredicateAnalyzerException
Internal exception(package private) static class
PredicateAnalyzer.QueryExpression
Main expression operators (likeequals
,gt
,exists
etc.)(package private) static class
PredicateAnalyzer.SimpleQueryExpression
Usually basic expression of typea = 'val'
orb > 42
.(package private) static interface
PredicateAnalyzer.TerminalExpression
Empty interface; exists only to define type hierarchyprivate static class
PredicateAnalyzer.Visitor
TraversesRexNode
tree and builds ES query.
-
Constructor Summary
Constructors Modifier Constructor Description private
PredicateAnalyzer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static QueryBuilders.RangeQueryBuilder
addFormatIfNecessary(PredicateAnalyzer.LiteralExpression literal, QueryBuilders.RangeQueryBuilder rangeQueryBuilder)
By default, range queries on date/time need use the format of the source to parse the literal.(package private) static QueryBuilders.QueryBuilder
analyze(RexNode expression)
Walks the expression tree, attempting to convert the entire tree into an equivalent Elasticsearch query filter.private static void
checkForIncompatibleDateTimeOperands(RexCall call)
If one operand in a binary operator is a DateTime type, but the other isn't, we should not push down the predicate
-
-
-
Method Detail
-
analyze
static QueryBuilders.QueryBuilder analyze(RexNode expression) throws PredicateAnalyzer.ExpressionNotAnalyzableException
Walks the expression tree, attempting to convert the entire tree into an equivalent Elasticsearch query filter. If an error occurs, or if it is determined that the expression cannot be converted, an exception is thrown and an error message logged.Callers should catch ExpressionNotAnalyzableException and fall back to not using push-down filters.
- Parameters:
expression
- expression to analyze- Returns:
- search query which can be used to query ES cluster
- Throws:
PredicateAnalyzer.ExpressionNotAnalyzableException
- when expression can't processed by this analyzer
-
addFormatIfNecessary
private static QueryBuilders.RangeQueryBuilder addFormatIfNecessary(PredicateAnalyzer.LiteralExpression literal, QueryBuilders.RangeQueryBuilder rangeQueryBuilder)
By default, range queries on date/time need use the format of the source to parse the literal. So we need to specify that the literal has "date_time" format- Parameters:
literal
- literal valuerangeQueryBuilder
- query builder to optionally addformat
expression- Returns:
- existing builder with possible
format
attribute
-
checkForIncompatibleDateTimeOperands
private static void checkForIncompatibleDateTimeOperands(RexCall call)
If one operand in a binary operator is a DateTime type, but the other isn't, we should not push down the predicate- Parameters:
call
- current node being evaluated
-
-