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



##########
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:
       Good call! Changed. Actually I have to extract only `Math.abs(hash % 
numBuckets)` because in the function used by ingestion `static ShardSpecLookup 
createHashLookup` only needs `Math.abs(hash % numBuckets)` instead of the whole 
statement you mentioned.

##########
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:
       Oh, I mean in the shard spec, we don't store truncated timestamps of the 
events that fall into the shard. I've rephrased it. Let me know if it makes 
sense or needs more clarification.




----------------------------------------------------------------
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