rdblue commented on code in PR #18604:
URL: https://github.com/apache/iceberg/pull/18604#discussion_r4462094324


##########
core/src/test/java/org/apache/iceberg/TestStatsUtil.java:
##########
@@ -564,6 +572,293 @@ public void testContentStatsWriteSchemaOmitsListAndMap() {
     assertThat(actual.fields()).isEmpty();
   }
 
+  @Test
+  void identityBounds() {
+    assertThat(sourceBounds(Types.StringType.get(), Transforms.identity(), 
"books"))
+        .isEqualTo(new StatsUtil.PartitionSourceBounds<>("books", "books"));
+  }
+
+  @Test
+  void identityNaN() {
+    assertThat(sourceBounds(Types.FloatType.get(), Transforms.identity(), 
Float.NaN)).isNull();
+    assertThat(sourceBounds(Types.DoubleType.get(), Transforms.identity(), 
Double.NaN)).isNull();
+  }
+
+  private static Stream<Partition> truncatedNumbers() {
+    Type decimal = Types.DecimalType.of(9, 2);
+    return Stream.of(
+        partition(Types.IntegerType.get(), Transforms.truncate(10), 
20).withExpectedBounds(20, 29),
+        partition(Types.IntegerType.get(), Transforms.truncate(10), -10)
+            .withExpectedBounds(-10, -1),
+        partition(Types.LongType.get(), Transforms.truncate(100), 12_300L)
+            .withExpectedBounds(12_300L, 12_399L),
+        partition(decimal, Transforms.truncate(50), new BigDecimal("12.00"))
+            .withExpectedBounds(new BigDecimal("12.00"), new 
BigDecimal("12.49")),
+        partition(decimal, Transforms.truncate(50), new BigDecimal("-0.50"))
+            .withExpectedBounds(new BigDecimal("-0.50"), new 
BigDecimal("-0.01")));
+  }
+
+  @ParameterizedTest
+  @MethodSource("truncatedNumbers")
+  void truncateNumberBounds(Partition partition) {
+    assertThat(sourceBounds(partition)).isEqualTo(partition.expected());
+  }
+
+  @Test
+  void truncateNumberNearMax() {
+    assertThat(sourceBounds(Types.IntegerType.get(), Transforms.truncate(10), 
2_147_483_640))
+        .isEqualTo(new StatsUtil.PartitionSourceBounds<>(2_147_483_640, 
Integer.MAX_VALUE));
+    assertThat(sourceBounds(Types.LongType.get(), Transforms.truncate(100), 
Long.MAX_VALUE - 7))

Review Comment:
   Use a constant like the integer case.



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


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

Reply via email to