Class PredicateAnalyzer

  • class PredicateAnalyzer
    extends java.lang.Object
    Query predicate analyzer. Uses visitor pattern to traverse existing expression and convert it to QueryBuilders.QueryBuilder.

    Major part of this class have been copied from dremio ES adapter (thanks to their team for improving calcite-ES integration).

    • Constructor Detail

      • PredicateAnalyzer

        private PredicateAnalyzer()
    • 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.

        expression - expression to analyze
        search query which can be used to query ES cluster
        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
        literal - literal value
        rangeQueryBuilder - query builder to optionally add format expression
        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
        call - current node being evaluated