timothyw553 commented on code in PR #19164:
URL: https://github.com/apache/iceberg/pull/19164#discussion_r4796386653
##########
api/src/test/java/org/apache/iceberg/transforms/TestTruncatesProjection.java:
##########
@@ -298,6 +336,193 @@ public void testLongInclusiveUpperBound() {
spec, notIn("value", value, value - 1), Expression.Operation.TRUE);
}
+ private static Stream<Arguments> integerTypes() {
+ return Stream.of(
+ Arguments.of(Types.IntegerType.get(), (long) Integer.MIN_VALUE),
+ Arguments.of(Types.LongType.get(), Long.MIN_VALUE));
+ }
+
+ private static Object sourceValue(Type type, long value) {
+ if (type.typeId() == Type.TypeID.INTEGER) {
+ return (int) value;
+ }
+
+ return value;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Object transform(PartitionSpec spec, Type type, long value) {
+ Transform<Object, Object> transform =
+ (Transform<Object, Object>) spec.fields().get(0).transform();
+ return transform.bind(type).apply(sourceValue(type, value));
+ }
+
+ private static long firstNormalPartition(long minimum, int width) {
+ return minimum + (width - Math.floorMod(minimum, width));
+ }
+
+ private static boolean evalProjection(
+ PartitionSpec spec, UnboundPredicate<?> filter, boolean strict, Object
partitionValue) {
+ Expression projection =
+ strict
+ ? Projections.strict(spec).project(filter)
+ : Projections.inclusive(spec).project(filter);
+ return new Evaluator(spec.partitionType(), projection, true)
+ .eval(TestHelpers.Row.of(partitionValue));
+ }
+
+ private static void assertProjectionEvaluation(
+ PartitionSpec spec,
+ UnboundPredicate<?> filter,
+ boolean strict,
+ Object partitionValue,
+ boolean expected) {
+ assertThat(evalProjection(spec, filter, strict,
partitionValue)).isEqualTo(expected);
+ }
+
+ @ParameterizedTest
Review Comment:
these new boundary tests (and the residual ones) only use widths 10 and
1000, so they miss MAX_VALUE, power-of-two widths, widths around 2^30, and
strict < / <= with null partitions. for example, changing `firstNormal - 1` to
`firstNormal - 2` in `ProjectionUtil` or dropping `notNull` on strict `<`/`<=`
still passes, even though width 3 with `x > MIN_VALUE` would prune every file.
could we add a bounded test over those widths and boundaries (including
residuals and legacy methods) checking that inclusive never drops matching
values and strict never accepts non-matching ones?
##########
api/src/main/java/org/apache/iceberg/expressions/ResidualEvaluator.java:
##########
@@ -243,19 +243,15 @@ public <T> Expression predicate(BoundPredicate<T> pred) {
for (PartitionField part : parts) {
// checking the strict projection
- UnboundPredicate<?> strictProjection =
- ((Transform<T, ?>) part.transform()).projectStrict(part.name(),
pred);
+ Expression strictProjection =
+ ((Transform<T, ?>) part.transform()).project(part.name(), pred,
true);
Expression strictResult = null;
if (strictProjection != null) {
- Expression bound = strictProjection.bind(spec.partitionType(),
caseSensitive);
- if (bound instanceof BoundPredicate) {
- strictResult = super.predicate((BoundPredicate<?>) bound);
- } else {
- // if the result is not a predicate, then it must be a constant
like alwaysTrue or
- // alwaysFalse
- strictResult = bound;
- }
+ strictResult =
+ new Evaluator(spec.partitionType(), strictProjection,
caseSensitive).eval(struct)
Review Comment:
nit: now that we evaluate projections with `Evaluator` instead of
`super.predicate(...)`, the 14 leaf overrides (`isNull` through `notStartsWith`
at lines 145-225) look unreachable. should we drop those overrides and unused
imports (`Comparator`, `Set`, `NaNUtil`) and have `ResidualVisitor` extend
`ExpressionVisitor<Expression>`?
##########
api/src/main/java/org/apache/iceberg/expressions/ResidualEvaluator.java:
##########
@@ -243,19 +243,15 @@ public <T> Expression predicate(BoundPredicate<T> pred) {
for (PartitionField part : parts) {
// checking the strict projection
- UnboundPredicate<?> strictProjection =
- ((Transform<T, ?>) part.transform()).projectStrict(part.name(),
pred);
+ Expression strictProjection =
+ ((Transform<T, ?>) part.transform()).project(part.name(), pred,
true);
Expression strictResult = null;
if (strictProjection != null) {
- Expression bound = strictProjection.bind(spec.partitionType(),
caseSensitive);
- if (bound instanceof BoundPredicate) {
- strictResult = super.predicate((BoundPredicate<?>) bound);
- } else {
- // if the result is not a predicate, then it must be a constant
like alwaysTrue or
- // alwaysFalse
- strictResult = bound;
- }
+ strictResult =
+ new Evaluator(spec.partitionType(), strictProjection,
caseSensitive).eval(struct)
Review Comment:
creating `new Evaluator(...)` here (and on the inclusive path below)
re-binds the projected expression on every `residualFor` call. a quick check on
truncate-int residuals measured ~1060-1110 ns vs ~700-750 ns on base. could we
confirm with a benchmark and, if it holds, pre-bind or reuse the projection
evaluators per predicate and partition field?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]