Class CompletionFunction
- All Implemented Interfaces:
NamedWriteable,Writeable,Resolvable
This function is an internal optimization primitive used exclusively for constant folding of
COMPLETION commands during the analysis phase. It should never be registered in the
function registry or exposed to users, as ESQL does not currently support async functions
in the function registry.
When a COMPLETION command has a foldable prompt (e.g., a literal or foldable expression),
the analyzer transforms it into an EVAL node with a CompletionFunction expression:
FROM books
| COMPLETION "Translate this text" WITH { "inference_id": "my-model" }
is internally rewritten into:
FROM books
| EVAL completion = COMPLETION("Translate this text", "my-model")
The pre-optimizer then evaluates this function using InferenceFunctionEvaluator and
replaces it with a literal result.-
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.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
Fields inherited from class org.elasticsearch.xpack.esql.expression.function.inference.InferenceFunction
INFERENCE_ID_PARAMETER_NAMEFields inherited from class org.elasticsearch.xpack.esql.core.tree.Node
TO_STRING_MAX_WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionCompletionFunction(Source source, Expression prompt, Expression inferenceId) -
Method Summary
Modifier and TypeMethodDescriptiondataType()TheDataTypereturned by executing the tree rooted at this expression.booleanbooleanfoldable()Whether the expression can be evaluated statically, aka "folded", or not.inthashCode()The inference endpoint identifier expression.protected NodeInfo<? extends Expression> info()Normally, you want to use one of the staticcreatemethods to implement this.prompt()replaceChildren(List<Expression> newChildren) protected Expression.TypeResolutionThe implementation ofExpression.typeResolved(), which is just a caching wrapper around this method.taskType()The task type required by this function (e.g., TEXT_EMBEDDING).toString()withInferenceResolutionError(String inferenceId, String error) Returns a copy with inference resolution error for display to user.voidwriteTo(StreamOutput out) Methods inherited from class org.elasticsearch.xpack.esql.expression.function.inference.InferenceFunction
hasNestedInferenceFunctionMethods inherited from class org.elasticsearch.xpack.esql.core.expression.function.Function
arguments, functionName, nodeString, nullableMethods inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
canonical, canonicalize, childrenResolved, fold, propertiesToString, references, resolved, semanticEquals, semanticHash, typeResolvedMethods inherited from class org.elasticsearch.xpack.esql.core.tree.Node
anyMatch, children, collect, collect, collect, collectFirstChildren, collectLeaves, doCollectFirst, forEachDown, forEachDown, forEachDownMayReturnEarly, forEachProperty, forEachPropertyDown, forEachPropertyOnly, forEachPropertyUp, forEachUp, forEachUp, nodeName, nodeProperties, replaceChildrenSameSize, source, sourceLocation, sourceText, transformChildren, transformDown, transformDown, transformDown, transformNodeProps, transformPropertiesDown, transformPropertiesOnly, transformPropertiesUp, transformUp, transformUp, transformUp
-
Constructor Details
-
CompletionFunction
-
-
Method Details
-
writeTo
- Throws:
IOException
-
getWriteableName
-
prompt
-
inferenceId
Description copied from class:InferenceFunctionThe inference endpoint identifier expression.- Specified by:
inferenceIdin classInferenceFunction<CompletionFunction>
-
foldable
public boolean foldable()Description copied from class:ExpressionWhether the expression can be evaluated statically, aka "folded", or not.- Overrides:
foldablein classExpression
-
dataType
Description copied from class:ExpressionTheDataTypereturned by executing the tree rooted at this expression. IfExpression.typeResolved()returns an error then the behavior of this method is undefined. It may return a valid type. Or it may throw an exception. Or it may return a totally nonsensical type.- Specified by:
dataTypein classExpression
-
resolveType
Description copied from class:ExpressionThe implementation ofExpression.typeResolved(), which is just a caching wrapper around this method. See it's javadoc for what this method should return.Implementations will rarely interact with the
Expression.TypeResolutionclass directly, instead usually calling the utility methods onTypeResolutions.Implementations should fail if
Expression.childrenResolved()returnsfalse.- Overrides:
resolveTypein classExpression
-
taskType
Description copied from class:InferenceFunctionThe task type required by this function (e.g., TEXT_EMBEDDING).- Specified by:
taskTypein classInferenceFunction<CompletionFunction>
-
withInferenceResolutionError
Description copied from class:InferenceFunctionReturns a copy with inference resolution error for display to user.- Specified by:
withInferenceResolutionErrorin classInferenceFunction<CompletionFunction>
-
replaceChildren
- Specified by:
replaceChildrenin classNode<Expression>
-
info
Description copied from class:NodeNormally, you want to use one of the staticcreatemethods to implement this.For
QueryPlans, it is very important that the properties contain all of the expressions and references relevant to this node, and that all the properties are used in the provided constructor; otherwise query plan transformations likeQueryPlan#transformExpressionsOnly(Function)will not have an effect.- Specified by:
infoin classNode<Expression>
-
toString
- Overrides:
toStringin classExpression
-
equals
-
hashCode
public int hashCode()
-