Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private static VariantValue truncateUpperBound(VariantValue value) {
return truncatedString != null ? Variants.of(PhysicalType.STRING, truncatedString) : null;
case BINARY:
ByteBuffer truncatedBuffer =
BinaryUtil.truncateBinaryMin((ByteBuffer) value.asPrimitive().get(), 16);
BinaryUtil.truncateBinaryMax((ByteBuffer) value.asPrimitive().get(), 16);
return truncatedBuffer != null ? Variants.of(PhysicalType.BINARY, truncatedBuffer) : null;
default:
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,56 @@ public void testShreddedPrimitiveTypeMismatch(VariantValue value) throws IOExcep
.isEqualTo(Map.of(1, Conversions.toByteBuffer(Type.TypeID.LONG, 1L)));
}

@Test
public void testShreddedBinaryBoundsTruncation() throws IOException {
// binary longer than the 16-byte truncation length so the bounds are truncated
byte[] bytes = new byte[20];
for (int i = 0; i < bytes.length; i += 1) {
bytes[i] = (byte) (i + 1);
}
VariantValue value = Variants.of(ByteBuffer.wrap(bytes));

Metrics metrics =
writeParquet(
(id, name) -> ParquetVariantUtil.toParquetSchema(value),
Variant.of(EMPTY, value),
Variant.of(EMPTY, Variants.ofNull()),
null);

assertThat(metrics.lowerBounds().get(2))
.extracting(b -> Variant.from(b).value().asObject().get(ROOT_FIELD))
.isEqualTo(Variants.of(BinaryUtil.truncateBinaryMin(ByteBuffer.wrap(bytes), 16)));

assertThat(metrics.upperBounds().get(2))
.extracting(b -> Variant.from(b).value().asObject().get(ROOT_FIELD))
.isEqualTo(Variants.of(BinaryUtil.truncateBinaryMax(ByteBuffer.wrap(bytes), 16)));
}

@Test
public void testShreddedBinaryUpperBoundOverflow() throws IOException {
// an all-0xFF binary cannot be truncated up so the upper bound is omitted
byte[] bytes = new byte[20];
for (int i = 0; i < bytes.length; i += 1) {
bytes[i] = (byte) 0xFF;
}
VariantValue value = Variants.of(ByteBuffer.wrap(bytes));

Metrics metrics =
writeParquet(
(id, name) -> ParquetVariantUtil.toParquetSchema(value),
Variant.of(EMPTY, value),
Variant.of(EMPTY, Variants.ofNull()),
null);

assertThat(metrics.lowerBounds().get(2))
.extracting(b -> Variant.from(b).value().asObject().get(ROOT_FIELD))
.isEqualTo(Variants.of(BinaryUtil.truncateBinaryMin(ByteBuffer.wrap(bytes), 16)));

assertThat(metrics.upperBounds().get(2))
.extracting(b -> Variant.from(b).value().asObject().get(ROOT_FIELD))
.isNull();
}

@Test
public void testVariantFloatNaN() throws IOException {
// NaN values are not counted because there is no ID for FieldMetrics
Expand Down
Loading