From 03b2c726c9bc6143d5f169965054a4ef743bc374 Mon Sep 17 00:00:00 2001 From: Jinyang Li Date: Tue, 26 Mar 2024 10:59:13 -0700 Subject: [PATCH] Fix incorrect pushdown when no partitionSpec exists The constraint check was previously misbehaving when dealing with empty tables due to empty_stream.allMatch(...) always returns True. --- .../java/io/trino/plugin/iceberg/IcebergUtil.java | 10 ++++++++-- .../plugin/iceberg/BaseIcebergConnectorTest.java | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergUtil.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergUtil.java index 1f3706937b77..a8cfb404ba33 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergUtil.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergUtil.java @@ -406,9 +406,15 @@ public static boolean canEnforceColumnConstraintInSpecs( IcebergColumnHandle columnHandle, Domain domain) { - return table.specs().values().stream() + List partitionSpecs = table.specs().values().stream() .filter(partitionSpec -> partitionSpecIds.contains(partitionSpec.specId())) - .allMatch(spec -> canEnforceConstraintWithinPartitioningSpec(typeOperators, spec, columnHandle, domain)); + .collect(toImmutableList()); + + if (partitionSpecs.isEmpty()) { + return false; + } + + return partitionSpecs.stream().allMatch(spec -> canEnforceConstraintWithinPartitioningSpec(typeOperators, spec, columnHandle, domain)); } private static boolean canEnforceConstraintWithinPartitioningSpec(TypeOperators typeOperators, PartitionSpec spec, IcebergColumnHandle column, Domain domain) diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java index 12c2853b4fb3..694656f3e9b1 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java @@ -3802,6 +3802,21 @@ public void testPredicatePushdown() dropTable(tableName.getObjectName()); } + @Test + public void testPredicateOnDataColumnIsNotPushedDown() + { + try (TestTable testTable = new TestTable( + getQueryRunner()::execute, + "test_predicate_on_data_column_is_not_pushed_down", + "(a integer)")) { + assertThat(query("SELECT * FROM " + testTable.getName() + " WHERE a = 10")) + .isNotFullyPushedDown(FilterNode.class); + assertUpdate("INSERT INTO " + testTable.getName() + " VALUES 10", 1); + assertThat(query("SELECT * FROM " + testTable.getName() + " WHERE a = 10")) + .isNotFullyPushedDown(FilterNode.class); + } + } + @Test public void testPredicatesWithStructuralTypes() {