Skip to content

fix(arrow): skip data files with a known zero record count - #3682

Merged
CTTY merged 3 commits into
apache:mainfrom
alexanderbianchi:fix/arrow-reader-empty-files
Nov 14, 2026
Merged

CTTY merged 3 commits into
apache:mainfrom
alexanderbianchi:fix/arrow-reader-empty-files

Conversation

@alexanderbianchi

@alexanderbianchi alexanderbianchi commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #3681.

What changes are included in this PR?

Return an empty stream from FileScanTaskReader::process when the task has a known zero record count (Some(0)), before loading deletes or opening the Parquet reader.

The metrics evaluator already excludes zero-record files when empty files are not requested, but unfiltered scans can bypass that evaluator. Tasks can also be supplied directly to ArrowReader::read. Those tasks currently try to load a footer even though they cannot contribute rows, failing on zero-byte or missing files.

The check belongs in the Arrow reader so it covers both planned and directly supplied tasks.

Explicit mapping to the Java implementation

The semantic rule is known zero records means no rows to read. Java applies it during metrics evaluation and avoids zero-length read ranges during splitting.

This PR Java reference (Iceberg 1.10.0)
task.record_count() == Some(0) returns an empty stream. InclusiveMetricsEvaluator.MetricsEvalVisitor.eval returns ROWS_CANNOT_MATCH when file.recordCount() == 0, before evaluating the predicate.
None does not take the empty-file fast path. The same Java method treats an unknown legacy record count (recordCount() < 0) as ROWS_MIGHT_MATCH, not an empty file.
Empty tasks do not open a data-file reader. For a splittable data file without split offsets, BaseContentScanTask.split uses FixedSizeSplitScanTaskIterator. Its hasNext() is remainingLength > 0, so a zero-length file produces no file-range tasks.

For that splitting path, BaseContentScanTask.length() calls ScanTaskUtil.contentSizeInBytes, which returns fileSizeInBytes() for data files. Trino 479's IcebergSplitSource uses this splitting path for scans projecting data columns.

The Rust change deliberately uses record count, not byte size: a positive-record/zero-byte task must still fail. Keeping the check in FileScanTaskReader::process also covers direct task streams from data sources without requiring a particular planner or predicate.

@alexanderbianchi
alexanderbianchi marked this pull request as ready for review November 12, 2026 22:22

@CTTY CTTY left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@CTTY
CTTY added this pull request to the merge queue Nov 14, 2026
Merged via the queue into apache:main with commit 6612395 Nov 14, 2026
25 checks passed
@alexanderbianchi

Copy link
Copy Markdown
Contributor Author

Thank you for the quick review + merge! We noticed this on production migrating trino traffic to datafusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arrow reader opens data files with a known zero record count

2 participants