File tree Expand file tree Collapse file tree
main/java/org/apache/iceberg/expressions
test/java/org/apache/iceberg/expressions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222import java .math .BigDecimal ;
2323import java .math .RoundingMode ;
2424import java .nio .ByteBuffer ;
25+ import java .nio .ByteOrder ;
2526import java .time .Instant ;
2627import java .time .LocalDate ;
2728import java .time .LocalTime ;
@@ -734,7 +735,8 @@ static class BoundingBoxLiteral implements Literal<ByteBuffer> {
734735 }
735736
736737 BoundingBoxLiteral (ByteBuffer value ) {
737- this .value = value ;
738+ Preconditions .checkNotNull (value , "Bounding box buffer cannot be null" );
739+ this .value = value .slice ().order (ByteOrder .LITTLE_ENDIAN );
738740 }
739741
740742 @ Override
Original file line number Diff line number Diff line change 2121import static org .assertj .core .api .Assertions .assertThat ;
2222
2323import java .nio .ByteBuffer ;
24+ import java .nio .ByteOrder ;
2425import java .time .LocalDate ;
2526import java .time .OffsetDateTime ;
2627import java .time .ZoneOffset ;
@@ -1393,6 +1394,22 @@ public void testSanitizeGeospatialPredicates(
13931394 .isEqualTo (expectedSanitizedString );
13941395 }
13951396
1397+ @ Test
1398+ public void testBoundingBoxLiteralNormalizesBuffer () {
1399+ GeospatialBound min = GeospatialBound .createXY (1.0 , 2.0 );
1400+ GeospatialBound max = GeospatialBound .createXY (3.0 , 4.0 );
1401+ BoundingBox box = new BoundingBox (min , max );
1402+ ByteBuffer serialized = box .toByteBuffer ();
1403+
1404+ ByteBuffer padded = ByteBuffer .allocate (serialized .remaining () + 1 ).order (ByteOrder .BIG_ENDIAN );
1405+ padded .put ((byte ) 0x0 );
1406+ padded .put (serialized .duplicate ());
1407+ padded .position (1 );
1408+ Literal <ByteBuffer > literal = new Literals .BoundingBoxLiteral (padded );
1409+
1410+ assertThat (literal .toString ()).isEqualTo (box .toString ());
1411+ }
1412+
13961413 private void assertEquals (Expression expected , Expression actual ) {
13971414 assertThat (expected ).isInstanceOf (UnboundPredicate .class );
13981415 assertEquals ((UnboundPredicate <?>) expected , (UnboundPredicate <?>) actual );
You can’t perform that action at this time.
0 commit comments