diff --git a/processing/src/main/java/org/apache/druid/query/filter/DimFilterUtils.java b/processing/src/main/java/org/apache/druid/query/filter/DimFilterUtils.java index dad5cfd98b3..ff863f764b7 100644 --- a/processing/src/main/java/org/apache/druid/query/filter/DimFilterUtils.java +++ b/processing/src/main/java/org/apache/druid/query/filter/DimFilterUtils.java @@ -20,6 +20,7 @@ package org.apache.druid.query.filter; import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.RangeSet; import org.apache.druid.query.planning.DataSourceAnalysis; import org.apache.druid.timeline.partition.ShardSpec; @@ -116,13 +117,19 @@ public class DimFilterUtils final Map>> dimensionRangeCache ) { + if (dimFilter == null) { + // ImmutableSet retains order from "input". + return ImmutableSet.copyOf(input); + } + + // LinkedHashSet retains order from "input". Set retSet = new LinkedHashSet<>(); for (T obj : input) { ShardSpec shard = converter.apply(obj); boolean include = true; - if (dimFilter != null && shard != null) { + if (shard != null) { Map> filterDomain = new HashMap<>(); List dimensions = shard.getDomainDimensions(); for (String dimension : dimensions) {