Kontinuation commented on code in PR #14101:
URL: https://github.com/apache/iceberg/pull/14101#discussion_r2935545789


##########
api/src/main/java/org/apache/iceberg/expressions/Literals.java:
##########
@@ -719,4 +723,71 @@ public String toString() {
       return "X'" + BaseEncoding.base16().encode(bytes) + "'";
     }
   }
+
+  static class BoundingBoxLiteral implements Literal<ByteBuffer> {
+    private static final Comparator<ByteBuffer> CMP =
+        
Comparators.<ByteBuffer>nullsFirst().thenComparing(Comparators.unsignedBytes());
+
+    private final ByteBuffer value;
+
+    BoundingBoxLiteral(BoundingBox value) {
+      this.value = value.toByteBuffer();
+    }
+
+    BoundingBoxLiteral(ByteBuffer value) {
+      Preconditions.checkNotNull(value, "Bounding box buffer cannot be null");
+      this.value = value.slice().order(ByteOrder.LITTLE_ENDIAN);
+    }
+
+    @Override
+    public ByteBuffer value() {
+      return value;
+    }
+
+    @Override
+    public ByteBuffer toByteBuffer() {
+      return value;
+    }
+
+    @Override
+    public <T> Literal<T> to(Type type) {
+      if (type.typeId() != Type.TypeID.GEOMETRY && type.typeId() != 
Type.TypeID.GEOGRAPHY) {
+        return null;
+      }
+
+      return (Literal<T>) this;
+    }
+
+    @Override
+    public Comparator<ByteBuffer> comparator() {

Review Comment:
   Having a comparator makes it integrates more cleanly with the rest of the 
code base by avoiding special-casing 
[`BoundLiteralPredicate.test`](https://github.com/apache/iceberg/blob/a50c2d920aadbb79f978bac10d1271bc4aa63a1a/api/src/main/java/org/apache/iceberg/expressions/BoundLiteralPredicate.java#L73)
 and 
[`BoundLiteralPredicate.isEquivalentTo`](https://github.com/apache/iceberg/blob/a50c2d920aadbb79f978bac10d1271bc4aa63a1a/api/src/main/java/org/apache/iceberg/expressions/BoundLiteralPredicate.java#L104).
 I have reimplemented the comparator to have better semantics for BoundingBox 
values.



-- 
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]

Reply via email to