jihoonson commented on a change in pull request #9810:
URL: https://github.com/apache/druid/pull/9810#discussion_r462038053
##########
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:
Hmm, did you mean queryGranularity instead of timestamp? Druid does
store timestamp, but it's not possible to get the query granularity after
ingestion.
##########
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:
Can we extract `Math.abs(hash % numBuckets) == bucketId % numBuckets` as
a common method so that we can avoid a [mistake that you have
fixed](https://github.com/apache/druid/pull/9810#discussion_r418961446) in the
future?
----------------------------------------------------------------
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]