diff --git a/processing/src/main/java/org/apache/druid/query/SampledTableDataSource.java b/processing/src/main/java/org/apache/druid/query/SampledTableDataSource.java index 17ee748e173f..5d1dd777f171 100644 --- a/processing/src/main/java/org/apache/druid/query/SampledTableDataSource.java +++ b/processing/src/main/java/org/apache/druid/query/SampledTableDataSource.java @@ -23,24 +23,15 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.common.base.Preconditions; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.atomic.AtomicLong; -import java.util.function.Function; import org.apache.druid.java.util.common.Cacheable; -import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.StringUtils; -import org.apache.druid.query.planning.DataSourceAnalysis; -import org.apache.druid.segment.SegmentReference; @JsonTypeName("sampled_table") public class SampledTableDataSource extends TableDataSource { private final SamplingType samplingType; private final int samplingPercentage; + public enum SamplingType implements Cacheable { FIXED_SHARD; @@ -88,17 +79,20 @@ public static SampledTableDataSource create( @JsonProperty - public SamplingType getSamplingType() { + public SamplingType getSamplingType() + { return samplingType; } @JsonProperty - public float getSamplingPercentage() { + public float getSamplingPercentage() + { return samplingPercentage; } @Override - public boolean equals(Object o) { + public boolean equals(Object o) + { if (this == o) { return true; } @@ -118,7 +112,8 @@ public boolean equals(Object o) { } @Override - public int hashCode() { + public int hashCode() + { int result = super.hashCode(); result = 31 * result + (samplingType != null ? samplingType.hashCode() : 0); result = 31 * result + samplingPercentage; diff --git a/processing/src/main/java/org/apache/druid/query/context/ResponseContext.java b/processing/src/main/java/org/apache/druid/query/context/ResponseContext.java index dfd7299f56ce..34cdb580eb70 100644 --- a/processing/src/main/java/org/apache/druid/query/context/ResponseContext.java +++ b/processing/src/main/java/org/apache/druid/query/context/ResponseContext.java @@ -745,6 +745,12 @@ public void addCpuNanos(long ns) addValue(Keys.CPU_CONSUMED_NANOS, ns); } + + public void addSamplingComposition(String samplingComposition) + { + addValue(Keys.SAMPLING_COMPOSITION, samplingComposition); + } + private Object addValue(Key key, Object value) { return getDelegate().merge(key, value, key::mergeValues); diff --git a/processing/src/main/java/org/apache/druid/query/planning/DataSourceAnalysis.java b/processing/src/main/java/org/apache/druid/query/planning/DataSourceAnalysis.java index 7f23eb217cf8..dfea4cc36d19 100644 --- a/processing/src/main/java/org/apache/druid/query/planning/DataSourceAnalysis.java +++ b/processing/src/main/java/org/apache/druid/query/planning/DataSourceAnalysis.java @@ -114,7 +114,8 @@ public DataSource getBaseDataSource() * Note that this can return empty even if {@link #isConcreteAndTableBased()} is true. This happens if the base * datasource is a {@link UnionDataSource} of {@link TableDataSource}. */ - public Optional getBaseTableDataSource() { + public Optional getBaseTableDataSource() + { if (baseDataSource instanceof TableDataSource) { return Optional.of((TableDataSource) baseDataSource); } else if (baseDataSource instanceof SampledTableDataSource) { diff --git a/processing/src/main/java/org/apache/druid/query/topn/TopNQueryEngine.java b/processing/src/main/java/org/apache/druid/query/topn/TopNQueryEngine.java index 084db4b61934..50b8a30d1028 100644 --- a/processing/src/main/java/org/apache/druid/query/topn/TopNQueryEngine.java +++ b/processing/src/main/java/org/apache/druid/query/topn/TopNQueryEngine.java @@ -132,7 +132,7 @@ private TopNMapFn getMapFn( final TopNAlgorithm topNAlgorithm; - if (canUsePooledAlgorithm(selector, query, columnCapabilities)) { + if (canUsePooledAlgorithm(selector, query, columnCapabilities)) { // pool based algorithm selection, if we can if (selector.isAggregateAllMetrics()) { // if sorted by dimension we should aggregate all metrics in a single pass, use the regular pooled algorithm for diff --git a/server/src/main/java/org/apache/druid/client/CachingClusteredClient.java b/server/src/main/java/org/apache/druid/client/CachingClusteredClient.java index e4c11020e386..590a29e4a8d4 100644 --- a/server/src/main/java/org/apache/druid/client/CachingClusteredClient.java +++ b/server/src/main/java/org/apache/druid/client/CachingClusteredClient.java @@ -19,8 +19,6 @@ package org.apache.druid.client; -import static org.apache.druid.query.context.ResponseContext.Keys.SAMPLING_COMPOSITION; - import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.annotations.VisibleForTesting; @@ -350,7 +348,7 @@ ClusterQueryResult run( final Set segmentServers = computeSegmentsToQuery(timeline, specificSegments); Pair ratio = pruneSegmentsForShardSampling(segmentServers); if (ratio != null) { - responseContext.add(SAMPLING_COMPOSITION, ratio.lhs + "/" + ratio.rhs); + responseContext.addSamplingComposition(ratio.lhs + "/" + ratio.rhs); } @Nullable final byte[] queryCacheKey = cacheKeyManager.computeSegmentLevelQueryCacheKey(); @@ -512,7 +510,8 @@ private void computeUncoveredIntervals(TimelineLookup ti } } - private Pair pruneSegmentsForShardSampling(final Set segments) { + private Pair pruneSegmentsForShardSampling(final Set segments) + { if (query.getDataSource() instanceof SampledTableDataSource) { if (((SampledTableDataSource) query.getDataSource()).getSamplingType() == SamplingType.FIXED_SHARD) {