Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/src/main/java/org/apache/iceberg/transforms/Identity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.ObjectStreamException;
import java.util.Set;
import org.apache.iceberg.expressions.BoundPredicate;
import org.apache.iceberg.expressions.BoundReference;
import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.expressions.UnboundPredicate;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
Expand Down Expand Up @@ -146,6 +147,10 @@ public UnboundPredicate<T> project(String name, BoundPredicate<T> predicate) {

@Override
public UnboundPredicate<T> projectStrict(String name, BoundPredicate<T> predicate) {
if (!(predicate.term() instanceof BoundReference)) {
return null;
}

if (predicate.isUnaryPredicate()) {
return Expressions.predicate(predicate.op(), name);
} else if (predicate.isLiteralPredicate()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,30 @@ public void testProjectionNames() {
Projections.inclusive(partitionSpec).project(equal(truncate("string", 10), "abc"));
assertThat(predicate.ref().name()).isEqualTo("string_trunc");
}

@Test
public void testIdentityProjectionWithTransformPredicate() {
// Regression test for https://github.com/apache/iceberg/issues/15502
// Identity-partitioned timestamptz field filtered with hours() should not throw
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence looks incomplete. "... should not throw ValidationException"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — completed the sentence.

// ValidationException when projecting the predicate.
Schema schema =
new Schema(
required(1, "id", Types.LongType.get()),
required(2, "ts", Types.TimestampType.withZone()));

PartitionSpec spec = PartitionSpec.builderFor(schema).identity("ts").build();

// hours(ts) = 490674 produces an integer literal that cannot bind to timestamptz.
// Without the fix, projectStrict() attempts to create an UnboundPredicate with the
// integer literal for a timestamptz field, which fails during binding.
Expression hourFilter = equal(hour("ts"), 490674);

// Inclusive projection: cannot project → falls back to alwaysTrue
Expression projected = Projections.inclusive(spec).project(hourFilter);
assertThat(projected).isEqualTo(Expressions.alwaysTrue());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValidationException isn't thrown in this test even if I revert a change of Identity.java‎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception is caught internally by the projection framework and converted to alwaysTrue/alwaysFalse. Without the fix, projectStrict() creates an UnboundPredicate with an integer literal for a timestamptz field, which fails during binding — the test assertion fails because the projection result is neither alwaysTrue nor alwaysFalse. Updated the comments to explain this more clearly.


// Strict projection: cannot project → falls back to alwaysFalse
Expression strictProjected = Projections.strict(spec).project(hourFilter);
assertThat(strictProjected).isEqualTo(Expressions.alwaysFalse());
}
}
Loading