Class NullableNumericAggregatorFactory<T extends BaseNullableColumnValueSelector>
java.lang.Object
org.apache.druid.query.aggregation.AggregatorFactory
org.apache.druid.query.aggregation.NullableNumericAggregatorFactory<T>
- All Implemented Interfaces:
Cacheable
- Direct Known Subclasses:
SimpleDoubleAggregatorFactory,SimpleFloatAggregatorFactory,SimpleLongAggregatorFactory
public abstract class NullableNumericAggregatorFactory<T extends BaseNullableColumnValueSelector>
extends AggregatorFactory
Abstract superclass for null-aware numeric aggregators.
Includes functionality to wrap
Aggregator, BufferAggregator, VectorAggregator, and
AggregateCombiner to support nullable aggregations. The result of this aggregator will be null if all the
values to be aggregated are null values, or if no values are aggregated at all. If any of the values are non-null,
the result will be the aggregated value of the non-null values.
Aggregators that use BaseObjectColumnValueSelector.getObject() must override
useGetObject(ColumnSelectorFactory). Otherwise, the logic in this class is not correct for
non-numeric selectors.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Aggregatorfactorize(ColumnSelectorFactory columnSelectorFactory) protected abstract Aggregatorfactorize(ColumnSelectorFactory columnSelectorFactory, T selector) Creates anAggregatorto aggregate values from several rows, by using the provided selector.final BufferAggregatorfactorizeBuffered(ColumnSelectorFactory columnSelectorFactory) protected abstract BufferAggregatorfactorizeBuffered(ColumnSelectorFactory columnSelectorFactory, T selector) Creates anBufferAggregatorto aggregate values from several rows into a ByteBuffer.final VectorAggregatorfactorizeVector(VectorColumnSelectorFactory columnSelectorFactory) Create a VectorAggregator based on the provided column selector factory.protected VectorAggregatorfactorizeVector(VectorColumnSelectorFactory columnSelectorFactory, VectorValueSelector selector) Creates aVectorAggregatorto aggregate values from several rows into a ByteBuffer.booleanIf true, this aggregator will not check for null inputs, instead directly delegating to the underlying aggregator.final intReturns the maximum size that this aggregator will require in bytes for intermediate storage of results.Get theColumnTypefor the final form of this aggregator, i.e.final AggregateCombinerCreates anAggregateCombinerwhich supports nullability.protected abstract Tselector(ColumnSelectorFactory columnSelectorFactory) Creates aColumnValueSelectorfor the aggregated column.protected booleanuseGetObject(ColumnSelectorFactory columnSelectorFactory) Returns whether the selector created byselector(ColumnSelectorFactory)for the givenColumnSelectorFactoryprefersBaseObjectColumnValueSelector.getObject().protected VectorValueSelectorvectorSelector(VectorColumnSelectorFactory columnSelectorFactory) Creates aVectorValueSelectorfor the aggregated column.Methods inherited from class org.apache.druid.query.aggregation.AggregatorFactory
canVectorize, combine, deserialize, factorizeWithSize, finalizeComputation, getCombiningFactory, getComparator, getComplexTypeName, getFinalizedType, getIntermediateType, getMaxIntermediateSize, getMergingFactory, getName, getRequiredColumns, getType, guessAggregatorHeapFootprint, makeAggregateCombiner, mergeAggregators, optimizeForSegment, requiredFields, substituteCombiningFactory, withNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.druid.java.util.common.Cacheable
getCacheKey
-
Constructor Details
-
NullableNumericAggregatorFactory
public NullableNumericAggregatorFactory()
-
-
Method Details
-
forceNotNullable
public boolean forceNotNullable()If true, this aggregator will not check for null inputs, instead directly delegating to the underlying aggregator. Currently, this is only used byCountAggregatorFactory.getCombiningFactory(). This isn't entirely safe, as some selectors might throw an exception when attempting to retrieve a primitive value from `null`. -
factorize
- Specified by:
factorizein classAggregatorFactory
-
factorizeBuffered
- Specified by:
factorizeBufferedin classAggregatorFactory
-
factorizeVector
Description copied from class:AggregatorFactoryCreate a VectorAggregator based on the provided column selector factory. Will throw an exception if this aggregation class does not support vectorization: check "canVectorize" first.- Overrides:
factorizeVectorin classAggregatorFactory
-
makeNullableAggregateCombiner
Description copied from class:AggregatorFactoryCreates anAggregateCombinerwhich supports nullability. Implementations ofAggregatorFactorywhich need to Support Nullable Aggregations are encouraged to extendNullableNumericAggregatorFactoryinstead of overriding this method. Default implementation callsAggregatorFactory.makeAggregateCombiner()for backwards compatibility.- Overrides:
makeNullableAggregateCombinerin classAggregatorFactory- See Also:
-
getMaxIntermediateSizeWithNulls
public final int getMaxIntermediateSizeWithNulls()Description copied from class:AggregatorFactoryReturns the maximum size that this aggregator will require in bytes for intermediate storage of results. Implementations ofAggregatorFactorywhich need to Support Nullable Aggregations are encouraged to extendNullableNumericAggregatorFactoryinstead of overriding this method. Default implementation callsAggregatorFactory.makeAggregateCombiner()for backwards compatibility.- Overrides:
getMaxIntermediateSizeWithNullsin classAggregatorFactory- Returns:
- the maximum number of bytes that an aggregator of this type will require for intermediate result storage.
-
selector
Creates aColumnValueSelectorfor the aggregated column.- See Also:
-
useGetObject
Returns whether the selector created byselector(ColumnSelectorFactory)for the givenColumnSelectorFactoryprefersBaseObjectColumnValueSelector.getObject(). For backwards compatibilty with older extensions, this is a non-abstract method. -
vectorSelector
Creates aVectorValueSelectorfor the aggregated column.- See Also:
-
factorize
Creates anAggregatorto aggregate values from several rows, by using the provided selector.- Parameters:
columnSelectorFactory- metricFactoryselector-ColumnValueSelectorfor the column to aggregate.- See Also:
-
factorizeBuffered
protected abstract BufferAggregator factorizeBuffered(ColumnSelectorFactory columnSelectorFactory, T selector) Creates anBufferAggregatorto aggregate values from several rows into a ByteBuffer.- Parameters:
columnSelectorFactory- columnSelectorFactory in case any other columns are needed.selector-ColumnValueSelectorfor the column to aggregate.- See Also:
-
factorizeVector
protected VectorAggregator factorizeVector(VectorColumnSelectorFactory columnSelectorFactory, VectorValueSelector selector) Creates aVectorAggregatorto aggregate values from several rows into a ByteBuffer.- Parameters:
columnSelectorFactory- columnSelectorFactory in case any other columns are needed.selector-VectorValueSelectorfor the column to aggregate.- See Also:
-
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
-