Skip to content

feat(data): enforce residual filters in the task reader - #1065

Merged
wgtmac merged 5 commits into
apache:mainfrom
kamcheungting-db:feat/task-residual-enforcement
Nov 10, 2026
Merged

wgtmac merged 5 commits into
apache:mainfrom
kamcheungting-db:feat/task-residual-enforcement

Conversation

@kamcheungting-db

Copy link
Copy Markdown
Contributor

FileScanTaskReader gains two Options: case_sensitive (matching the planning scan's setting, because task residuals are unbound) and apply_residuals (default false, keeping the serial reader's results unchanged; the parallel reader will always enable it).

When enabled, each task's residual is enforced row by row after deletes and before the final projection with the existing Evaluator. Residual-only columns are appended to the read schema and projected away again, so a filter can reference columns absent from the output projection. Residuals are bound against the table schema with the configured case sensitivity; unresolvable or nested references fail with explicit errors instead of silently returning unfiltered rows. ReaderOptions.filter is still forwarded to format readers as a pruning hint, but nothing relies on it.

The merge-on-read stream source now also serves tasks without deletes when a residual must be enforced: delete filtering and residual evaluation are both optional, and the pass-through fast path only triggers when no filter removed a row.

Tests cover residuals with position and equality deletes, filter columns absent from the projection, case-insensitive residuals, null values, always-false residuals, kept row identities, apply_residuals disabled, and explicit errors for unknown, case-mismatched, and nested references.

@kamcheungting-db
kamcheungting-db force-pushed the feat/task-residual-enforcement branch from 6a278cc to 87764af Compare November 6, 2026 08:53
kamcheungting-db and others added 4 commits November 9, 2026 17:01
FileScanTaskReader gains two Options: case_sensitive (matching the planning
scan's setting, because task residuals are unbound) and apply_residuals
(default false, keeping the serial reader's results unchanged; the parallel
reader will always enable it).

When enabled, each task's residual is enforced row by row after deletes and
before the final projection with the existing Evaluator. Residual-only
columns are appended to the read schema and projected away again, so a
filter can reference columns absent from the output projection. Residuals
are bound against the table schema with the configured case sensitivity;
unresolvable or nested references fail with explicit errors instead of
silently returning unfiltered rows. ReaderOptions.filter is still forwarded
to format readers as a pruning hint, but nothing relies on it.

The merge-on-read stream source now also serves tasks without deletes when
a residual must be enforced: delete filtering and residual evaluation are
both optional, and the pass-through fast path only triggers when no filter
removed a row.

Tests cover residuals with position and equality deletes, filter columns
absent from the projection, case-insensitive residuals, null values,
always-false residuals, kept row identities, apply_residuals disabled, and
explicit errors for unknown, case-mismatched, and nested references.
Use std::ranges::sort for the residual field ids, and keep std::iota for
the row-index selection with a NOLINT: ranges::iota requires C++23, but
the repo builds with C++20 compatibility (same pattern as
parquet_reader.cc).
@wgtmac
wgtmac force-pushed the feat/task-residual-enforcement branch from 87764af to 28d3e9c Compare November 10, 2026 08:42
@wgtmac

wgtmac commented Nov 10, 2026

Copy link
Copy Markdown
Member

Sorry for the churn. My earlier comment on this PR #1065 (comment) pointed you toward #1062, before I posted my concerns about that approach #1062 (comment). That sent the implementation in the wrong direction.

I've rebased the branch and simplified the reader:

@wgtmac
wgtmac merged commit a82619e into apache:main Nov 10, 2026
15 checks passed
@wgtmac

wgtmac commented Nov 10, 2026

Copy link
Copy Markdown
Member

Thanks @kamcheungting-db for adding this and @shangxinli for the review!

wgtmac pushed a commit that referenced this pull request Nov 22, 2026
… group planning (#1113)

## What this PR does

Adds task-group planning for parallel scans, on top of the byte ranges from #976 and the range-aware Parquet reads from #1002:

- `DataTableScan::PlanTasksStream()` — lazy, fallible stream of `FileScanTaskGroup`
- `DataTableScan::PlanTasks()` — the same, collected into a vector

Eligible Parquet files are split into byte ranges, and the tasks are packed into groups of roughly `read.split.target-size` bytes.

## How it works

```
          PlanFilesStream()
                 |
                 v
          Whole Parquet file larger than target? -- no --> keep task as is
                 |
                yes
                 v
          Valid manifest split_offsets?
             | yes                    | no
             v                        v
          merge intervals          fixed-size byte ranges
          toward target            (shorter final range if needed)
                 |                    |
                 +---------+----------+
                           v
                 pack tasks into groups
                           |
                           v
                  FileScanTaskGroup stream
```

**Packing** — follows Java Iceberg’s first-fit and eviction rules:

- task weight = `max(range bytes + delete content bytes, (1 + delete files) * open-file-cost)`; a deletion vector counts its blob size, not its container file size
- a task joins the first open group that still fits
- at most `planning-lookback` groups stay open; when a new one opens, the largest open group is closed first
- at most 1,024 tasks per group; a task heavier than the target becomes its own group

**Files that stay whole:** files at or below the target size, non-Parquet files, and Parquet files whose valid manifest offsets yield only one range.

## Settings

| Property | Default | Resolves from |
|---|---|---|
| `read.split.target-size` | 128 MB | scan option > table property > default |
| `read.split.planning-lookback` | 10 | same |
| `read.split.open-file-cost` | 4 MB | same |

Malformed or invalid values fail planning before any planning work starts.

## Stream behavior

Single pass, lazy, owns the underlying task stream and its metrics, and can outlive the scan. An executor set with `PlanWith()` is borrowed and must stay alive until the group stream is destroyed. Destroying the stream mid-consumption releases all planning resources. The stream retains the current file’s remaining splits across calls to `Next()`. Splitting requires no data-file I/O or Parquet bundle registration.

## Tests

- `table_test` (core-only, includes `ScanTaskPlanningTest`): split coverage and merging, delete files and residual filters carried into every split, mixed Parquet/Avro groups, the Java weight formula, group packing (first fit, lookback, 1,024 cap, oversized singleton), settings precedence and errors, incremental consumption, early destruction.
- Bundled `scan_test`, across manifest format versions: split offsets used with no footer read (the file path does not exist), fixed-size ranges for missing or invalid offsets, files at or below target stay whole, every row read exactly once across splits, scan option beats table property, no-snapshot scans, delete files carried into every split.

`pre-commit` is clean.

## Related

Part 1 #976 · Part 2a #1002 · Part 2b #1062 · Part 2c #1065. The bounded parallel reader and end-to-end validation follow in later parts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants