Class ExpressionLambdaAggregatorFactory

java.lang.Object
org.apache.druid.query.aggregation.AggregatorFactory
org.apache.druid.query.aggregation.ExpressionLambdaAggregatorFactory
All Implemented Interfaces:
Cacheable

public class ExpressionLambdaAggregatorFactory extends AggregatorFactory
  • Field Details

  • Constructor Details

    • ExpressionLambdaAggregatorFactory

      public ExpressionLambdaAggregatorFactory(String name, @Nullable Set<String> fields, @Nullable String accumulatorIdentifier, String initialValue, @Nullable String initialCombineValue, @Nullable Boolean isNullUnlessAggregated, @Nullable Boolean shouldAggregateNullInputs, @Nullable Boolean shouldCombineAggregateNullInputs, String foldExpression, @Nullable String combineExpression, @Nullable String compareExpression, @Nullable String finalizeExpression, @Nullable HumanReadableBytes maxSizeBytes, ExprMacroTable macroTable)
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in class AggregatorFactory
      Returns:
      output name of the aggregator column.
    • getFields

      @Nullable public Set<String> getFields()
    • getAccumulatorIdentifier

      @Nullable public String getAccumulatorIdentifier()
    • getInitialValueExpressionString

      public String getInitialValueExpressionString()
    • getInitialCombineValueExpressionString

      public String getInitialCombineValueExpressionString()
    • getIsNullUnlessAggregated

      public boolean getIsNullUnlessAggregated()
    • getShouldAggregateNullInputs

      public boolean getShouldAggregateNullInputs()
    • getShouldCombineAggregateNullInputs

      public boolean getShouldCombineAggregateNullInputs()
    • getFoldExpressionString

      public String getFoldExpressionString()
    • getCombineExpressionString

      public String getCombineExpressionString()
    • getCompareExpressionString

      @Nullable public String getCompareExpressionString()
    • getFinalizeExpressionString

      @Nullable public String getFinalizeExpressionString()
    • getMaxSizeBytes

      public HumanReadableBytes getMaxSizeBytes()
    • getCacheKey

      public byte[] getCacheKey()
      Description copied from interface: Cacheable
      Get a byte array used as a cache key.
      Returns:
      bytes to be used as cache key - or null if this object should not be cached.
    • factorize

      public Aggregator factorize(ColumnSelectorFactory metricFactory)
      Specified by:
      factorize in class AggregatorFactory
    • factorizeBuffered

      public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory)
      Specified by:
      factorizeBuffered in class AggregatorFactory
    • getComparator

      public Comparator getComparator()
      Specified by:
      getComparator in class AggregatorFactory
    • combine

      @Nullable public Object combine(@Nullable Object lhs, @Nullable Object rhs)
      Description copied from class: AggregatorFactory
      A method that knows how to combine the outputs of Aggregator.get() produced via AggregatorFactory.factorize(org.apache.druid.segment.ColumnSelectorFactory) or BufferAggregator.get(java.nio.ByteBuffer, int) produced via AggregatorFactory.factorizeBuffered(org.apache.druid.segment.ColumnSelectorFactory). Note, even though this method is called "combine", this method's contract *does* allow for mutation of the input objects. Thus, any use of lhs or rhs after calling this method is highly discouraged.
      Specified by:
      combine in class AggregatorFactory
      Parameters:
      lhs - The left hand side of the combine
      rhs - The right hand side of the combine
      Returns:
      an object representing the combination of lhs and rhs, this can be a new object or a mutation of the inputs
    • deserialize

      public Object deserialize(Object object)
      Description copied from class: AggregatorFactory
      A method that knows how to "deserialize" the object from whatever form it might have been put into in order to transfer via JSON.
      Specified by:
      deserialize in class AggregatorFactory
      Parameters:
      object - the object to deserialize
      Returns:
      the deserialized object
    • finalizeComputation

      @Nullable public Object finalizeComputation(@Nullable Object object)
      Description copied from class: AggregatorFactory
      "Finalizes" the computation of an object. Primarily useful for complex types that have a different mergeable intermediate format than their final resultant output.
      Specified by:
      finalizeComputation in class AggregatorFactory
      Parameters:
      object - the object to be finalized
      Returns:
      the finalized value that should be returned for the initial query
    • requiredFields

      public List<String> requiredFields()
      Description copied from class: AggregatorFactory
      Get a list of fields that aggregators built by this factory will need to read.
      Specified by:
      requiredFields in class AggregatorFactory
    • getCombiningFactory

      public AggregatorFactory getCombiningFactory()
      Description copied from class: AggregatorFactory
      Returns an AggregatorFactory that can be used to combine the output of aggregators from this factory. It is used when we know we have some values that were produced with this aggregator factory, and want to do some additional combining of them. This happens, for example, when merging query results from two different segments, or two different servers. For simple aggregators, the combining factory may be computed by simply creating a new factory that is the same as the current, except with its input column renamed to the same as the output column. For example, this aggregator: {"type": "longSum", "fieldName": "foo", "name": "bar"} Would become: {"type": "longSum", "fieldName": "bar", "name": "bar"} Sometimes, the type or other parameters of the combining aggregator will be different from the original aggregator. For example, the CountAggregatorFactory getCombiningFactory method will return a LongSumAggregatorFactory, because counts are combined by summing. No matter what, `foo.getCombiningFactory()` and `foo.getCombiningFactory().getCombiningFactory()` should return the same result.
      Specified by:
      getCombiningFactory in class AggregatorFactory
      Returns:
      a new Factory that can be used for operations on top of data output from the current factory.
    • getIntermediateType

      public ColumnType getIntermediateType()
      Description copied from class: AggregatorFactory
      Get the "intermediate" ColumnType for this aggregator. This is the same as the type returned by AggregatorFactory.deserialize(java.lang.Object) and the type accepted by AggregatorFactory.combine(java.lang.Object, java.lang.Object). However, it is *not* necessarily the same type returned by AggregatorFactory.finalizeComputation(java.lang.Object). Refer to the ColumnType javadocs for details on the implications of choosing a type.
      Overrides:
      getIntermediateType in class AggregatorFactory
    • getResultType

      public ColumnType getResultType()
      Description copied from class: AggregatorFactory
      Get the ColumnType for the final form of this aggregator, i.e. the type of the value returned by AggregatorFactory.finalizeComputation(java.lang.Object). This may be the same as or different than the types expected in AggregatorFactory.deserialize(java.lang.Object) and AggregatorFactory.combine(java.lang.Object, java.lang.Object). Refer to the ColumnType javadocs for details on the implications of choosing a type.
      Overrides:
      getResultType in class AggregatorFactory
    • getMaxIntermediateSize

      public int getMaxIntermediateSize()
      Description copied from class: AggregatorFactory
      Returns the maximum size that this aggregator will require in bytes for intermediate storage of results.
      Specified by:
      getMaxIntermediateSize in class AggregatorFactory
      Returns:
      the maximum number of bytes that an aggregator of this type will require for intermediate result storage.
    • withName

      public AggregatorFactory withName(String newName)
      Description copied from class: AggregatorFactory
      Used in cases where we want to change the output name of the aggregator to something else. For eg: if we have a query `select a, sum(b) as total group by a from table` the aggregator returned from the native group by query is "a0" set in
      invalid reference
      org.apache.druid.sql.calcite.rel.DruidQuery#computeAggregations
      . We can use withName("total") to set the output name of the aggregator to "total".

      As all implementations of this interface method may not exist, callers of this method are advised to handle such a case.

      Overrides:
      withName in class AggregatorFactory
      Parameters:
      newName - newName of the output for aggregator factory
      Returns:
      AggregatorFactory with the output name set as the input param.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object