rdblue commented on a change in pull request #398: Push down StringStartsWith 
in Spark IcebergSource
URL: https://github.com/apache/incubator-iceberg/pull/398#discussion_r317264545
 
 

 ##########
 File path: 
api/src/main/java/org/apache/iceberg/expressions/InclusiveMetricsEvaluator.java
 ##########
 @@ -254,5 +258,43 @@ public Boolean or(Boolean leftResult, Boolean 
rightResult) {
     public <T> Boolean notIn(BoundReference<T> ref, Literal<T> lit) {
       return ROWS_MIGHT_MATCH;
     }
+
+    @Override
+    public <T> Boolean startsWith(BoundReference<T> ref, Literal<T> lit) {
+      int id = ref.fieldId();
+
+      String prefix = (String) lit.value();
+      ByteBuffer prefixAsBytes = 
ByteBuffer.wrap(prefix.getBytes(StandardCharsets.UTF_8));
+
+      Comparator<ByteBuffer> comparator = Comparators.unsignedBytes();
+
+      if (lowerBounds != null && lowerBounds.containsKey(id)) {
+        ByteBuffer lower = lowerBounds.get(id);
+        // take the same number of bytes from prefix and lower bound
+        int length = Math.min(prefixAsBytes.remaining(), lower.remaining());
+
+        int cmp = comparator.compare(
+            length < lower.remaining() ? BinaryUtil.truncateBinary(lower, 
length) : lower,
 
 Review comment:
   Also, the `truncate` methods will return the original value if there is no 
need to truncate, so you can simplify this code.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to