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

 ##########
 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:
   `BinaryUtil.truncateBinary` will complain if the length is lower than the 
number of remaining elements. I would probably change that to return the 
original value. 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to