Class SingleValueAggregatorFactory
- java.lang.Object
-
- org.apache.druid.query.aggregation.AggregatorFactory
-
- org.apache.druid.query.aggregation.SingleValueAggregatorFactory
-
- All Implemented Interfaces:
Cacheable
public class SingleValueAggregatorFactory extends AggregatorFactory
This AggregatorFactory is meant to wrap the subquery used as an expression into a single value and is expected to throw an exception when the subquery results in more than one rowThis consumes columnType as well along with name and fieldName to pass it on to underlying
SingleValueBufferAggregatorto work with different ColumnTypes
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_VALUE_SIZE
-
Constructor Summary
Constructors Constructor Description SingleValueAggregatorFactory(String name, String fieldName, ColumnType columnType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectcombine(Object lhs, Object rhs)Combine method would never be invoked as the broker sends the subquery to multiple segments and gather the results to a single value on which the single value aggregator is applied.Objectdeserialize(Object object)A method that knows how to "deserialize" the object from whatever form it might have been put into in order to transfer via JSON.booleanequals(Object o)Aggregatorfactorize(ColumnSelectorFactory metricFactory)BufferAggregatorfactorizeBuffered(ColumnSelectorFactory metricFactory)ObjectfinalizeComputation(Object object)"Finalizes" the computation of an object.byte[]getCacheKey()Get a byte array used as a cache key.AggregatorFactorygetCombiningFactory()Returns an AggregatorFactory that can be used to combine the output of aggregators from this factory.ComparatorgetComparator()StringgetFieldName()ColumnTypegetIntermediateType()Get the "intermediate"ColumnTypefor this aggregator.intgetMaxIntermediateSize()Returns the maximum size that this aggregator will require in bytes for intermediate storage of results.StringgetName()ColumnTypegetResultType()Get theColumnTypefor the final form of this aggregator, i.e.inthashCode()List<String>requiredFields()Get a list of fields that aggregators built by this factory will need to read.StringtoString()-
Methods inherited from class org.apache.druid.query.aggregation.AggregatorFactory
canVectorize, factorizeVector, factorizeWithSize, getComplexTypeName, getFinalizedType, getMaxIntermediateSizeWithNulls, getMergingFactory, getRequiredColumns, getType, guessAggregatorHeapFootprint, makeAggregateCombiner, makeNullableAggregateCombiner, mergeAggregators, optimizeForSegment, substituteCombiningFactory, withName
-
-
-
-
Field Detail
-
DEFAULT_MAX_VALUE_SIZE
public static final int DEFAULT_MAX_VALUE_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SingleValueAggregatorFactory
public SingleValueAggregatorFactory(String name, String fieldName, ColumnType columnType)
-
-
Method Detail
-
factorize
public Aggregator factorize(ColumnSelectorFactory metricFactory)
- Specified by:
factorizein classAggregatorFactory
-
factorizeBuffered
public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory)
- Specified by:
factorizeBufferedin classAggregatorFactory
-
getComparator
public Comparator getComparator()
- Specified by:
getComparatorin classAggregatorFactory
-
combine
@Nullable public Object combine(@Nullable Object lhs, @Nullable Object rhs)
Combine method would never be invoked as the broker sends the subquery to multiple segments and gather the results to a single value on which the single value aggregator is applied. Though getCombiningFactory would be invoked for understanding the fieldname.- Specified by:
combinein classAggregatorFactory- Parameters:
lhs- The left hand side of the combinerhs- 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
-
getCombiningFactory
public AggregatorFactory getCombiningFactory()
Description copied from class:AggregatorFactoryReturns 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, theCountAggregatorFactorygetCombiningFactory method will return aLongSumAggregatorFactory, because counts are combined by summing. No matter what, `foo.getCombiningFactory()` and `foo.getCombiningFactory().getCombiningFactory()` should return the same result.- Specified by:
getCombiningFactoryin classAggregatorFactory- Returns:
- a new Factory that can be used for operations on top of data output from the current factory.
-
deserialize
public Object deserialize(Object object)
Description copied from class:AggregatorFactoryA 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:
deserializein classAggregatorFactory- 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:
finalizeComputationin classAggregatorFactory- Parameters:
object- the object to be finalized- Returns:
- the finalized value that should be returned for the initial query
-
getIntermediateType
public ColumnType getIntermediateType()
Description copied from class:AggregatorFactoryGet the "intermediate"ColumnTypefor this aggregator. This is the same as the type returned byAggregatorFactory.deserialize(java.lang.Object)and the type accepted byAggregatorFactory.combine(java.lang.Object, java.lang.Object). However, it is *not* necessarily the same type returned byAggregatorFactory.finalizeComputation(java.lang.Object). Refer to theColumnTypejavadocs for details on the implications of choosing a type.- Overrides:
getIntermediateTypein classAggregatorFactory
-
getResultType
public ColumnType getResultType()
Description copied from class:AggregatorFactoryGet theColumnTypefor the final form of this aggregator, i.e. the type of the value returned byAggregatorFactory.finalizeComputation(java.lang.Object). This may be the same as or different than the types expected inAggregatorFactory.deserialize(java.lang.Object)andAggregatorFactory.combine(java.lang.Object, java.lang.Object). Refer to theColumnTypejavadocs for details on the implications of choosing a type.- Overrides:
getResultTypein classAggregatorFactory
-
getName
public String getName()
- Specified by:
getNamein classAggregatorFactory- Returns:
- output name of the aggregator column.
-
getFieldName
public String getFieldName()
-
requiredFields
public List<String> requiredFields()
Description copied from class:AggregatorFactoryGet a list of fields that aggregators built by this factory will need to read.- Specified by:
requiredFieldsin classAggregatorFactory
-
getMaxIntermediateSize
public int getMaxIntermediateSize()
Description copied from class:AggregatorFactoryReturns the maximum size that this aggregator will require in bytes for intermediate storage of results.- Specified by:
getMaxIntermediateSizein classAggregatorFactory- Returns:
- the maximum number of bytes that an aggregator of this type will require for intermediate result storage.
-
getCacheKey
public byte[] getCacheKey()
Description copied from interface:CacheableGet a byte array used as a cache key.- Returns:
- a cache key
-
-