Skip to content

Commit fc86d0c

Browse files
committed
Fix more review comments
1 parent 5a48e11 commit fc86d0c

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

api/src/main/java/org/apache/iceberg/expressions/ExpressionUtil.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.iceberg.Schema;
3535
import org.apache.iceberg.Table;
3636
import org.apache.iceberg.expressions.Literals.BoundingBoxLiteral;
37+
import org.apache.iceberg.geospatial.BoundingBox;
3738
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
3839
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
3940
import org.apache.iceberg.transforms.Transforms;
@@ -549,7 +550,8 @@ private static String sanitize(Literal<?> literal, long now, int today) {
549550
} else if (literal instanceof Literals.VariantLiteral) {
550551
return sanitizeVariant(((Literals.VariantLiteral) literal).value(), now, today);
551552
} else if (literal instanceof BoundingBoxLiteral) {
552-
return "(boundingbox)";
553+
BoundingBox bbox = BoundingBox.fromByteBuffer(((BoundingBoxLiteral) literal).value());
554+
return sanitizeBoundingBox(bbox);
553555
} else {
554556
// for uuid, decimal, fixed and binary, match the string result
555557
return sanitizeSimpleString(literal.value().toString());
@@ -628,6 +630,20 @@ private static String sanitizeSimpleString(CharSequence value) {
628630
return String.format(Locale.ROOT, "(hash-%08x)", HASH_FUNC.apply(value));
629631
}
630632

633+
private static String sanitizeBoundingBox(BoundingBox bbox) {
634+
boolean hasZ = bbox.min().hasZ() && bbox.max().hasZ();
635+
boolean hasM = bbox.min().hasM() && bbox.max().hasM();
636+
if (hasZ && hasM) {
637+
return "(boundingbox-xyzm)";
638+
} else if (hasZ) {
639+
return "(boundingbox-xyz)";
640+
} else if (hasM) {
641+
return "(boundingbox-xym)";
642+
} else {
643+
return "(boundingbox-xy)";
644+
}
645+
}
646+
631647
private static String sanitizeVariant(Variant value, long now, int today) {
632648
return sanitizeVariant(value.value(), now, today);
633649
}

api/src/main/java/org/apache/iceberg/expressions/UnboundPredicate.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.iceberg.expressions;
2020

2121
import java.util.List;
22-
import java.util.Locale;
2322
import java.util.Set;
2423
import org.apache.iceberg.exceptions.ValidationException;
2524
import org.apache.iceberg.relocated.com.google.common.base.Joiner;
@@ -286,11 +285,9 @@ public String toString() {
286285
case NOT_STARTS_WITH:
287286
return term() + " notStartsWith \"" + literal() + "\"";
288287
case ST_INTERSECTS:
288+
return "st_intersects(" + term() + ", " + literal() + ")";
289289
case ST_DISJOINT:
290-
{
291-
String functionName = op().name().toLowerCase(Locale.ROOT);
292-
return functionName + "(" + term() + ", " + literal() + ")";
293-
}
290+
return "st_disjoint(" + term() + ", " + literal() + ")";
294291
case IN:
295292
return term() + " in (" + COMMA.join(literals()) + ")";
296293
case NOT_IN:

api/src/test/java/org/apache/iceberg/expressions/TestExpressionUtil.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,25 +1328,59 @@ private static Stream<Arguments> geospatialPredicateParameters() {
13281328
GeospatialBound max = GeospatialBound.createXY(3.0, 4.0);
13291329
BoundingBox bbox = new BoundingBox(min, max);
13301330

1331+
GeospatialBound minXYZ = GeospatialBound.createXYZ(1.0, 2.0, 3.0);
1332+
GeospatialBound maxXYZ = GeospatialBound.createXYZ(3.0, 4.0, 5.0);
1333+
BoundingBox bboxXYZ = new BoundingBox(minXYZ, maxXYZ);
1334+
1335+
GeospatialBound minXYM = GeospatialBound.createXYM(1.0, 2.0, 3.0);
1336+
GeospatialBound maxXYM = GeospatialBound.createXYM(3.0, 4.0, 5.0);
1337+
BoundingBox bboxXYM = new BoundingBox(minXYM, maxXYM);
1338+
1339+
GeospatialBound minXYZM = GeospatialBound.createXYZM(1.0, 2.0, 3.0, 4.0);
1340+
GeospatialBound maxXYZM = GeospatialBound.createXYZM(3.0, 4.0, 5.0, 6.0);
1341+
BoundingBox bboxXYZM = new BoundingBox(minXYZM, maxXYZM);
1342+
13311343
return Stream.of(
13321344
Arguments.of(
1333-
Expressions.stIntersects("geometry", bbox), "st_intersects(geometry, (boundingbox))"),
1345+
Expressions.stIntersects("geometry", bbox),
1346+
"st_intersects(geometry, (boundingbox-xy))",
1347+
"(boundingbox-xy)"),
1348+
Arguments.of(
1349+
Expressions.stIntersects("geography", bbox),
1350+
"st_intersects(geography, (boundingbox-xy))",
1351+
"(boundingbox-xy)"),
1352+
Arguments.of(
1353+
Expressions.stDisjoint("geometry", bbox),
1354+
"st_disjoint(geometry, (boundingbox-xy))",
1355+
"(boundingbox-xy)"),
1356+
Arguments.of(
1357+
Expressions.stDisjoint("geography", bbox),
1358+
"st_disjoint(geography, (boundingbox-xy))",
1359+
"(boundingbox-xy)"),
13341360
Arguments.of(
1335-
Expressions.stIntersects("geography", bbox), "st_intersects(geography, (boundingbox))"),
1361+
Expressions.stIntersects("geometry", bboxXYZ),
1362+
"st_intersects(geometry, (boundingbox-xyz))",
1363+
"(boundingbox-xyz)"),
13361364
Arguments.of(
1337-
Expressions.stDisjoint("geometry", bbox), "st_disjoint(geometry, (boundingbox))"),
1365+
Expressions.stIntersects("geometry", bboxXYM),
1366+
"st_intersects(geometry, (boundingbox-xym))",
1367+
"(boundingbox-xym)"),
13381368
Arguments.of(
1339-
Expressions.stDisjoint("geography", bbox), "st_disjoint(geography, (boundingbox))"));
1369+
Expressions.stIntersects("geometry", bboxXYZM),
1370+
"st_intersects(geometry, (boundingbox-xyzm))",
1371+
"(boundingbox-xyzm)"));
13401372
}
13411373

13421374
@ParameterizedTest
13431375
@MethodSource("geospatialPredicateParameters")
13441376
public void testSanitizeGeospatialPredicates(
1345-
UnboundPredicate<ByteBuffer> geoPredicate, String expectedSanitizedString) {
1377+
UnboundPredicate<ByteBuffer> geoPredicate,
1378+
String expectedSanitizedString,
1379+
String expectedLiteral) {
13461380
Expression.Operation operation = geoPredicate.op();
13471381
String columnName = geoPredicate.term().ref().name();
13481382

1349-
Expression predicateSanitized = Expressions.predicate(operation, columnName, "(boundingbox)");
1383+
Expression predicateSanitized = Expressions.predicate(operation, columnName, expectedLiteral);
13501384
assertEquals(predicateSanitized, ExpressionUtil.sanitize(geoPredicate));
13511385
assertEquals(predicateSanitized, ExpressionUtil.sanitize(STRUCT, geoPredicate, true));
13521386

0 commit comments

Comments
 (0)