Skip to content

Commit e1c9c7d

Browse files
committed
Minor cleanup on TestTupleDomainParquetPredicate
Adds a new test on evaluating ShortDecimal with Int64 and pad zeros for binary statistics.
1 parent 17b3ff4 commit e1c9c7d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

lib/trino-parquet/src/test/java/io/trino/parquet/TestTupleDomainParquetPredicate.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import static io.airlift.slice.Slices.utf8Slice;
6666
import static io.trino.parquet.ParquetEncoding.PLAIN_DICTIONARY;
6767
import static io.trino.parquet.ParquetTimestampUtils.JULIAN_EPOCH_OFFSET_DAYS;
68+
import static io.trino.parquet.ParquetTypeUtils.paddingBigInteger;
6869
import static io.trino.parquet.predicate.TupleDomainParquetPredicate.getDomain;
6970
import static io.trino.spi.predicate.Domain.all;
7071
import static io.trino.spi.predicate.Domain.create;
@@ -237,6 +238,25 @@ public void testShortDecimal()
237238
.withMessage("Malformed Parquet file. Corrupted statistics for column \"[] required int32 ShortDecimalColumn\": [min: 100, max: 10, num_nulls: 0] [testFile]");
238239
}
239240

241+
@Test
242+
public void testShortDecimalWithInt64()
243+
throws Exception
244+
{
245+
ColumnDescriptor columnDescriptor = createColumnDescriptor(INT64, "ShortDecimalColumn");
246+
Type type = createDecimalType(5, 2);
247+
assertThat(getDomain(columnDescriptor, type, 0, null, ID, UTC)).isEqualTo(all(type));
248+
249+
assertThat(getDomain(columnDescriptor, type, 10, longColumnStats(10012L, 10012L), ID, UTC)).isEqualTo(singleValue(type, 10012L));
250+
// Test that statistics overflowing the size of the type are not used
251+
assertThat(getDomain(columnDescriptor, type, 10, longColumnStats(100012L, 100012L), ID, UTC)).isEqualTo(notNull(type));
252+
253+
assertThat(getDomain(columnDescriptor, type, 10, longColumnStats(0L, 100L), ID, UTC)).isEqualTo(create(ValueSet.ofRanges(range(type, 0L, true, 100L, true)), false));
254+
// fail on corrupted statistics
255+
assertThatExceptionOfType(ParquetCorruptionException.class)
256+
.isThrownBy(() -> getDomain(columnDescriptor, type, 10, longColumnStats(100L, 10L), ID, UTC))
257+
.withMessage("Malformed Parquet file. Corrupted statistics for column \"[] required int64 ShortDecimalColumn\": [min: 100, max: 10, num_nulls: 0] [testFile]");
258+
}
259+
240260
@Test
241261
public void testShortDecimalWithNoScale()
242262
throws Exception
@@ -277,7 +297,7 @@ public void testLongDecimal()
277297
// fail on corrupted statistics
278298
assertThatExceptionOfType(ParquetCorruptionException.class)
279299
.isThrownBy(() -> getDomain(columnDescriptor, type, 10, binaryColumnStats(100L, 10L), ID, UTC))
280-
.withMessage("Malformed Parquet file. Corrupted statistics for column \"[] required fixed_len_byte_array(0) LongDecimalColumn\": [min: 0x64, max: 0x0A, num_nulls: 0] [testFile]");
300+
.withMessage("Malformed Parquet file. Corrupted statistics for column \"[] required fixed_len_byte_array(0) LongDecimalColumn\": [min: 0x00000000000000000000000000000064, max: 0x0000000000000000000000000000000A, num_nulls: 0] [testFile]");
281301
}
282302

283303
@Test
@@ -296,7 +316,7 @@ public void testLongDecimalWithNoScale()
296316
// fail on corrupted statistics
297317
assertThatExceptionOfType(ParquetCorruptionException.class)
298318
.isThrownBy(() -> getDomain(columnDescriptor, type, 10, binaryColumnStats(100L, 10L), ID, UTC))
299-
.withMessage("Malformed Parquet file. Corrupted statistics for column \"[] required fixed_len_byte_array(0) LongDecimalColumnWithNoScale\": [min: 0x64, max: 0x0A, num_nulls: 0] [testFile]");
319+
.withMessage("Malformed Parquet file. Corrupted statistics for column \"[] required fixed_len_byte_array(0) LongDecimalColumnWithNoScale\": [min: 0x00000000000000000000000000000064, max: 0x0000000000000000000000000000000A, num_nulls: 0] [testFile]");
300320
}
301321

302322
@Test
@@ -786,8 +806,8 @@ private static BinaryStatistics binaryColumnStats(long minimum, long maximum)
786806
private static BinaryStatistics binaryColumnStats(BigInteger minimum, BigInteger maximum)
787807
{
788808
return (BinaryStatistics) Statistics.getBuilderForReading(Types.optional(BINARY).named("BinaryColumn"))
789-
.withMin(minimum.toByteArray())
790-
.withMax(maximum.toByteArray())
809+
.withMin(paddingBigInteger(minimum, 16))
810+
.withMax(paddingBigInteger(maximum, 16))
791811
.withNumNulls(0)
792812
.build();
793813
}

0 commit comments

Comments
 (0)