Skip to content

Commit

Permalink
Fix incorrect pushdown when no partitionSpec exists
Browse files Browse the repository at this point in the history
The constraint check was previously misbehaving when dealing with empty tables
due to empty_stream.allMatch(...) always returns True.
  • Loading branch information
jinyangli34 authored and raunaqmorarka committed Mar 27, 2024
1 parent a643a47 commit 03b2c72
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,15 @@ public static boolean canEnforceColumnConstraintInSpecs(
IcebergColumnHandle columnHandle,
Domain domain)
{
return table.specs().values().stream()
List<PartitionSpec> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 03b2c72

Please sign in to comment.