rdblue commented on a change in pull request #628: [WIP] Implement the project
and the projectStrict in the transforms
URL: https://github.com/apache/incubator-iceberg/pull/628#discussion_r350302733
##########
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:
This is a case where the streams API is much more verbose than using Guava
Iterables, so I think we should prefer Iterables:
```
return Expressions.notIn(name,
Iterables.transform(predicate.asSetPredicate().literalSet(), this::apply));
```
----------------------------------------------------------------
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]