jihoonson commented on a change in pull request #5857: Optimize filtered aggs with interval filters in per-segment queries URL: https://github.com/apache/incubator-druid/pull/5857#discussion_r206665169
########## File path: processing/src/main/java/io/druid/query/aggregation/SuppressedAggregatorFactory.java ########## @@ -0,0 +1,375 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.druid.query.aggregation; + +import io.druid.query.PerSegmentQueryOptimizationContext; +import io.druid.query.monomorphicprocessing.RuntimeShapeInspector; +import io.druid.segment.ColumnSelectorFactory; + +import javax.annotation.Nullable; +import java.nio.ByteBuffer; +import java.util.Comparator; +import java.util.List; +import java.util.Objects; + +/** + * 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). + */ +public class SuppressedAggregatorFactory extends AggregatorFactory +{ + private final AggregatorFactory delegate; + + public SuppressedAggregatorFactory( + AggregatorFactory delegate + ) + { + this.delegate = delegate; + } + + @Override + public Aggregator factorize(ColumnSelectorFactory metricFactory) + { + return new SuppressedAggregator(delegate.factorize(metricFactory)); + } + + @Override + public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory) + { + return new SuppressedBufferAggregator(delegate.factorizeBuffered(metricFactory)); + } + + @Override + public Comparator getComparator() + { + return delegate.getComparator(); + } + + @Override + public Object combine(Object lhs, Object rhs) + { + return delegate.combine(lhs, rhs); + } + + @Override + public AggregateCombiner makeAggregateCombiner() + { + return delegate.makeAggregateCombiner(); + } + + @Override + public AggregatorFactory getCombiningFactory() + { + return delegate.getCombiningFactory(); + } + + @Override + public AggregatorFactory getMergingFactory(AggregatorFactory other) throws AggregatorFactoryNotMergeableException + { + return delegate.getMergingFactory(other); + } + + @Override + public List<AggregatorFactory> getRequiredColumns() + { + return delegate.getRequiredColumns(); + } + + @Override + public Object deserialize(Object object) + { + return delegate.deserialize(object); + } + + @Override + public Object finalizeComputation(Object object) + { + return delegate.finalizeComputation(object); + } + + @Override + public String getName() + { + return delegate.getName(); + } + + @Override + public List<String> requiredFields() + { + return delegate.requiredFields(); + } + + @Override + public String getTypeName() + { + return delegate.getTypeName(); + } + + @Override + public int getMaxIntermediateSize() + { + return delegate.getMaxIntermediateSize(); + } + + @Override + public AggregatorFactory optimizeForSegment(PerSegmentQueryOptimizationContext optimizationContext) + { + // we are already the result of an optimizeForSegment() call + return this; + } + + @Override + public byte[] getCacheKey() + { + byte[] delegateCacheKey = delegate.getCacheKey(); + return ByteBuffer.allocate(1 + delegateCacheKey.length) Review comment: Please use `CacheKeyBuilder`. `AggregatorFactory` is `Cacheable`, so that you can simply use `builder.appendCacheable()`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
