You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "jtuglu1 (via GitHub)" <gi...@apache.org> on 2026/01/25 21:25:04 UTC
[PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
jtuglu1 opened a new pull request, #18953:
URL: https://github.com/apache/druid/pull/18953
<!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
<!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
Fixes #XXXX.
<!-- Replace XXXX with the id of the issue fixed in this PR. Remove this section if there is no corresponding issue. Don't reference the issue in the title of this pull-request. -->
<!-- If you are a committer, follow the PR action item checklist for committers:
https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers. -->
### Description
<!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
<!-- Describe your patch: what did you change in code? How did you fix the problem? -->
<!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
#### Fixed the bug ...
#### Renamed the class ...
#### Added a forbidden-apis entry ...
<!--
In each section, please describe design decisions made, including:
- Choice of algorithms
- Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
- Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
- Method organization and design (how the logic is split between methods, parameters and return types)
- Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
-->
<!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
<!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
<!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
#### Release note
<!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users.
If your change doesn't have end user impact, you can skip this section.
For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
-->
<hr>
##### Key changed/added classes in this PR
* `MyFoo`
* `OurBar`
* `TheirBaz`
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [ ] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 merged PR #18953:
URL: https://github.com/apache/druid/pull/18953
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2734703265
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +127,47 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters if mode is not IGNORE
+ if (effectiveMode != ResidualFilterMode.IGNORE && detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
+ detectedResidual = residual;
+ }
+ }
+ }
+
+ // Handle residual filter based on mode
+ if (detectedResidual != null) {
+ String message = StringUtils.format(
+ "Iceberg filter produced residual expression that requires row-level filtering. "
+ + "This typically means the filter is on a non-partition column. "
+ + "Residual rows may be ingested unless filtered by transformSpec. "
+ + "Residual filter: [%s]",
+ detectedResidual
+ );
+
+ if (effectiveMode == ResidualFilterMode.FAIL) {
+ throw new IAE(
+ "%s To allow residual rows, set residualFilterMode to 'ignore' or 'warn', "
+ + "or add a corresponding filter in transformSpec.",
+ message
+ );
+ } else if (effectiveMode == ResidualFilterMode.WARN) {
+ log.warn(message);
+ }
+ }
Review Comment:
That's fine with me. It's only a single log and reduces branching.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2740090401
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +107,44 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters
+ if (detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
+ detectedResidual = residual;
+ }
+ }
+ }
+
+ // Handle residual filter based on mode
+ if (detectedResidual != null) {
+ String message = StringUtils.format(
+ "Iceberg filter produced residual expression that requires row-level filtering. "
+ + "This typically means the filter is on a non-partition column. "
+ + "Residual rows may be ingested unless filtered by transformSpec. "
+ + "Residual filter: [%s]",
+ detectedResidual
+ );
+
+ if (residualFilterMode == ResidualFilterMode.FAIL) {
+ throw DruidException.forPersona(DruidException.Persona.DEVELOPER)
Review Comment:
Should this be `Admin` persona rather than `Developer`? (developer is for unexpected things / bugs)
##########
extensions-contrib/druid-iceberg-extensions/src/test/java/org/apache/druid/iceberg/input/IcebergInputSourceTest.java:
##########
@@ -215,6 +222,104 @@ public void testCaseInsensitiveFiltering() throws IOException
Assert.assertEquals(1, localInputSourceList.size());
}
+ @Test
+ public void testResidualFilterModeIgnore() throws IOException
+ {
+ // Filter on non-partition column with IGNORE mode should succeed
+ IcebergInputSource inputSource = new IcebergInputSource(
+ TABLENAME,
+ NAMESPACE,
+ new IcebergEqualsFilter("id", "123988"),
+ testCatalog,
+ new LocalInputSourceFactory(),
+ null,
+ ResidualFilterMode.IGNORE
+ );
+ Stream<InputSplit<List<String>>> splits = inputSource.createSplits(null, new MaxSizeSplitHintSpec(null, null));
+ Assert.assertEquals(1, splits.count());
+ }
+
+ @Test
+ public void testResidualFilterModeFail() throws IOException
+ {
+ // Filter on non-partition column with FAIL mode should throw exception
+ IcebergInputSource inputSource = new IcebergInputSource(
+ TABLENAME,
+ NAMESPACE,
+ new IcebergEqualsFilter("id", "123988"),
+ testCatalog,
+ new LocalInputSourceFactory(),
+ null,
+ ResidualFilterMode.FAIL
+ );
+ DruidException exception = Assert.assertThrows(
+ DruidException.class,
+ () -> inputSource.createSplits(null, new MaxSizeSplitHintSpec(null, null))
+ );
+ Assert.assertTrue(
+ "Expect residual error to be thrown",
+ exception.getMessage().contains("residual")
+ );
+ }
+
+ @Test
+ public void testResidualFilterModeFailWithPartitionedTable() throws IOException
+ {
+ // Create a partitioned table and filter on the partition column
+ TableIdentifier partitionedTableId = TableIdentifier.of(Namespace.of(NAMESPACE), "partitionedTable");
Review Comment:
Could assign this to `tableIdentifier` and I think we can remove the try - finally block along with cleanup `dropTableFromCatalog(tableIdentifier)` since it's already part of `teardown()`?
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergInputSource.java:
##########
@@ -177,6 +183,13 @@ public DateTime getSnapshotTime()
return snapshotTime;
}
+ @Nullable
Review Comment:
no longer Nullable:
```suggestion
```
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2734722206
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +127,47 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters if mode is not IGNORE
+ if (effectiveMode != ResidualFilterMode.IGNORE && detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
Review Comment:
I don't think so. If you change partitions, etc. I think it can still be non-null. Void transforms are another possibility.
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +127,47 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters if mode is not IGNORE
+ if (effectiveMode != ResidualFilterMode.IGNORE && detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
Review Comment:
I don't think so. If you change partitions, etc. I think it can still be non-null. Partitions created via void transforms are another possibility.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2740155504
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +107,44 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters
+ if (detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
+ detectedResidual = residual;
+ }
+ }
+ }
+
+ // Handle residual filter based on mode
+ if (detectedResidual != null) {
+ String message = StringUtils.format(
+ "Iceberg filter produced residual expression that requires row-level filtering. "
+ + "This typically means the filter is on a non-partition column. "
+ + "Residual rows may be ingested unless filtered by transformSpec. "
+ + "Residual filter: [%s]",
+ detectedResidual
+ );
+
+ if (residualFilterMode == ResidualFilterMode.FAIL) {
+ throw DruidException.forPersona(DruidException.Persona.DEVELOPER)
Review Comment:
Considering a developer is the person running the ingests (same as with queries), I figured we'd surface it there. IMO Admin should not be concerned with the state of data, but rather how/whether the data can be ingested at all.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2734649261
##########
docs/ingestion/input-sources.md:
##########
@@ -1063,6 +1063,7 @@ The following is a sample spec for a S3 warehouse source:
|icebergCatalog|The JSON Object used to define the catalog that manages the configured Iceberg table.|yes|
|warehouseSource|The JSON Object that defines the native input source for reading the data files from the warehouse.|yes|
|snapshotTime|Timestamp in ISO8601 DateTime format that will be used to fetch the most recent snapshot as of this time.|no|
+|residualFilterMode|Controls how residual filters are handled when filtering on non-partition columns. When an Iceberg filter targets a non-partition column, files may contain rows that don't match the filter (residual rows). Valid values are: `ignore` (default, ingest all rows), `warn` (log a warning but continue), `fail` (fail the ingestion job). Use `fail` to ensure filters only target partition columns.|no|
Review Comment:
fwiw, this is also the same behavior with Delta lake filtering, where the filter predicates are pushed down to partition columns; for filtering on non-partition columns, it's best-effort
---
It might also make sense to update `icebergFilter` in the docs to clarify how filtering on partition columns vs non-partition columns behave and perhaps point to this new property `residualFilterMode`
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2734601466
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -70,12 +74,35 @@ public List<String> extractSnapshotDataFiles(
IcebergFilter icebergFilter,
DateTime snapshotTime
)
+ {
+ return extractSnapshotDataFiles(tableNamespace, tableName, icebergFilter, snapshotTime, null);
+ }
Review Comment:
This old signature appears to be unused, can be removed?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2734722206
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +127,47 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters if mode is not IGNORE
+ if (effectiveMode != ResidualFilterMode.IGNORE && detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
Review Comment:
I don't think so. If you change partitions, etc. I think it can still be non-null. Partitions created via void transforms are another possibility. If there is residual, it should show up regardless of filtereed-column partitioning.
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +127,47 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters if mode is not IGNORE
+ if (effectiveMode != ResidualFilterMode.IGNORE && detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
Review Comment:
I don't think so. If you change partitions, etc. I think it can still be non-null. Partitions created via void transforms are another possibility. If there is residual, it should show up regardless of filtered-column partitioning.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2734702058
##########
docs/ingestion/input-sources.md:
##########
@@ -1063,6 +1063,7 @@ The following is a sample spec for a S3 warehouse source:
|icebergCatalog|The JSON Object used to define the catalog that manages the configured Iceberg table.|yes|
|warehouseSource|The JSON Object that defines the native input source for reading the data files from the warehouse.|yes|
|snapshotTime|Timestamp in ISO8601 DateTime format that will be used to fetch the most recent snapshot as of this time.|no|
+|residualFilterMode|Controls how residual filters are handled when filtering on non-partition columns. When an Iceberg filter targets a non-partition column, files may contain rows that don't match the filter (residual rows). Valid values are: `ignore` (default, ingest all rows), `warn` (log a warning but continue), `fail` (fail the ingestion job). Use `fail` to ensure filters only target partition columns.|no|
Review Comment:
Sure – I think this is already clear in the iceberg.md changes:
```
When an Iceberg filter is applied on a non-partition column, the filtering happens at the file metadata level only (using column statistics). Files that might contain matching rows are returned, but these files may include "residual" rows that don't actually match the filter. These residual rows would be ingested unless filtered by a `transformSpec` filter on the Druid side.
To control this behavior, you can set the `residualFilterMode` property on the Iceberg input source:
```
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2734619570
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +127,47 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters if mode is not IGNORE
+ if (effectiveMode != ResidualFilterMode.IGNORE && detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
+ detectedResidual = residual;
+ }
+ }
+ }
+
+ // Handle residual filter based on mode
+ if (detectedResidual != null) {
+ String message = StringUtils.format(
+ "Iceberg filter produced residual expression that requires row-level filtering. "
+ + "This typically means the filter is on a non-partition column. "
+ + "Residual rows may be ingested unless filtered by transformSpec. "
+ + "Residual filter: [%s]",
+ detectedResidual
+ );
+
+ if (effectiveMode == ResidualFilterMode.FAIL) {
+ throw new IAE(
+ "%s To allow residual rows, set residualFilterMode to 'ignore' or 'warn', "
+ + "or add a corresponding filter in transformSpec.",
+ message
+ );
+ } else if (effectiveMode == ResidualFilterMode.WARN) {
+ log.warn(message);
+ }
+ }
long duration = System.currentTimeMillis() - start;
log.info("Data file scan and fetch took [%d ms] time for [%d] paths", duration, dataFilePaths.size());
}
+ catch (IAE e) {
+ throw e;
+ }
Review Comment:
Is this catch block needed? It can just fall through to the generic block below.
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -70,12 +74,35 @@ public List<String> extractSnapshotDataFiles(
IcebergFilter icebergFilter,
DateTime snapshotTime
)
+ {
+ return extractSnapshotDataFiles(tableNamespace, tableName, icebergFilter, snapshotTime, null);
+ }
+
+ /**
+ * Extract the iceberg data files upto the latest snapshot associated with the table
+ *
+ * @param tableNamespace The catalog namespace under which the table is defined
+ * @param tableName The iceberg table name
+ * @param icebergFilter The iceberg filter that needs to be applied before reading the files
+ * @param snapshotTime Datetime that will be used to fetch the most recent snapshot as of this time
+ * @param residualFilterMode Controls how residual filters are handled. When filtering on non-partition
+ * columns, residual rows may be returned that need row-level filtering.
+ * @return a list of data file paths
+ */
+ public List<String> extractSnapshotDataFiles(
+ String tableNamespace,
+ String tableName,
+ IcebergFilter icebergFilter,
+ DateTime snapshotTime,
+ @Nullable ResidualFilterMode residualFilterMode
+ )
{
Catalog catalog = retrieveCatalog();
Namespace namespace = Namespace.of(tableNamespace);
String tableIdentifier = tableNamespace + "." + tableName;
List<String> dataFilePaths = new ArrayList<>();
+ ResidualFilterMode effectiveMode = residualFilterMode != null ? residualFilterMode : ResidualFilterMode.IGNORE;
Review Comment:
This initialization when the value is null can be done in the `IcebergInputSource` constructor and then we can just pass a non-null mode everywhere.
##########
docs/development/extensions-contrib/iceberg.md:
##########
@@ -139,6 +139,37 @@ java \
See [Loading community extensions](../../configuration/extensions.md#loading-community-extensions) for more information.
+## Residual filter handling
+
+When an Iceberg filter is applied on a non-partition column, the filtering happens at the file metadata level only (using column statistics). Files that might contain matching rows are returned, but these files may include "residual" rows that don't actually match the filter. These residual rows would be ingested unless filtered by a `transformSpec` filter on the Druid side.
+
+To control this behavior, you can set the `residualFilterMode` property on the Iceberg input source:
+
+| Mode | Description |
+|------|-------------|
+| `ignore` | Default. Residual rows are ingested unless filtered by `transformSpec`. |
+| `warn` | Log a warning when residual filters are detected, but continue with ingestion. |
Review Comment:
I feel having a separate mode for `warn` is unnecessary. Can we just fold a warning log in both the `ignore` and `fail` modes?
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +127,47 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters if mode is not IGNORE
+ if (effectiveMode != ResidualFilterMode.IGNORE && detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
+ detectedResidual = residual;
+ }
+ }
+ }
+
+ // Handle residual filter based on mode
+ if (detectedResidual != null) {
+ String message = StringUtils.format(
+ "Iceberg filter produced residual expression that requires row-level filtering. "
+ + "This typically means the filter is on a non-partition column. "
+ + "Residual rows may be ingested unless filtered by transformSpec. "
+ + "Residual filter: [%s]",
+ detectedResidual
+ );
+
+ if (effectiveMode == ResidualFilterMode.FAIL) {
+ throw new IAE(
+ "%s To allow residual rows, set residualFilterMode to 'ignore' or 'warn', "
+ + "or add a corresponding filter in transformSpec.",
+ message
+ );
+ } else if (effectiveMode == ResidualFilterMode.WARN) {
+ log.warn(message);
+ }
+ }
Review Comment:
IMO it’d be better to always log a warning when a residual filter is detected (regardless of mode), not sure anyone would want just `warn`.
What do you think about simplifying this to two just two modes: `ignore` (default) and `fail`? (we cadn still keep it as an enum for extensibility)
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +127,47 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters if mode is not IGNORE
+ if (effectiveMode != ResidualFilterMode.IGNORE && detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
+ detectedResidual = residual;
+ }
+ }
+ }
+
+ // Handle residual filter based on mode
+ if (detectedResidual != null) {
+ String message = StringUtils.format(
+ "Iceberg filter produced residual expression that requires row-level filtering. "
+ + "This typically means the filter is on a non-partition column. "
+ + "Residual rows may be ingested unless filtered by transformSpec. "
+ + "Residual filter: [%s]",
+ detectedResidual
+ );
+
+ if (effectiveMode == ResidualFilterMode.FAIL) {
+ throw new IAE(
Review Comment:
nit: throw `DruidException`
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -100,12 +127,47 @@ public List<String> extractSnapshotDataFiles(
tableScan = tableScan.caseSensitive(isCaseSensitive());
CloseableIterable<FileScanTask> tasks = tableScan.planFiles();
- CloseableIterable.transform(tasks, FileScanTask::file)
- .forEach(dataFile -> dataFilePaths.add(dataFile.path().toString()));
+
+ Expression detectedResidual = null;
+ for (FileScanTask task : tasks) {
+ dataFilePaths.add(task.file().path().toString());
+
+ // Check for residual filters if mode is not IGNORE
+ if (effectiveMode != ResidualFilterMode.IGNORE && detectedResidual == null) {
+ Expression residual = task.residual();
+ if (residual != null && !residual.equals(Expressions.alwaysTrue())) {
Review Comment:
Is the residual expression from task guaranteed to be null for filters on partition columns? (i.e., confirming there would be no false negatives)
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/IcebergCatalog.java:
##########
@@ -70,12 +74,35 @@ public List<String> extractSnapshotDataFiles(
IcebergFilter icebergFilter,
DateTime snapshotTime
)
+ {
+ return extractSnapshotDataFiles(tableNamespace, tableName, icebergFilter, snapshotTime, null);
+ }
Review Comment:
Appears to be unused, can be removed?
##########
extensions-contrib/druid-iceberg-extensions/src/main/java/org/apache/druid/iceberg/input/ResidualFilterMode.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.iceberg.input;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+
+/**
+ * Controls how residual filters are handled during Iceberg table scanning.
+ *
+ * When an Iceberg filter is applied on a non-partition column, the filtering happens at the
+ * file metadata level only. Files that might contain matching rows are returned, but these
+ * files may include "residual" rows that don't actually match the filter. These residual rows
+ * would need to be filtered on the Druid side using a filter in transformSpec.
+ */
+public enum ResidualFilterMode
+{
+ /**
+ * Ignore residual filters. This is the default behavior for backward compatibility.
+ * Residual rows will be ingested unless filtered by transformSpec.
+ */
+ IGNORE("ignore"),
+
+ /**
+ * Log a warning when residual filters are detected, but continue with ingestion.
+ * Useful for identifying potential data quality issues without failing the job.
+ */
+ WARN("warn"),
+
+ /**
+ * Fail the ingestion job when residual filters are detected.
+ * Use this mode to ensure that only partition-column filters are used,
+ * preventing unintended residual rows from being ingested.
+ */
+ FAIL("fail");
+
+ private final String value;
+
+ ResidualFilterMode(String value)
+ {
+ this.value = value;
+ }
+
+ @JsonValue
+ public String getValue()
+ {
+ return value;
+ }
+
+ public static ResidualFilterMode fromString(String value)
+ {
+ for (ResidualFilterMode mode : values()) {
+ if (mode.value.equalsIgnoreCase(value)) {
+ return mode;
+ }
+ }
+ throw new IllegalArgumentException(
+ "Unknown residualFilterMode: " + value + ". Valid values are: ignore, warn, fail"
+ );
Review Comment:
`DruidException` for better UX
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Allow failing on residual for Iceberg filters on non-partition cols (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #18953:
URL: https://github.com/apache/druid/pull/18953#discussion_r2740221976
##########
extensions-contrib/druid-iceberg-extensions/src/test/java/org/apache/druid/iceberg/input/IcebergInputSourceTest.java:
##########
@@ -215,6 +222,104 @@ public void testCaseInsensitiveFiltering() throws IOException
Assert.assertEquals(1, localInputSourceList.size());
}
+ @Test
+ public void testResidualFilterModeIgnore() throws IOException
+ {
+ // Filter on non-partition column with IGNORE mode should succeed
+ IcebergInputSource inputSource = new IcebergInputSource(
+ TABLENAME,
+ NAMESPACE,
+ new IcebergEqualsFilter("id", "123988"),
+ testCatalog,
+ new LocalInputSourceFactory(),
+ null,
+ ResidualFilterMode.IGNORE
+ );
+ Stream<InputSplit<List<String>>> splits = inputSource.createSplits(null, new MaxSizeSplitHintSpec(null, null));
+ Assert.assertEquals(1, splits.count());
+ }
+
+ @Test
+ public void testResidualFilterModeFail() throws IOException
+ {
+ // Filter on non-partition column with FAIL mode should throw exception
+ IcebergInputSource inputSource = new IcebergInputSource(
+ TABLENAME,
+ NAMESPACE,
+ new IcebergEqualsFilter("id", "123988"),
+ testCatalog,
+ new LocalInputSourceFactory(),
+ null,
+ ResidualFilterMode.FAIL
+ );
+ DruidException exception = Assert.assertThrows(
+ DruidException.class,
+ () -> inputSource.createSplits(null, new MaxSizeSplitHintSpec(null, null))
+ );
+ Assert.assertTrue(
+ "Expect residual error to be thrown",
+ exception.getMessage().contains("residual")
+ );
+ }
+
+ @Test
+ public void testResidualFilterModeFailWithPartitionedTable() throws IOException
+ {
+ // Create a partitioned table and filter on the partition column
+ TableIdentifier partitionedTableId = TableIdentifier.of(Namespace.of(NAMESPACE), "partitionedTable");
Review Comment:
We can, I just did separate tables as it means the other table set in setup() would not get dropped without a preemptive cleanup.
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org