You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2019/11/28 19:43:38 UTC

[GitHub] [incubator-iceberg] jun-he commented on a change in pull request #628: Implement the project and the projectStrict in the transforms

jun-he commented on a change in pull request #628: Implement the project and the projectStrict in the transforms
URL: https://github.com/apache/incubator-iceberg/pull/628#discussion_r351913877
 
 

 ##########
 File path: api/src/main/java/org/apache/iceberg/transforms/Bucket.java
 ##########
 @@ -111,45 +114,36 @@ public String toString() {
 
   @Override
   public UnboundPredicate<Integer> project(String name, BoundPredicate<T> predicate) {
-    if (predicate instanceof BoundUnaryPredicate) {
+    if (predicate.isUnaryPredicate()) {
       return Expressions.predicate(predicate.op(), name);
-    } else if (predicate instanceof BoundLiteralPredicate) {
-      BoundLiteralPredicate<T> pred = predicate.asLiteralPredicate();
-      switch (pred.op()) {
-        case EQ:
-          return Expressions.predicate(
-              pred.op(), name, apply(pred.literal().value()));
-//      case IN:
-//        return Expressions.predicate();
-        case STARTS_WITH:
-        default:
-          // comparison predicates can't be projected, notEq can't be projected
-          // TODO: small ranges can be projected.
-          // for example, (x > 0) and (x < 3) can be turned into in({1, 2}) and projected.
-          return null;
-      }
-    }
+    } else if (predicate.isLiteralPredicate() && predicate.op() == EQ) {
+      return Expressions.predicate(
+          predicate.op(), name, apply(predicate.asLiteralPredicate().literal().value()));
+    } else if (predicate.isSetPredicate() && predicate.op() == IN) { // notIn can't be projected
+      return Expressions.in(name,
+          predicate.asSetPredicate().literalSet()
+              .stream().map(this::apply).collect(Collectors.toList()));
+    }
+  // comparison predicates can't be projected, notEq can't be projected
+  // TODO: small ranges can be projected.
+  // for example, (x > 0) and (x < 3) can be turned into in({1, 2}) and projected.
 
     return null;
   }
 
   @Override
   public UnboundPredicate<Integer> projectStrict(String name, BoundPredicate<T> predicate) {
-    if (predicate instanceof BoundUnaryPredicate) {
+    if (predicate.isUnaryPredicate()) {
       return Expressions.predicate(predicate.op(), name);
-    } else if (predicate instanceof BoundLiteralPredicate) {
-      BoundLiteralPredicate<T> pred = predicate.asLiteralPredicate();
-      switch (pred.op()) {
-        case NOT_EQ: // TODO: need to translate not(eq(...)) into notEq in expressions
-          return Expressions.predicate(pred.op(), name, apply(pred.literal().value()));
-//      case NOT_IN:
-//        return null;
-        default:
-          // no strict projection for comparison or equality
-          return null;
-      }
-    }
-
+    } else if (predicate.isLiteralPredicate() && predicate.op() == NOT_EQ) {
+      // TODO: need to translate not(eq(...)) into notEq in expressions
+      return Expressions.predicate(predicate.op(), name, apply(predicate.asLiteralPredicate().literal().value()));
+    } else if (predicate.isSetPredicate() && predicate.op() == NOT_IN) {
+      return Expressions.notIn(name,
+          predicate.asSetPredicate().literalSet()
+              .stream().map(this::apply).collect(Collectors.toList()));
 
 Review comment:
   Refactored the code and used the `Iterables`.

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


With regards,
Apache Git Services

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