Class FullTextFunction
- All Implemented Interfaces:
NamedWriteable,Writeable,PostAnalysisPlanVerificationAware,PostOptimizationVerificationAware,TranslationAware,Resolvable,EvaluatorMapper,ExpressionScoreMapper
- Direct Known Subclasses:
Knn,Kql,Match,MatchPhrase,MultiMatch,QueryString,Term
LocalPhysicalPlanOptimizer to rewrite them into Lucene queries.-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
Expression.TypeResolutionNested classes/interfaces inherited from interface org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper
EvaluatorMapper.ToEvaluatorNested classes/interfaces inherited from interface org.elasticsearch.xpack.esql.score.ExpressionScoreMapper
ExpressionScoreMapper.ToScorerNested classes/interfaces inherited from interface org.elasticsearch.xpack.esql.capabilities.TranslationAware
TranslationAware.FinishedTranslatable, TranslationAware.SingleValueTranslationAware, TranslationAware.TranslatableNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFullTextFunction(Source source, Expression query, List<Expression> children, QueryBuilder queryBuilder) -
Method Summary
Modifier and TypeMethodDescriptionasQuery(LucenePushdownPredicates pushdownPredicates, TranslatorHandler handler) Translates the implementing expression into a Query.dataType()booleanstatic FieldAttributefieldAsFieldAttribute(Expression field) static voidfieldVerifier(LogicalPlan plan, FullTextFunction function, Expression field, Failures failures) Used to differentiate error messages between functions and operatorsstatic StringgetNameFromFieldAttribute(FieldAttribute fieldAttribute) inthashCode()nullable()Allows the implementer to return a consumer that will perform self-validation in the context of the tree structure the implementer is part of.voidpostOptimizationVerification(Failures failures) Validates the implementing expression - discovered failures are reported to the givenFailuresclass.query()abstract ExpressionreplaceQueryBuilder(QueryBuilder queryBuilder) protected Expression.TypeResolutionResolves the type for the function parameters, as part of the type resolution for the functionprotected Expression.TypeResolutionresolveQuery(TypeResolutions.ParamOrdinal queryOrdinal) Resolves the type for the query parameter, as part of the type resolution for the functionprotected final Expression.TypeResolutiontoEvaluator(EvaluatorMapper.ToEvaluator toEvaluator) Convert this into anEvalOperator.ExpressionEvaluator.toScorer(ExpressionScoreMapper.ToScorer toScorer) translatable(LucenePushdownPredicates pushdownPredicates) Can this instance be translated or not? Usually checks whether the expression arguments are actual fields that exist in Lucene.protected abstract Querytranslate(LucenePushdownPredicates pushdownPredicates, TranslatorHandler handler) Methods inherited from class org.elasticsearch.xpack.esql.core.expression.function.Function
arguments, functionName, nodeStringMethods inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
canonical, canonicalize, childrenResolved, fold, foldable, propertiesToString, references, resolved, semanticEquals, semanticHash, toString, typeResolvedMethods inherited from class org.elasticsearch.xpack.esql.core.tree.Node
anyMatch, children, collect, collectFirstChildren, collectLeaves, doCollectFirst, forEachDown, forEachDown, forEachDownMayReturnEarly, forEachProperty, forEachPropertyDown, forEachPropertyOnly, forEachPropertyUp, forEachUp, forEachUp, info, nodeName, nodeProperties, replaceChildren, replaceChildrenSameSize, source, sourceLocation, sourceText, transformChildren, transformDown, transformDown, transformDown, transformNodeProps, transformPropertiesDown, transformPropertiesOnly, transformPropertiesUp, transformUp, transformUp, transformUpMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper
foldMethods inherited from interface org.elasticsearch.common.io.stream.NamedWriteable
getWriteableNameMethods inherited from interface org.elasticsearch.xpack.esql.capabilities.TranslationAware
asLuceneQuery
-
Constructor Details
-
FullTextFunction
protected FullTextFunction(Source source, Expression query, List<Expression> children, QueryBuilder queryBuilder)
-
-
Method Details
-
dataType
- Specified by:
dataTypein classExpression
-
resolveType
- Overrides:
resolveTypein classExpression
-
resolveParams
Resolves the type for the function parameters, as part of the type resolution for the function- Returns:
- type resolution for the function parameters
-
resolveQuery
Resolves the type for the query parameter, as part of the type resolution for the function- Returns:
- type resolution for the query parameter
-
query
-
nullable
-
functionType
Used to differentiate error messages between functions and operators- Returns:
- function type for error messages
-
hashCode
public int hashCode() -
equals
-
translatable
Description copied from interface:TranslationAwareCan this instance be translated or not? Usually checks whether the expression arguments are actual fields that exist in Lucene. SeeTranslationAware.Translatablefor precisely what can be signaled from this method.- Specified by:
translatablein interfaceTranslationAware
-
asQuery
Description copied from interface:TranslationAwareTranslates the implementing expression into a Query. If during translation a child needs to be translated first, the handler needs to be used even if the child implements this interface as well. This is to ensure that the child is wrapped in a SingleValueQuery if necessary.So use this:
Query childQuery = handler.asQuery(child);and not this:
Query childQuery = child.asQuery(handler);- Specified by:
asQueryin interfaceTranslationAware
-
queryBuilder
-
translate
protected abstract Query translate(LucenePushdownPredicates pushdownPredicates, TranslatorHandler handler) -
replaceQueryBuilder
-
postAnalysisPlanVerification
Description copied from interface:PostAnalysisPlanVerificationAwareAllows 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
GroupingFunctioninstance, which models a function to group documents to aggregate over, can only be used in the context of the STATS command, modeled by theAggregateclass. 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:
postAnalysisPlanVerificationin interfacePostAnalysisPlanVerificationAware- Returns:
- a consumer that will receive a tree to check and an accumulator of failures found during inspection.
-
fieldVerifier
public static void fieldVerifier(LogicalPlan plan, FullTextFunction function, Expression field, Failures failures) -
toEvaluator
public EvalOperator.ExpressionEvaluator.Factory toEvaluator(EvaluatorMapper.ToEvaluator toEvaluator) Description copied from interface:EvaluatorMapperConvert this into anEvalOperator.ExpressionEvaluator.Note for implementors: If you are implementing this function, you should call the passed-in lambda on your children, after doing any other manipulation (casting, etc.) necessary.
Note for Callers: If you are attempting to call this method, and you have an
Expressionand aLayout, you likely want to callEvalMapper.toEvaluator(org.elasticsearch.xpack.esql.core.expression.FoldContext, org.elasticsearch.xpack.esql.core.expression.Expression, org.elasticsearch.xpack.esql.planner.Layout)instead. On the other hand, if you already have something that looks like the parameter for this method, you should call this method with that function.Build an
EvalOperator.ExpressionEvaluator.Factoryfor the tree of expressions rooted at this node. This is only guaranteed to return a sensible evaluator if this node has a valid type. If this node is a subclass ofExpressionthen "valid type" means thatExpression.typeResolved()returns a non-error resolution. If Expression.typeResolved() returns an error then this method may throw. Or return an evaluator that produces garbage. Or return an evaluator that throws when run.- Specified by:
toEvaluatorin interfaceEvaluatorMapper
-
toScorer
- Specified by:
toScorerin interfaceExpressionScoreMapper
-
getNameFromFieldAttribute
-
fieldAsFieldAttribute
-
postOptimizationVerification
Description copied from interface:PostOptimizationVerificationAwareValidates the implementing expression - discovered failures are reported to the givenFailuresclass.Example: the
Bucketfunction, which produces buckets over a numerical or date field, based on a number of literal arguments needs to check if its arguments are all indeed literals. This is how this verification is performed:@Override public void postOptimizationVerification(Failures failures) { String operation = sourceText(); failures.add(isFoldable(buckets, operation, SECOND)) .add(from != null ? isFoldable(from, operation, THIRD) : null) .add(to != null ? isFoldable(to, operation, FOURTH) : null); }- Specified by:
postOptimizationVerificationin interfacePostOptimizationVerificationAware
-