jihoonson commented on a change in pull request #9810:
URL: https://github.com/apache/druid/pull/9810#discussion_r462597040



##########
File path: 
server/src/test/java/org/apache/druid/client/CachingClusteredClientTest.java
##########
@@ -1541,6 +1543,135 @@ public void testSingleDimensionPruning()
     Assert.assertEquals(expected, ((TimeseriesQuery) 
capture.getValue().getQuery()).getQuerySegmentSpec());
   }
 
+  @Test
+  public void testHashBasedPruning()
+  {
+    DimFilter filter = new AndDimFilter(
+        new SelectorDimFilter("dim1", "a", null),
+        new BoundDimFilter("dim2", "e", "zzz", true, true, false, null, 
StringComparators.LEXICOGRAPHIC),
+        // Equivalent filter of dim3 below is InDimFilter("dim3", 
Arrays.asList("c"), null)
+        new AndDimFilter(
+            new InDimFilter("dim3", Arrays.asList("a", "c", "e", "g"), null),
+            new BoundDimFilter("dim3", "aaa", "ddd", false, false, false, 
null, StringComparators.LEXICOGRAPHIC)
+        )
+    );
+
+    final Druids.TimeseriesQueryBuilder builder = 
Druids.newTimeseriesQueryBuilder()
+                                                        
.dataSource(DATA_SOURCE)
+                                                        .filters(filter)
+                                                        
.granularity(GRANULARITY)
+                                                        .intervals(SEG_SPEC)
+                                                        .context(CONTEXT)
+                                                        
.intervals("2011-01-05/2011-01-10")
+                                                        
.aggregators(RENAMED_AGGS)
+                                                        
.postAggregators(RENAMED_POST_AGGS);

Review comment:
       You can fix the ci failure by adding `.randomQueryId()` here.

##########
File path: 
core/src/main/java/org/apache/druid/timeline/partition/HashBasedNumberedShardSpec.java
##########
@@ -192,4 +229,71 @@ public String toString()
            ", partitionDimensions=" + partitionDimensions +
            '}';
   }
+
+  @Override
+  public boolean possibleInDomain(Map<String, RangeSet<String>> domain)
+  {
+    // If no partitionDimensions are specified during ingestion, hash is based 
on all dimensions plus the truncated
+    // input timestamp according to QueryGranularity instead of just 
partitionDimensions. Since we don't store the
+    // timestamp after ingestion, bypass this case

Review comment:
       Thanks for making it more clear!

##########
File path: 
core/src/main/java/org/apache/druid/timeline/partition/HashBasedNumberedShardSpec.java
##########
@@ -90,10 +98,39 @@ public int getNumBuckets()
     return partitionDimensions;
   }
 
+  @Override
+  public List<String> getDomainDimensions()
+  {
+    return partitionDimensions;
+  }
+
   @Override
   public boolean isInChunk(long timestamp, InputRow inputRow)
   {
-    return (((long) hash(timestamp, inputRow)) - bucketId) % numBuckets == 0;
+    return Math.abs(hash(timestamp, inputRow) % numBuckets) == bucketId % 
numBuckets;
+  }
+
+  /**
+   * Check if the current segment possibly holds records if the values of 
dimensions in {@link #partitionDimensions}
+   * are of {@code partitionDimensionsValues}
+   *
+   * @param partitionDimensionsValues An instance of values of dimensions in 
{@link #partitionDimensions}
+   *
+   * @return Whether the current segment possibly holds records for the given 
values of partition dimensions
+   */
+  private boolean isInChunk(Map<String, String> partitionDimensionsValues)
+  {
+    assert !partitionDimensions.isEmpty();
+    List<Object> groupKey = Lists.transform(
+        partitionDimensions,
+        o -> Collections.singletonList(partitionDimensionsValues.get(o))
+    );
+    try {
+      return Math.abs(hash(jsonMapper, groupKey) % numBuckets) == bucketId % 
numBuckets;

Review comment:
       :+1: 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to