All Implemented Interfaces:
NamedWriteable, Writeable, PostAnalysisPlanVerificationAware, Resolvable
Direct Known Subclasses:
Avg, Count, CountDistinct, FromPartial, 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().
  • Constructor Details

  • Method Details

    • writeTo

      public final void writeTo(StreamOutput out) throws IOException
      Specified by:
      writeTo in interface Writeable
      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

      public Expression field()
    • parameters

      public List<? extends Expression> parameters()
    • hasFilter

      public boolean hasFilter()
    • filter

      public Expression filter()
    • resolveType

      protected Expression.TypeResolution resolveType()
      Overrides:
      resolveType in class Expression
    • withFilter

      public abstract AggregateFunction withFilter(Expression filter)
      Attach a filter to the aggregate function.
    • withParameters

      public AggregateFunction withParameters(List<? extends Expression> parameters)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Function
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Function
    • 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
      Returns:
      a consumer that will receive a tree to check and an accumulator of failures found during inspection.