Kontinuation commented on code in PR #14101:
URL: https://github.com/apache/iceberg/pull/14101#discussion_r2757902703
##########
api/src/test/java/org/apache/iceberg/expressions/TestExpressionUtil.java:
##########
@@ -1315,6 +1324,92 @@ private static VariantArray createArrayWithNestedTypes()
{
return (VariantArray) VariantValue.from(metadata, variantBB);
}
+ private static Stream<Arguments> geospatialPredicateParameters() {
+ GeospatialBound min = GeospatialBound.createXY(1.0, 2.0);
+ GeospatialBound max = GeospatialBound.createXY(3.0, 4.0);
+ BoundingBox bbox = new BoundingBox(min, max);
+
+ GeospatialBound minXYZ = GeospatialBound.createXYZ(1.0, 2.0, 3.0);
+ GeospatialBound maxXYZ = GeospatialBound.createXYZ(3.0, 4.0, 5.0);
+ BoundingBox bboxXYZ = new BoundingBox(minXYZ, maxXYZ);
+
+ GeospatialBound minXYM = GeospatialBound.createXYM(1.0, 2.0, 3.0);
+ GeospatialBound maxXYM = GeospatialBound.createXYM(3.0, 4.0, 5.0);
+ BoundingBox bboxXYM = new BoundingBox(minXYM, maxXYM);
+
+ GeospatialBound minXYZM = GeospatialBound.createXYZM(1.0, 2.0, 3.0, 4.0);
+ GeospatialBound maxXYZM = GeospatialBound.createXYZM(3.0, 4.0, 5.0, 6.0);
+ BoundingBox bboxXYZM = new BoundingBox(minXYZM, maxXYZM);
+
+ return Stream.of(
+ Arguments.of(
+ Expressions.stIntersects("geometry", bbox),
+ "st_intersects(geometry, (boundingbox-xy))",
+ "(boundingbox-xy)"),
+ Arguments.of(
+ Expressions.stIntersects("geography", bbox),
+ "st_intersects(geography, (boundingbox-xy))",
+ "(boundingbox-xy)"),
+ Arguments.of(
+ Expressions.stDisjoint("geometry", bbox),
+ "st_disjoint(geometry, (boundingbox-xy))",
+ "(boundingbox-xy)"),
+ Arguments.of(
+ Expressions.stDisjoint("geography", bbox),
+ "st_disjoint(geography, (boundingbox-xy))",
+ "(boundingbox-xy)"),
+ Arguments.of(
+ Expressions.stIntersects("geometry", bboxXYZ),
+ "st_intersects(geometry, (boundingbox-xyz))",
+ "(boundingbox-xyz)"),
+ Arguments.of(
+ Expressions.stIntersects("geometry", bboxXYM),
+ "st_intersects(geometry, (boundingbox-xym))",
+ "(boundingbox-xym)"),
+ Arguments.of(
+ Expressions.stIntersects("geometry", bboxXYZM),
+ "st_intersects(geometry, (boundingbox-xyzm))",
+ "(boundingbox-xyzm)"));
+ }
+
+ @ParameterizedTest
+ @MethodSource("geospatialPredicateParameters")
+ public void testSanitizeGeospatialPredicates(
+ UnboundPredicate<ByteBuffer> geoPredicate,
+ String expectedSanitizedString,
+ String expectedLiteral) {
+ Expression.Operation operation = geoPredicate.op();
+ String columnName = geoPredicate.term().ref().name();
+
+ Expression predicateSanitized = Expressions.predicate(operation,
columnName, expectedLiteral);
+ assertEquals(predicateSanitized, ExpressionUtil.sanitize(geoPredicate));
+ assertEquals(predicateSanitized, ExpressionUtil.sanitize(STRUCT,
geoPredicate, true));
+
+ assertThat(ExpressionUtil.toSanitizedString(geoPredicate))
+ .as("Sanitized string should be identical for geospatial predicates")
+ .isEqualTo(expectedSanitizedString);
+
+ assertThat(ExpressionUtil.toSanitizedString(STRUCT, geoPredicate, true))
+ .as("Sanitized string should be identical for geospatial predicates")
+ .isEqualTo(expectedSanitizedString);
+ }
+
+ @Test
+ public void testBoundingBoxLiteralNormalizesBuffer() {
+ GeospatialBound min = GeospatialBound.createXY(1.0, 2.0);
+ GeospatialBound max = GeospatialBound.createXY(3.0, 4.0);
+ BoundingBox box = new BoundingBox(min, max);
+ ByteBuffer serialized = box.toByteBuffer();
+
+ ByteBuffer padded = ByteBuffer.allocate(serialized.remaining() +
1).order(ByteOrder.BIG_ENDIAN);
+ padded.put((byte) 0x0);
Review Comment:
This is for testing the buffer normalization. There's a comment suggesting
normalizing the buffer to handle the non-little-endian or non-zero offset
buffers properly:
https://github.com/apache/iceberg/pull/14101#discussion_r2706366191
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]