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.

        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 value
        rangeQueryBuilder - query builder to optionally add format 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