-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Fix filter pushdown for DELETE queries #13705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1793,9 +1793,42 @@ static Predicate<Map<ColumnHandle, NullableValue>> convertToPredicate(TupleDomai | |
| } | ||
|
|
||
| @Override | ||
| public boolean supportsMetadataDelete(ConnectorSession session, ConnectorTableHandle tableHandle) | ||
| public boolean supportsMetadataDelete(ConnectorSession session, ConnectorTableHandle tableHandle, Optional<ConnectorTableLayoutHandle> tableLayoutHandle) | ||
| { | ||
| return true; | ||
| if (!tableLayoutHandle.isPresent()) { | ||
|
||
| return true; | ||
| } | ||
|
|
||
| // Allow metadata delete for range filters on partition columns. | ||
| // TODO Add support for metadata delete for any filter on partition columns. | ||
|
|
||
| HiveTableLayoutHandle layoutHandle = (HiveTableLayoutHandle) tableLayoutHandle.get(); | ||
| if (!layoutHandle.isPushdownFilterEnabled()) { | ||
| return true; | ||
| } | ||
|
|
||
| if (layoutHandle.getPredicateColumns().isEmpty()) { | ||
| return true; | ||
| } | ||
|
|
||
| if (!TRUE_CONSTANT.equals(layoutHandle.getRemainingPredicate())) { | ||
| return false; | ||
| } | ||
|
|
||
| TupleDomain<Subfield> domainPredicate = layoutHandle.getDomainPredicate(); | ||
| if (domainPredicate.isAll()) { | ||
| return true; | ||
| } | ||
|
|
||
| Set<String> predicateColumnNames = domainPredicate.getDomains().get().keySet().stream() | ||
| .map(Subfield::getRootName) | ||
| .collect(toImmutableSet()); | ||
|
|
||
| Set<String> partitionColumnNames = layoutHandle.getPartitionColumns().stream() | ||
| .map(HiveColumnHandle::getName) | ||
| .collect(toImmutableSet()); | ||
|
|
||
| return partitionColumnNames.containsAll(predicateColumnNames); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1677,6 +1677,15 @@ public void testMetadataDelete() | |
|
|
||
| assertQuery("SELECT * from test_metadata_delete", "SELECT orderkey, linenumber, linestatus FROM lineitem WHERE linestatus<>'F' or linenumber<>3"); | ||
|
|
||
| // TODO This use case can be supported | ||
|
||
| try { | ||
| getQueryRunner().execute("DELETE FROM test_metadata_delete WHERE lower(LINE_STATUS)='f' and LINE_NUMBER=CAST(4 AS INTEGER)"); | ||
| fail("expected exception"); | ||
| } | ||
| catch (RuntimeException e) { | ||
| assertEquals(e.getMessage(), "This connector only supports delete where one or more partitions are deleted entirely"); | ||
| } | ||
|
|
||
| assertUpdate("DELETE FROM test_metadata_delete WHERE LINE_STATUS='O'"); | ||
|
|
||
| assertQuery("SELECT * from test_metadata_delete", "SELECT orderkey, linenumber, linestatus FROM lineitem WHERE linestatus<>'O' and linenumber<>3"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have an enumeration of comments to explain the cases when metadata delete can happen and when it can't? By looking at the code, it seems that it's not an all or nothing call given the filter could be "simple" or very "complicated" but turning to be simple if we do constant folding or even evaluation. Of course, there is a limit we can push. We can only inference the delete if the filter is not "that complicated" .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@highker James, thank you review.
Strictly speaking we should be able to support metadata delete for any filter that doesn't touch non-partition columns. Today we only support it for range filters on partition columns though (regardless of whether filter pushdown is on or off). I'll add a comment and a TODO.