All Implemented Interfaces:
NamedWriteable, Writeable, PostAnalysisPlanVerificationAware, PostOptimizationPlanVerificationAware, PostOptimizationVerificationAware, RewriteableAware, TranslationAware, Resolvable, EvaluatorMapper, ExpressionScoreMapper

public class Term extends FullTextFunction implements PostAnalysisPlanVerificationAware
Full text function that performs a TermQuery .
  • Field Details

  • Constructor Details

  • Method Details

    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • getWriteableName

      public String getWriteableName()
      Specified by:
      getWriteableName in interface NamedWriteable
    • resolveParams

      protected Expression.TypeResolution resolveParams()
      Description copied from class: FullTextFunction
      Resolves the type for the function parameters, as part of the type resolution for the function
      Overrides:
      resolveParams in class FullTextFunction
      Returns:
      type resolution for the function parameters
    • postAnalysisPlanVerification

      public BiConsumer<LogicalPlan,Failures> postAnalysisPlanVerification()
      Description copied from interface: PostAnalysisPlanVerificationAware
      Allows the implementer to return a consumer that will perform self-validation in the context of the tree structure the implementer is part of. This usually involves checking the type and configuration of the children or that of the parent.

      It is often more useful to perform the checks as extended as it makes sense, over stopping at the first failure. This will allow the author to progress faster to a correct query.

      Example: a GroupingFunction instance, which models a function to group documents to aggregate over, can only be used in the context of the STATS command, modeled by the Aggregate class. This is how this verification is performed:

           
            @Override
            public BiConsumer<LogicalPlan, Failures> postAnalysisPlanVerification() {
                return (p, failures) -> {
                    if (p instanceof Aggregate == false) {
                        p.forEachExpression(
                            GroupingFunction.class,
                            gf -> failures.add(fail(gf, "cannot use grouping function [{}] outside of a STATS command", gf.sourceText()))
                        );
                    }
                };
            }
           
           
      Specified by:
      postAnalysisPlanVerification in interface PostAnalysisPlanVerificationAware
      Overrides:
      postAnalysisPlanVerification in class FullTextFunction
      Returns:
      a consumer that will receive a tree to check and an accumulator of failures found during inspection.
    • postOptimizationPlanVerification

      public BiConsumer<LogicalPlan,Failures> postOptimizationPlanVerification()
      Description copied from interface: PostOptimizationPlanVerificationAware
      Validates the implementing expression - discovered failures are reported to the given Failures class.

      Example: the SORT command, OrderBy, can only be executed currently if it can be associated with a LIMIT Limit and together transformed into a TopN (which is executable). The replacement of the LIMIT+SORT into a TopN is done at the end of the optimization phase. This means that any SORT still existing in the plan post optimization is an error. However, there can be a LIMIT in the plan, but separated from the SORT by an INLINE STATS; in this case, the LIMIT cannot be pushed down near the SORT. To inform the user how they need to modify the query so it can be run, we implement this:

           
      
            @Override
            public BiConsumer<LogicalPlan, Failures> postOptimizationPlanVerification() {
                return (p, failures) -> {
                    if (p instanceof InlineJoin inlineJoin) {
                        inlineJoin.forEachUp(OrderBy.class, orderBy -> {
                            failures.add(
                                fail(
                                    inlineJoin,
                                    "unbounded SORT [{}] not supported before INLINE STATS [{}], move the sort after the INLINE STATS",
                                    orderBy.sourceText(),
                                    inlineJoin.sourceText()
                                )
                            );
                        });
                    } else if (p instanceof OrderBy) {
                        failures.add(fail(p, "Unbounded SORT not supported yet [{}] please add a LIMIT", p.sourceText()));
                    }
                };
            }
           
           

      If we didn't need to check the structure of the plan, it would have sufficed to implement the PostOptimizationVerificationAware interface, which would simply check if there is an instance of OrderBy in the plan.

      Specified by:
      postOptimizationPlanVerification in interface PostOptimizationPlanVerificationAware
      Overrides:
      postOptimizationPlanVerification in class FullTextFunction
      Returns:
      a consumer that will receive a tree to check and an accumulator of failures found during inspection.
    • replaceChildren

      public Expression replaceChildren(List<Expression> newChildren)
      Specified by:
      replaceChildren in class Node<Expression>
    • info

      protected NodeInfo<? extends Expression> info()
      Specified by:
      info in class Node<Expression>
    • queryParamOrdinal

      protected TypeResolutions.ParamOrdinal queryParamOrdinal()
    • translate

      protected Query translate(LucenePushdownPredicates pushdownPredicates, TranslatorHandler handler)
      Specified by:
      translate in class FullTextFunction
    • replaceQueryBuilder

      public Expression replaceQueryBuilder(QueryBuilder queryBuilder)
      Description copied from interface: RewriteableAware
      Replaces the current query builder with a rewritten iteration. This happens multiple times through the rewrite phase until the final iteration of the query builder is stored.
      Specified by:
      replaceQueryBuilder in interface RewriteableAware
      Parameters:
      queryBuilder - QueryBuilder
      Returns:
      Expression defining the active QueryBuilder
    • field

      public Expression field()
    • functionName

      public String functionName()
      Overrides:
      functionName in class Function