voonhous commented on code in PR #19776:
URL: https://github.com/apache/hudi/pull/19776#discussion_r3902001123


##########
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/TestCoalescingPartitioner.java:
##########
@@ -184,4 +184,20 @@ public WriteStatus call(Tuple2<String, WriteStatus> 
booleanIntegerTuple2) throws
       return booleanIntegerTuple2._2;
     }
   }
+
+  /**
+   * "polygenelubricants" hashes to Integer.MIN_VALUE, which Math.abs leaves 
negative, so a
+   * partitioner deriving its answer that way returns an index Spark cannot 
use. Asserting the
+   * fixture first, so this stops silently passing if String.hashCode ever 
changes.
+   */
+  @Test
+  public void testPartitionIsInRangeForMinValueHash() {
+    String key = "polygenelubricants";
+    assertEquals(Integer.MIN_VALUE, key.hashCode());
+    for (int numPartitions : new int[] {1, 2, 3, 4, 5, 6, 7, 8, 16}) {
+      int partition = new 
CoalescingPartitioner(numPartitions).getPartition(key);
+      assertTrue(partition >= 0 && partition < numPartitions,
+          "partition " + partition + " out of range for numPartitions " + 
numPartitions);
+    }

Review Comment:
   Now asserts against `HashPartitioner` for negative and non-negative keys 
across 1..16, with the fixture hash and the power-of-two note kept.



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

To unsubscribe, e-mail: [email protected]

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

Reply via email to