Skip to content

Make Spark readers function asynchronously for many small files. #15287

@varun-lakhyani

Description

@varun-lakhyani

Feature Request / Improvement

In Spark readers, scan tasks are currently processed sequentially. The iteration logic in BaseReader.next() opens one task at a time, fully consumes it, and only then proceeds to the next task.

public boolean next() throws IOException {
try {
while (true) {
if (currentIterator.hasNext()) {
this.current = currentIterator.next();
return true;
} else if (tasks.hasNext()) {
this.currentIterator.close();
this.currentTask = tasks.next();
this.currentIterator = open(currentTask);
} else {
this.currentIterator.close();
return false;
}
}

With a large number of small files let's say hundreds or thousands of 5–10 KB files, this sequential task processing can lead to significant overhead.
Each task is opened and read independently, which may underutilize available CPU and I/O parallelism, especially on object stores with non-trivial per request latency.

Possible Improvement:
It may be beneficial to optionally allow Spark readers to process multiple small-file tasks concurrently, buffering rows into a shared iterator for downstream processing, while preserving the existing sequential behavior by default.

Query engine

None

Willingness to contribute

  • I would be willing to contribute this improvement/feature with guidance from the Iceberg community

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementPR that improves existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions