Class SuppressedAggregatorFactory
- java.lang.Object
-
- org.apache.druid.query.aggregation.AggregatorFactory
-
- org.apache.druid.query.aggregation.SuppressedAggregatorFactory
-
- All Implemented Interfaces:
Cacheable
public class SuppressedAggregatorFactory extends AggregatorFactory
This AggregatorFactory is meant for wrapping delegate aggregators for optimization purposes. The wrapper suppresses the aggregate() method for the underlying delegate, while leaving the behavior of other calls unchanged. This wrapper is meant to be used when an optimization decides that an aggregator can be entirely skipped (e.g., a FilteredAggregatorFactory where the filter condition will never match).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSuppressedAggregatorFactory.SuppressedAggregatorstatic classSuppressedAggregatorFactory.SuppressedBufferAggregatorstatic classSuppressedAggregatorFactory.SuppressedVectorAggregator
-
Constructor Summary
Constructors Constructor Description SuppressedAggregatorFactory(AggregatorFactory delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanVectorize(ColumnInspector columnInspector)Returns whether or not this aggregation class supports vectorization.Objectcombine(Object lhs, Object rhs)A method that knows how to combine the outputs ofAggregator.get()produced viaAggregatorFactory.factorize(org.apache.druid.segment.ColumnSelectorFactory)orBufferAggregator.get(java.nio.ByteBuffer, int)produced viaAggregatorFactory.factorizeBuffered(org.apache.druid.segment.ColumnSelectorFactory).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)VectorAggregatorfactorizeVector(VectorColumnSelectorFactory columnSelectorFactory)Create a VectorAggregator based on the provided column selector factory.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()AggregatorFactorygetDelegate()ColumnTypegetIntermediateType()Get the "intermediate"ColumnTypefor this aggregator.intgetMaxIntermediateSize()Returns the maximum size that this aggregator will require in bytes for intermediate storage of results.intgetMaxIntermediateSizeWithNulls()Returns the maximum size that this aggregator will require in bytes for intermediate storage of results.AggregatorFactorygetMergingFactory(AggregatorFactory other)Returns an AggregatorFactory that can be used to combine the output of aggregators from this factory and another factory.StringgetName()ColumnTypegetResultType()Get theColumnTypefor the final form of this aggregator, i.e.inthashCode()AggregateCombinermakeAggregateCombiner()Creates an AggregateCombiner to fold rollup aggregation results from serveral "rows" of different indexes during index merging.AggregatorFactoryoptimizeForSegment(PerSegmentQueryOptimizationContext optimizationContext)Return a potentially optimized form of this AggregatorFactory for per-segment queries.List<String>requiredFields()Get a list of fields that aggregators built by this factory will need to read.StringtoString()AggregatorFactorywithName(String newName)Used in cases where we want to change the output name of the aggregator to something else.-
Methods inherited from class org.apache.druid.query.aggregation.AggregatorFactory
factorizeWithSize, getComplexTypeName, getFinalizedType, getRequiredColumns, getType, guessAggregatorHeapFootprint, makeNullableAggregateCombiner, mergeAggregators
-
-
-
-
Constructor Detail
-
SuppressedAggregatorFactory
public SuppressedAggregatorFactory(AggregatorFactory delegate)
-
-
Method Detail
-
factorize
public Aggregator factorize(ColumnSelectorFactory metricFactory)
- Specified by:
factorizein classAggregatorFactory
-
factorizeBuffered
public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory)
- Specified by:
factorizeBufferedin classAggregatorFactory
-
factorizeVector
public VectorAggregator factorizeVector(VectorColumnSelectorFactory columnSelectorFactory)
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
-
canVectorize
public boolean canVectorize(ColumnInspector columnInspector)
Description copied from class:AggregatorFactoryReturns whether or not this aggregation class supports vectorization. The default implementation returns false.- Overrides:
canVectorizein classAggregatorFactory
-
getComparator
public Comparator getComparator()
- Specified by:
getComparatorin classAggregatorFactory
-
combine
public Object combine(Object lhs, Object rhs)
Description copied from class:AggregatorFactoryA method that knows how to combine the outputs ofAggregator.get()produced viaAggregatorFactory.factorize(org.apache.druid.segment.ColumnSelectorFactory)orBufferAggregator.get(java.nio.ByteBuffer, int)produced viaAggregatorFactory.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:
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
-
makeAggregateCombiner
public AggregateCombiner makeAggregateCombiner()
Description copied from class:AggregatorFactoryCreates an AggregateCombiner to fold rollup aggregation results from serveral "rows" of different indexes during index merging. AggregateCombiner implements the same logic asAggregatorFactory.combine(java.lang.Object, java.lang.Object), with the difference that it usesColumnValueSelectorand it's subinterfaces to get inputs and implementsColumnValueSelectorto provide output.- Overrides:
makeAggregateCombinerin classAggregatorFactory- See Also:
AggregateCombiner,IndexMerger
-
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.
-
getMergingFactory
public AggregatorFactory getMergingFactory(AggregatorFactory other) throws AggregatorFactoryNotMergeableException
Description copied from class:AggregatorFactoryReturns an AggregatorFactory that can be used to combine the output of aggregators from this factory and another factory. It is used when we have some values produced by this aggregator factory, and some values produced by the "other" aggregator factory, and we want to do some additional combining of them. This happens, for example, when compacting two segments together that both have a metric column with the same name. (Even though the name of the column is the same, the aggregator factory used to create it may be different from segment to segment.) This method may throwAggregatorFactoryNotMergeableException, meaning that "this" and "other" are not compatible and values from one cannot sensibly be combined with values from the other.- Overrides:
getMergingFactoryin classAggregatorFactory- Returns:
- a new Factory that can be used for merging the output of aggregators from this factory and other.
- Throws:
AggregatorFactoryNotMergeableException- See Also:
which is equivalent to (when "this" and "other" are the same instance).
-
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
-
getName
public String getName()
- Specified by:
getNamein classAggregatorFactory- Returns:
- output name of the aggregator column.
-
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
-
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
-
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.
-
getMaxIntermediateSizeWithNulls
public 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.
-
optimizeForSegment
public AggregatorFactory optimizeForSegment(PerSegmentQueryOptimizationContext optimizationContext)
Description copied from class:AggregatorFactoryReturn a potentially optimized form of this AggregatorFactory for per-segment queries.- Overrides:
optimizeForSegmentin classAggregatorFactory
-
withName
public AggregatorFactory withName(String newName)
Description copied from class:AggregatorFactoryUsed 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 inorg.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:
withNamein classAggregatorFactory- Parameters:
newName- newName of the output for aggregator factory- Returns:
- AggregatorFactory with the output name set as the input param.
-
getCacheKey
public byte[] getCacheKey()
Description copied from interface:CacheableGet a byte array used as a cache key.- Returns:
- a cache key
-
getDelegate
public AggregatorFactory getDelegate()
-
-