rdblue commented on code in PR #18604:
URL: https://github.com/apache/iceberg/pull/18604#discussion_r4462138425
##########
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))
+ .isEqualTo(new StatsUtil.PartitionSourceBounds<>(Long.MAX_VALUE - 7,
Long.MAX_VALUE));
+ assertThat(
+ sourceBounds(
+ Types.DecimalType.of(9, 2), Transforms.truncate(7), new
BigDecimal("9999999.94")))
+ .isEqualTo(
+ new StatsUtil.PartitionSourceBounds<>(
+ new BigDecimal("9999999.94"), new BigDecimal("9999999.99")));
+ }
+
+ @Test
+ void truncateNumberAtMinWraps() {
+ assertThat(sourceBounds(Types.IntegerType.get(), Transforms.truncate(10),
2_147_483_646))
+ .isEqualTo(new StatsUtil.PartitionSourceBounds<>(Integer.MIN_VALUE,
Integer.MIN_VALUE + 7));
+ assertThat(
+ sourceBounds(Types.LongType.get(), Transforms.truncate(10),
9_223_372_036_854_775_806L))
+ .isEqualTo(new StatsUtil.PartitionSourceBounds<>(Long.MIN_VALUE,
Long.MIN_VALUE + 7));
+ }
+
+ @Test
+ void truncateNumberAtMinWithPowerOfTwoWidth() {
+ assertThat(sourceBounds(Types.IntegerType.get(), Transforms.truncate(8),
Integer.MIN_VALUE))
+ .isEqualTo(new StatsUtil.PartitionSourceBounds<>(Integer.MIN_VALUE,
Integer.MIN_VALUE + 7));
+ assertThat(sourceBounds(Types.LongType.get(), Transforms.truncate(8),
Long.MIN_VALUE))
+ .isEqualTo(new StatsUtil.PartitionSourceBounds<>(Long.MIN_VALUE,
Long.MIN_VALUE + 7));
+ }
+
+ @Test
+ void truncateStringBounds() {
+ assertThat(sourceBounds(Types.StringType.get(), Transforms.truncate(3),
"abc"))
+ .isEqualTo(new StatsUtil.PartitionSourceBounds<>("abc", "abd"));
+ }
+
+ @Test
+ void truncateShortString() {
+ assertThat(sourceBounds(Types.StringType.get(), Transforms.truncate(3),
"ab"))
+ .isEqualTo(new StatsUtil.PartitionSourceBounds<>("ab", "ab"));
+ }
+
+ @Test
+ void truncateShortStringWithSurrogatePair() {
+ String value = "ab" + new String(Character.toChars(0x1F4B0));
+
+ assertThat(sourceBounds(Types.StringType.get(), Transforms.truncate(4),
value))
+ .isEqualTo(new StatsUtil.PartitionSourceBounds<>(value, value));
+ }
+
+ @Test
+ void truncateStringAtMaxCodePoint() {
+ String maxCodePoint = new
String(Character.toChars(Character.MAX_CODE_POINT));
+
+ assertThat(sourceBounds(Types.StringType.get(), Transforms.truncate(1),
maxCodePoint))
+ .isEqualTo(new StatsUtil.PartitionSourceBounds<>(maxCodePoint, null));
Review Comment:
Can you also add a case where you have the string `"a{MAX_CODE_POINT}"` with
`truncate(2)`?
--
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]