Class AggregateFunction
java.lang.Object
org.elasticsearch.xpack.esql.core.tree.Node<Expression>
org.elasticsearch.xpack.esql.core.expression.Expression
org.elasticsearch.xpack.esql.core.expression.function.Function
org.elasticsearch.xpack.esql.expression.function.aggregate.AggregateFunction
- All Implemented Interfaces:
NamedWriteable,Writeable,PostAnalysisPlanVerificationAware,Resolvable
- Direct Known Subclasses:
Avg,Count,CountDistinct,First,FromPartial,Last,Max,Median,Min,NumericAggregate,Sample,SpatialAggregateFunction,StdDev,TimeSeriesAggregateFunction,Top,ToPartial,Values,WeightedAvg
public abstract class AggregateFunction
extends Function
implements PostAnalysisPlanVerificationAware
A type of
Function that takes multiple values and extracts a single value out of them. For example, AVG().-
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> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedAggregateFunction(Source source, Expression field) protectedAggregateFunction(Source source, Expression field, List<? extends Expression> parameters) protectedAggregateFunction(Source source, Expression field, Expression filter, List<? extends Expression> parameters) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidDeprecated, for removal: This API element is subject to removal in a future version.booleanfield()filter()booleaninthashCode()List<? extends Expression> Allows the implementer to return a consumer that will perform self-validation in the context of the tree structure the implementer is part of.protected static AggregateFunctionRead a generic AggregateFunction from the stream input.protected Expression.TypeResolutionabstract AggregateFunctionwithFilter(Expression filter) Attach a filter to the aggregate function.withParameters(List<? extends Expression> parameters) final voidwriteTo(StreamOutput out) Methods 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, dataType, 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.common.io.stream.NamedWriteable
getWriteableName
-
Constructor Details
-
AggregateFunction
-
AggregateFunction
-
AggregateFunction
protected AggregateFunction(Source source, Expression field, Expression filter, List<? extends Expression> parameters) -
AggregateFunction
- Throws:
IOException
-
-
Method Details
-
readGenericAggregateFunction
Read a generic AggregateFunction from the stream input. This is used for BWC when the subclass requires a generic instance; then convert the parameters to the specific ones.- Throws:
IOException
-
writeTo
- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
deprecatedWriteParams
@Deprecated(since="8.16", forRemoval=true) protected void deprecatedWriteParams(StreamOutput out) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
IOException
-
field
-
parameters
-
hasFilter
public boolean hasFilter() -
filter
-
resolveType
- Overrides:
resolveTypein classExpression
-
withFilter
Attach a filter to the aggregate function. -
withParameters
-
hashCode
public int hashCode() -
equals
-
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.
-