Skip to content

Commit b6f44c9

Browse files
committed
Revert expression parser changes and defer them to apache#14856
1 parent 134c6c3 commit b6f44c9

2 files changed

Lines changed: 4 additions & 256 deletions

File tree

core/src/main/java/org/apache/iceberg/expressions/ExpressionParser.java

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
import java.util.function.Supplier;
3232
import org.apache.iceberg.Schema;
3333
import org.apache.iceberg.SingleValueParser;
34-
import org.apache.iceberg.expressions.Expression.Operation;
35-
import org.apache.iceberg.geospatial.BoundingBox;
36-
import org.apache.iceberg.geospatial.GeospatialBound;
3734
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
3835
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
3936
import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
@@ -162,13 +159,8 @@ public <T> Void predicate(BoundPredicate<T> pred) {
162159

163160
if (pred.isLiteralPredicate()) {
164161
gen.writeFieldName(VALUE);
165-
if (pred.op() == Operation.ST_INTERSECTS || pred.op() == Operation.ST_DISJOINT) {
166-
ByteBuffer value = (ByteBuffer) pred.asLiteralPredicate().literal().value();
167-
geospatialBoundingBox(BoundingBox.fromByteBuffer(value));
168-
} else {
169-
SingleValueParser.toJson(
170-
pred.term().type(), pred.asLiteralPredicate().literal().value(), gen);
171-
}
162+
SingleValueParser.toJson(
163+
pred.term().type(), pred.asLiteralPredicate().literal().value(), gen);
172164
} else if (pred.isSetPredicate()) {
173165
gen.writeArrayFieldStart(VALUES);
174166
for (T value : pred.asSetPredicate().literalSet()) {
@@ -200,11 +192,6 @@ public <T> Void predicate(UnboundPredicate<T> pred) {
200192
}
201193
gen.writeEndArray();
202194

203-
} else if (pred.op() == Expression.Operation.ST_INTERSECTS
204-
|| pred.op() == Expression.Operation.ST_DISJOINT) {
205-
gen.writeFieldName(VALUE);
206-
ByteBuffer value = (ByteBuffer) pred.literal().value();
207-
geospatialBoundingBox(BoundingBox.fromByteBuffer(value));
208195
} else {
209196
gen.writeFieldName(VALUE);
210197
unboundLiteral(pred.literal().value());
@@ -242,44 +229,6 @@ private void unboundLiteral(Object object) throws IOException {
242229
}
243230
}
244231

245-
private void geospatialBoundingBox(BoundingBox value) throws IOException {
246-
gen.writeStartObject();
247-
248-
// Write x coordinate
249-
gen.writeFieldName("x");
250-
gen.writeStartObject();
251-
gen.writeNumberField("min", value.min().x());
252-
gen.writeNumberField("max", value.max().x());
253-
gen.writeEndObject();
254-
255-
// Write y coordinate
256-
gen.writeFieldName("y");
257-
gen.writeStartObject();
258-
gen.writeNumberField("min", value.min().y());
259-
gen.writeNumberField("max", value.max().y());
260-
gen.writeEndObject();
261-
262-
// Write z coordinate if present
263-
if (value.min().hasZ() || value.max().hasZ()) {
264-
gen.writeFieldName("z");
265-
gen.writeStartObject();
266-
gen.writeNumberField("min", value.min().z());
267-
gen.writeNumberField("max", value.max().z());
268-
gen.writeEndObject();
269-
}
270-
271-
// Write m coordinate if present
272-
if (value.min().hasM() || value.max().hasM()) {
273-
gen.writeFieldName("m");
274-
gen.writeStartObject();
275-
gen.writeNumberField("min", value.min().m());
276-
gen.writeNumberField("max", value.max().m());
277-
gen.writeEndObject();
278-
}
279-
280-
gen.writeEndObject();
281-
}
282-
283232
private String operationType(Expression.Operation op) {
284233
return op.toString().replaceAll("_", "-").toLowerCase(Locale.ENGLISH);
285234
}
@@ -357,9 +306,6 @@ static Expression fromJson(JsonNode json, Schema schema) {
357306
return Expressions.or(
358307
fromJson(JsonUtil.get(LEFT, json), schema),
359308
fromJson(JsonUtil.get(RIGHT, json), schema));
360-
case ST_INTERSECTS:
361-
case ST_DISJOINT:
362-
return geospatialPredicateFromJson(op, json);
363309
}
364310

365311
return predicateFromJson(op, json, schema);
@@ -428,22 +374,6 @@ private static <T> UnboundPredicate<T> predicateFromJson(
428374
}
429375
}
430376

431-
private static Expression geospatialPredicateFromJson(Expression.Operation op, JsonNode node) {
432-
UnboundTerm<ByteBuffer> term = term(JsonUtil.get(TERM, node));
433-
Preconditions.checkArgument(node.has(VALUE), "Cannot parse %s predicate: missing value", op);
434-
Preconditions.checkArgument(
435-
!node.has(VALUES), "Cannot parse %s predicate: has invalid values field", op);
436-
BoundingBox boundingBox = geospatialBoundingBox(JsonUtil.get(VALUE, node));
437-
switch (op) {
438-
case ST_INTERSECTS:
439-
return Expressions.stIntersects(term, boundingBox);
440-
case ST_DISJOINT:
441-
return Expressions.stDisjoint(term, boundingBox);
442-
default:
443-
throw new UnsupportedOperationException("Unsupported geospatial operation: " + op);
444-
}
445-
}
446-
447377
private static <T> T literal(JsonNode valueNode, Function<JsonNode, T> toValue) {
448378
if (valueNode.isObject() && valueNode.has(TYPE)) {
449379
String type = JsonUtil.getString(TYPE, valueNode);
@@ -456,51 +386,6 @@ private static <T> T literal(JsonNode valueNode, Function<JsonNode, T> toValue)
456386
return toValue.apply(valueNode);
457387
}
458388

459-
private static BoundingBox geospatialBoundingBox(JsonNode valueNode) {
460-
// X and Y coordinates are required
461-
double xMin = valueNode.get("x").get("min").asDouble();
462-
double xMax = valueNode.get("x").get("max").asDouble();
463-
double yMin = valueNode.get("y").get("min").asDouble();
464-
double yMax = valueNode.get("y").get("max").asDouble();
465-
466-
// Create GeospatialBound objects for min and max
467-
GeospatialBound minBound;
468-
GeospatialBound maxBound;
469-
470-
// Check if Z coordinate exists
471-
boolean hasZ = valueNode.has("z");
472-
// Check if M coordinate exists
473-
boolean hasM = valueNode.has("m");
474-
475-
if (hasZ && hasM) {
476-
// Both Z and M present
477-
double zMin = valueNode.get("z").get("min").asDouble();
478-
double zMax = valueNode.get("z").get("max").asDouble();
479-
double mMin = valueNode.get("m").get("min").asDouble();
480-
double mMax = valueNode.get("m").get("max").asDouble();
481-
minBound = GeospatialBound.createXYZM(xMin, yMin, zMin, mMin);
482-
maxBound = GeospatialBound.createXYZM(xMax, yMax, zMax, mMax);
483-
} else if (hasZ) {
484-
// Only Z present, no M
485-
double zMin = valueNode.get("z").get("min").asDouble();
486-
double zMax = valueNode.get("z").get("max").asDouble();
487-
minBound = GeospatialBound.createXYZ(xMin, yMin, zMin);
488-
maxBound = GeospatialBound.createXYZ(xMax, yMax, zMax);
489-
} else if (hasM) {
490-
// Only M present, no Z
491-
double mMin = valueNode.get("m").get("min").asDouble();
492-
double mMax = valueNode.get("m").get("max").asDouble();
493-
minBound = GeospatialBound.createXYM(xMin, yMin, mMin);
494-
maxBound = GeospatialBound.createXYM(xMax, yMax, mMax);
495-
} else {
496-
// Only X and Y present
497-
minBound = GeospatialBound.createXY(xMin, yMin);
498-
maxBound = GeospatialBound.createXY(xMax, yMax);
499-
}
500-
501-
return new BoundingBox(minBound, maxBound);
502-
}
503-
504389
private static Object asObject(JsonNode node) {
505390
if (node.isIntegralNumber() && node.canConvertToLong()) {
506391
return node.asLong();

core/src/test/java/org/apache/iceberg/expressions/TestExpressionParser.java

Lines changed: 2 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import java.nio.ByteBuffer;
2929
import java.util.UUID;
3030
import org.apache.iceberg.Schema;
31-
import org.apache.iceberg.geospatial.BoundingBox;
32-
import org.apache.iceberg.geospatial.GeospatialBound;
3331
import org.apache.iceberg.types.Types;
3432
import org.junit.jupiter.api.Test;
3533

@@ -53,9 +51,7 @@ public class TestExpressionParser {
5351
required(114, "dec_9_0", Types.DecimalType.of(9, 0)),
5452
required(115, "dec_11_2", Types.DecimalType.of(11, 2)),
5553
required(116, "dec_38_10", Types.DecimalType.of(38, 10)), // maximum precision
56-
required(117, "time", Types.TimeType.get()),
57-
required(118, "geometry", Types.GeometryType.crs84()),
58-
required(119, "geography", Types.GeographyType.crs84()));
54+
required(117, "time", Types.TimeType.get()));
5955
private static final Schema SCHEMA = new Schema(SUPPORTED_PRIMITIVES.fields());
6056

6157
@Test
@@ -98,22 +94,7 @@ public void testSimpleExpressions() {
9894
Expressions.or(
9995
Expressions.greaterThan(Expressions.day("ts"), "2022-08-14"),
10096
Expressions.equal("date", "2022-08-14")),
101-
Expressions.not(Expressions.in("l", 1, 2, 3, 4)),
102-
Expressions.stIntersects(
103-
"geometry",
104-
new BoundingBox(GeospatialBound.createXY(1, 2), GeospatialBound.createXY(3, 4))),
105-
Expressions.stDisjoint(
106-
"geometry",
107-
new BoundingBox(
108-
GeospatialBound.createXYM(1, 2, 3), GeospatialBound.createXYM(3, 4, 5))),
109-
Expressions.stIntersects(
110-
"geography",
111-
new BoundingBox(
112-
GeospatialBound.createXYZ(1, 2, 3), GeospatialBound.createXYZ(3, 4, 5))),
113-
Expressions.stDisjoint(
114-
"geography",
115-
new BoundingBox(
116-
GeospatialBound.createXYZM(1, 2, 3, 4), GeospatialBound.createXYZM(3, 4, 5, 6)))
97+
Expressions.not(Expressions.in("l", 1, 2, 3, 4))
11798
};
11899

119100
for (Expression expr : expressions) {
@@ -563,122 +544,4 @@ public void testNegativeScaleDecimalLiteral() {
563544
assertThat(ExpressionParser.toJson(ExpressionParser.fromJson(expected), true))
564545
.isEqualTo(expected);
565546
}
566-
567-
@Test
568-
public void testSpatialPredicate() {
569-
String expected =
570-
"{\n"
571-
+ " \"type\" : \"st-intersects\",\n"
572-
+ " \"term\" : \"column-name\",\n"
573-
+ " \"value\" : {\n"
574-
+ " \"x\" : {\n"
575-
+ " \"min\" : 1.0,\n"
576-
+ " \"max\" : 3.0\n"
577-
+ " },\n"
578-
+ " \"y\" : {\n"
579-
+ " \"min\" : 2.0,\n"
580-
+ " \"max\" : 4.0\n"
581-
+ " }\n"
582-
+ " }\n"
583-
+ "}";
584-
585-
Expression expression =
586-
Expressions.stIntersects(
587-
"column-name",
588-
new BoundingBox(GeospatialBound.createXY(1, 2), GeospatialBound.createXY(3, 4)));
589-
assertThat(ExpressionParser.toJson(expression, true)).isEqualTo(expected);
590-
assertThat(ExpressionParser.toJson(ExpressionParser.fromJson(expected), true))
591-
.isEqualTo(expected);
592-
593-
expected =
594-
"{\n"
595-
+ " \"type\" : \"st-intersects\",\n"
596-
+ " \"term\" : \"column-name\",\n"
597-
+ " \"value\" : {\n"
598-
+ " \"x\" : {\n"
599-
+ " \"min\" : 1.0,\n"
600-
+ " \"max\" : 3.0\n"
601-
+ " },\n"
602-
+ " \"y\" : {\n"
603-
+ " \"min\" : 2.0,\n"
604-
+ " \"max\" : 4.0\n"
605-
+ " },\n"
606-
+ " \"m\" : {\n"
607-
+ " \"min\" : 3.0,\n"
608-
+ " \"max\" : 5.0\n"
609-
+ " }\n"
610-
+ " }\n"
611-
+ "}";
612-
613-
expression =
614-
Expressions.stIntersects(
615-
"column-name",
616-
new BoundingBox(
617-
GeospatialBound.createXYM(1, 2, 3), GeospatialBound.createXYM(3, 4, 5)));
618-
assertThat(ExpressionParser.toJson(expression, true)).isEqualTo(expected);
619-
assertThat(ExpressionParser.toJson(ExpressionParser.fromJson(expected), true))
620-
.isEqualTo(expected);
621-
622-
expected =
623-
"{\n"
624-
+ " \"type\" : \"st-intersects\",\n"
625-
+ " \"term\" : \"column-name\",\n"
626-
+ " \"value\" : {\n"
627-
+ " \"x\" : {\n"
628-
+ " \"min\" : 1.0,\n"
629-
+ " \"max\" : 3.0\n"
630-
+ " },\n"
631-
+ " \"y\" : {\n"
632-
+ " \"min\" : 2.0,\n"
633-
+ " \"max\" : 4.0\n"
634-
+ " },\n"
635-
+ " \"z\" : {\n"
636-
+ " \"min\" : 3.0,\n"
637-
+ " \"max\" : 5.0\n"
638-
+ " }\n"
639-
+ " }\n"
640-
+ "}";
641-
642-
expression =
643-
Expressions.stIntersects(
644-
"column-name",
645-
new BoundingBox(
646-
GeospatialBound.createXYZ(1, 2, 3), GeospatialBound.createXYZ(3, 4, 5)));
647-
assertThat(ExpressionParser.toJson(expression, true)).isEqualTo(expected);
648-
assertThat(ExpressionParser.toJson(ExpressionParser.fromJson(expected), true))
649-
.isEqualTo(expected);
650-
651-
expected =
652-
"{\n"
653-
+ " \"type\" : \"st-intersects\",\n"
654-
+ " \"term\" : \"column-name\",\n"
655-
+ " \"value\" : {\n"
656-
+ " \"x\" : {\n"
657-
+ " \"min\" : 1.0,\n"
658-
+ " \"max\" : 3.0\n"
659-
+ " },\n"
660-
+ " \"y\" : {\n"
661-
+ " \"min\" : 2.0,\n"
662-
+ " \"max\" : 4.0\n"
663-
+ " },\n"
664-
+ " \"z\" : {\n"
665-
+ " \"min\" : 3.0,\n"
666-
+ " \"max\" : 5.0\n"
667-
+ " },\n"
668-
+ " \"m\" : {\n"
669-
+ " \"min\" : 4.0,\n"
670-
+ " \"max\" : 6.0\n"
671-
+ " }\n"
672-
+ " }\n"
673-
+ "}";
674-
675-
expression =
676-
Expressions.stIntersects(
677-
"column-name",
678-
new BoundingBox(
679-
GeospatialBound.createXYZM(1, 2, 3, 4), GeospatialBound.createXYZM(3, 4, 5, 6)));
680-
assertThat(ExpressionParser.toJson(expression, true)).isEqualTo(expected);
681-
assertThat(ExpressionParser.toJson(ExpressionParser.fromJson(expected), true))
682-
.isEqualTo(expected);
683-
}
684547
}

0 commit comments

Comments
 (0)