moulimukherjee commented on a change in pull request #327: Introduce startsWith 
Predicate
URL: https://github.com/apache/incubator-iceberg/pull/327#discussion_r311725364
 
 

 ##########
 File path: api/src/main/java/org/apache/iceberg/transforms/Truncate.java
 ##########
 @@ -213,20 +213,35 @@ public boolean canTransform(Type type) {
 
     @Override
     public UnboundPredicate<CharSequence> project(String name,
-                                                  BoundPredicate<CharSequence> 
pred) {
-      if (pred.op() == NOT_NULL || pred.op() == IS_NULL) {
-        return Expressions.predicate(pred.op(), name);
+                                                  BoundPredicate<CharSequence> 
predicate) {
+      switch (predicate.op()) {
+        case NOT_NULL:
+        case IS_NULL:
+          return Expressions.predicate(predicate.op(), name);
+        case STARTS_WITH:
+        default:
+          return ProjectionUtil.truncateArray(name, predicate, this);
       }
-      return ProjectionUtil.truncateArray(name, pred, this);
     }
 
     @Override
     public UnboundPredicate<CharSequence> projectStrict(String name,
-                                                        
BoundPredicate<CharSequence> pred) {
-      if (pred.op() == NOT_NULL || pred.op() == IS_NULL) {
-        return Expressions.predicate(pred.op(), name);
+                                                        
BoundPredicate<CharSequence> predicate) {
+      switch (predicate.op()) {
+        case IS_NULL:
+        case NOT_NULL:
+          return Expressions.predicate(predicate.op(), name);
+        case STARTS_WITH:
+          if (predicate.literal().value().length() < width()) {
+            return Expressions.predicate(predicate.op(), name, 
predicate.literal().value());
+          } else if (predicate.literal().value().length() == width()) {
+            return Expressions.equal(name, predicate.literal().value());
+          } else {
+            return null;
 
 Review comment:
   Returning `ProjectionUtil.truncateArrayStrict(name, predicate, this)` would 
still return null anyways, since it can't handle the `STARTS_WITH` case. So I 
think it makes sense to return `null` here.

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