Java Code Examples for org.apache.iceberg.expressions.Expressions#predicate()

The following examples show how to use org.apache.iceberg.expressions.Expressions#predicate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Truncate.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public UnboundPredicate<Integer> projectStrict(String name, BoundPredicate<Integer> pred) {
  if (pred.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, pred);
  }

  // TODO: for integers, can this return the original predicate?
  // No. the predicate needs to be in terms of the applied value. For all x, apply(x) <= x.
  // Therefore, the lower bound can be transformed outside of a greater-than bound.
  if (pred instanceof BoundUnaryPredicate) {
    return Expressions.predicate(pred.op(), name);
  } else if (pred instanceof BoundLiteralPredicate) {
    return ProjectionUtil.truncateIntegerStrict(name, pred.asLiteralPredicate(), this);
  } else if (pred.isSetPredicate() && pred.op() == Expression.Operation.NOT_IN) {
    return ProjectionUtil.transformSet(name, pred.asSetPredicate(), this);
  }
  return null;
}
 
Example 2
Source File: Truncate.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public UnboundPredicate<CharSequence> project(String name,
                                              BoundPredicate<CharSequence> predicate) {
  if (predicate.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, predicate);
  }

  if (predicate.isUnaryPredicate()) {
    return Expressions.predicate(predicate.op(), name);
  } else if (predicate.isLiteralPredicate()) {
    return ProjectionUtil.truncateArray(name, predicate.asLiteralPredicate(), this);
  } else if (predicate.isSetPredicate() && predicate.op() == Expression.Operation.IN) {
    return ProjectionUtil.transformSet(name, predicate.asSetPredicate(), this);
  }
  return null;
}
 
Example 3
Source File: Truncate.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public UnboundPredicate<CharSequence> projectStrict(String name,
                                                    BoundPredicate<CharSequence> predicate) {
  if (predicate.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, predicate);
  }

  if (predicate instanceof BoundUnaryPredicate) {
    return Expressions.predicate(predicate.op(), name);
  } else if (predicate instanceof BoundLiteralPredicate) {
    BoundLiteralPredicate<CharSequence> pred = predicate.asLiteralPredicate();
    if (pred.op() == Expression.Operation.STARTS_WITH) {
      if (pred.literal().value().length() < width()) {
        return Expressions.predicate(pred.op(), name, pred.literal().value());
      } else if (pred.literal().value().length() == width()) {
        return Expressions.equal(name, pred.literal().value());
      }
    } else {
      return ProjectionUtil.truncateArrayStrict(name, pred, this);
    }
  } else if (predicate.isSetPredicate() && predicate.op() == Expression.Operation.NOT_IN) {
    return ProjectionUtil.transformSet(name, predicate.asSetPredicate(), this);
  }
  return null;
}
 
Example 4
Source File: Truncate.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public UnboundPredicate<ByteBuffer> project(String name,
                                            BoundPredicate<ByteBuffer> pred) {
  if (pred.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, pred);
  }

  if (pred.isUnaryPredicate()) {
    return Expressions.predicate(pred.op(), name);
  } else if (pred.isLiteralPredicate()) {
    return ProjectionUtil.truncateArray(name, pred.asLiteralPredicate(), this);
  } else if (pred.isSetPredicate() && pred.op() == Expression.Operation.IN) {
    return ProjectionUtil.transformSet(name, pred.asSetPredicate(), this);
  }
  return null;
}
 
Example 5
Source File: Truncate.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public UnboundPredicate<ByteBuffer> projectStrict(String name,
                                                  BoundPredicate<ByteBuffer> pred) {
  if (pred.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, pred);
  }

  if (pred.isUnaryPredicate()) {
    return Expressions.predicate(pred.op(), name);
  } else if (pred.isLiteralPredicate()) {
    return ProjectionUtil.truncateArrayStrict(name, pred.asLiteralPredicate(), this);
  } else if (pred.isSetPredicate() && pred.op() == Expression.Operation.NOT_IN) {
    return ProjectionUtil.transformSet(name, pred.asSetPredicate(), this);
  }
  return null;
}
 
Example 6
Source File: Truncate.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public UnboundPredicate<BigDecimal> project(String name,
                                            BoundPredicate<BigDecimal> pred) {
  if (pred.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, pred);
  }

  if (pred.isUnaryPredicate()) {
    return Expressions.predicate(pred.op(), name);
  } else if (pred.isLiteralPredicate()) {
    return ProjectionUtil.truncateDecimal(name, pred.asLiteralPredicate(), this);
  } else if (pred.isSetPredicate() && pred.op() == Expression.Operation.IN) {
    return ProjectionUtil.transformSet(name, pred.asSetPredicate(), this);
  }
  return null;
}
 
Example 7
Source File: Truncate.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public UnboundPredicate<BigDecimal> projectStrict(String name,
                                                  BoundPredicate<BigDecimal> pred) {
  if (pred.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, pred);
  }

  if (pred.isUnaryPredicate()) {
    return Expressions.predicate(pred.op(), name);
  } else if (pred.isLiteralPredicate()) {
    return ProjectionUtil.truncateDecimalStrict(name, pred.asLiteralPredicate(), this);
  } else if (pred.isSetPredicate() && pred.op() == Expression.Operation.NOT_IN) {
    return ProjectionUtil.transformSet(name, pred.asSetPredicate(), this);
  }
  return null;
}
 
Example 8
Source File: Bucket.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public UnboundPredicate<Integer> project(String name, BoundPredicate<T> predicate) {
  if (predicate.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, predicate);
  }

  if (predicate.isUnaryPredicate()) {
    return Expressions.predicate(predicate.op(), name);
  } else if (predicate.isLiteralPredicate() && predicate.op() == Expression.Operation.EQ) {
    return Expressions.predicate(
        predicate.op(), name, apply(predicate.asLiteralPredicate().literal().value()));
  } else if (predicate.isSetPredicate() && predicate.op() == Expression.Operation.IN) { // notIn can't be projected
    return ProjectionUtil.transformSet(name, predicate.asSetPredicate(), this);
  }

  // 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;
}
 
Example 9
Source File: Bucket.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Override
public UnboundPredicate<Integer> projectStrict(String name, BoundPredicate<T> predicate) {
  if (predicate.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, predicate);
  }

  if (predicate.isUnaryPredicate()) {
    return Expressions.predicate(predicate.op(), name);
  } else if (predicate.isLiteralPredicate() && predicate.op() == Expression.Operation.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() == Expression.Operation.NOT_IN) {
    return ProjectionUtil.transformSet(name, predicate.asSetPredicate(), this);
  }

  // no strict projection for comparison or equality
  return null;
}
 
Example 10
Source File: Identity.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public UnboundPredicate<T> projectStrict(String name, BoundPredicate<T> predicate) {
  if (predicate.isUnaryPredicate()) {
    return Expressions.predicate(predicate.op(), name);
  } else if (predicate.isLiteralPredicate()) {
    return Expressions.predicate(predicate.op(), name, predicate.asLiteralPredicate().literal().value());
  } else if (predicate.isSetPredicate()) {
    return Expressions.predicate(predicate.op(), name, predicate.asSetPredicate().literalSet());
  }
  return null;
}
 
Example 11
Source File: ProjectionUtil.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private static <T> UnboundPredicate<T> removeTransform(String partitionName, BoundPredicate<T> pred) {
  if (pred.isUnaryPredicate()) {
    return Expressions.predicate(pred.op(), partitionName);
  } else if (pred.isLiteralPredicate()) {
    return Expressions.predicate(pred.op(), partitionName, pred.asLiteralPredicate().literal());
  } else if (pred.isSetPredicate()) {
    return Expressions.predicate(pred.op(), partitionName, pred.asSetPredicate().literalSet());
  }
  throw new UnsupportedOperationException("Cannot replace transform in unknown predicate: " + pred);
}
 
Example 12
Source File: Truncate.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public UnboundPredicate<Integer> project(String name, BoundPredicate<Integer> pred) {
  if (pred.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, pred);
  }

  if (pred.isUnaryPredicate()) {
    return Expressions.predicate(pred.op(), name);
  } else if (pred.isLiteralPredicate()) {
    return ProjectionUtil.truncateInteger(name, pred.asLiteralPredicate(), this);
  } else if (pred.isSetPredicate() && pred.op() == Expression.Operation.IN) {
    return ProjectionUtil.transformSet(name, pred.asSetPredicate(), this);
  }
  return null;
}
 
Example 13
Source File: Truncate.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public UnboundPredicate<Long> project(String name, BoundPredicate<Long> pred) {
  if (pred.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, pred);
  }

  if (pred.isUnaryPredicate()) {
    return Expressions.predicate(pred.op(), name);
  } else if (pred.isLiteralPredicate()) {
    return ProjectionUtil.truncateLong(name, pred.asLiteralPredicate(), this);
  } else if (pred.isSetPredicate() && pred.op() == Expression.Operation.IN) {
    return ProjectionUtil.transformSet(name, pred.asSetPredicate(), this);
  }
  return null;
}
 
Example 14
Source File: Truncate.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
public UnboundPredicate<Long> projectStrict(String name, BoundPredicate<Long> pred) {
  if (pred.term() instanceof BoundTransform) {
    return ProjectionUtil.projectTransformPredicate(this, name, pred);
  }

  if (pred.isUnaryPredicate()) {
    return Expressions.predicate(pred.op(), name);
  } else if (pred.isLiteralPredicate()) {
    return ProjectionUtil.truncateLongStrict(name, pred.asLiteralPredicate(), this);
  } else if (pred.isSetPredicate() && pred.op() == Expression.Operation.NOT_IN) {
    return ProjectionUtil.transformSet(name, pred.asSetPredicate(), this);
  }
  return null;
}