3131import java .util .function .Supplier ;
3232import org .apache .iceberg .Schema ;
3333import 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 ;
3734import org .apache .iceberg .relocated .com .google .common .base .Preconditions ;
3835import org .apache .iceberg .relocated .com .google .common .collect .ImmutableList ;
3936import 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 ();
0 commit comments