65
65
import static io .airlift .slice .Slices .utf8Slice ;
66
66
import static io .trino .parquet .ParquetEncoding .PLAIN_DICTIONARY ;
67
67
import static io .trino .parquet .ParquetTimestampUtils .JULIAN_EPOCH_OFFSET_DAYS ;
68
+ import static io .trino .parquet .ParquetTypeUtils .paddingBigInteger ;
68
69
import static io .trino .parquet .predicate .TupleDomainParquetPredicate .getDomain ;
69
70
import static io .trino .spi .predicate .Domain .all ;
70
71
import static io .trino .spi .predicate .Domain .create ;
@@ -237,6 +238,25 @@ public void testShortDecimal()
237
238
.withMessage ("Malformed Parquet file. Corrupted statistics for column \" [] required int32 ShortDecimalColumn\" : [min: 100, max: 10, num_nulls: 0] [testFile]" );
238
239
}
239
240
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
+
240
260
@ Test
241
261
public void testShortDecimalWithNoScale ()
242
262
throws Exception
@@ -277,7 +297,7 @@ public void testLongDecimal()
277
297
// fail on corrupted statistics
278
298
assertThatExceptionOfType (ParquetCorruptionException .class )
279
299
.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]" );
281
301
}
282
302
283
303
@ Test
@@ -296,7 +316,7 @@ public void testLongDecimalWithNoScale()
296
316
// fail on corrupted statistics
297
317
assertThatExceptionOfType (ParquetCorruptionException .class )
298
318
.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]" );
300
320
}
301
321
302
322
@ Test
@@ -786,8 +806,8 @@ private static BinaryStatistics binaryColumnStats(long minimum, long maximum)
786
806
private static BinaryStatistics binaryColumnStats (BigInteger minimum , BigInteger maximum )
787
807
{
788
808
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 ))
791
811
.withNumNulls (0 )
792
812
.build ();
793
813
}
0 commit comments