File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
main/java/org/apache/parquet/column/statistics
test/java/org/apache/parquet/column/statistics Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -105,16 +105,16 @@ String stringify(Binary value) {
105105
106106 @ Override
107107 public boolean isSmallerThan (long size ) {
108- return !hasNonNullValue () || ((min .length () + max .length ()) < size );
108+ return !hasNonNullValue () || ((( long ) min .length () + max .length ()) < size );
109109 }
110110
111111 public boolean isSmallerThanWithTruncation (long size , int truncationLength ) {
112112 if (!hasNonNullValue ()) {
113113 return true ;
114114 }
115115
116- int minTruncateLength = Math .min (min .length (), truncationLength );
117- int maxTruncateLength = Math .min (max .length (), truncationLength );
116+ long minTruncateLength = Math .min (min .length (), truncationLength );
117+ long maxTruncateLength = Math .min (max .length (), truncationLength );
118118
119119 return minTruncateLength + maxTruncateLength < size ;
120120 }
Original file line number Diff line number Diff line change @@ -927,4 +927,15 @@ public void testNoopStatistics() {
927927 assertThrows (UnsupportedOperationException .class , stats ::minAsString );
928928 assertThrows (UnsupportedOperationException .class , () -> stats .isSmallerThan (0 ));
929929 }
930+
931+ @ Test
932+ public void testBinaryIsSmallerThanNoOverflowForLargeValues () {
933+ BinaryStatistics stats = new BinaryStatistics ();
934+ // Create a Binary whose length() reports 2^30 without allocating 1 GB
935+ Binary fakeLarge = Binary .fromConstantByteArray (new byte [0 ], 0 , 1 << 30 );
936+ stats .updateStats (fakeLarge );
937+
938+ // min.length() + max.length() = 2^31, must not overflow int to negative
939+ assertFalse (stats .isSmallerThan (4096 ));
940+ }
930941}
You can’t perform that action at this time.
0 commit comments