Skip to content

[python] Choose split read parallelism from planned splits - #1504

Draft
XiaoHongbo-Hope wants to merge 5 commits into
apache:mainfrom
XiaoHongbo-Hope:codex/python-read-auto-parallelism-20261123
Draft

XiaoHongbo-Hope wants to merge 5 commits into
apache:mainfrom
XiaoHongbo-Hope:codex/python-read-auto-parallelism-20261123

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

For filtered reads without LIMIT, derive the default worker count from the supplied splits. Cap ordinary and descriptor reads at 64 workers. Cap reads of known-size managed BLOBs at 32 when the physical files in the plan are covered by the shared output budget from #1508. External payloads and plans with uncertain BLOB coverage use one worker. REST BLOB View descriptor lookups use the 32-worker cap. Views that return stored references use the descriptor cap.

Unfiltered and limited reads default to one worker. Both read() and read_arrow() accept parallelism=None. A positive explicit value overrides the automatic policy. ordered=True retains split order.

Evidence

The original worker-cap sweep used three paired seeds on an 8-vCPU, 32-GiB ECS. Queries used a fixed content key, unordered reads, the default batch size, and a local page-cache drop before each cold run.

  • 1000-clip descriptor reads used 2.209 s and 631 MiB peak RSS at 64 workers, and 2.027 s and 786 MiB at 128 workers.
  • 100-clip full BLOB reads used 3.296 s and 4.34 GiB peak RSS at 32 workers, and 3.773 s and 5.63 GiB at 64 workers. Native CRC was enabled. Timing excludes measured Python SHA time.

These measurements selected the caps for the tested workload. The automatic BLOB path now uses the shared Core budget in #1508.

Validation

  • Rust tests cover split-count caps, unknown and historical BLOB layouts, packed-video descriptors, and unresolved Views.
  • Python tests exercise parallelism=None on both read() and read_arrow().
  • On head 5ca4c53f with merged [core] Bound queued BLOB split batches by a shared byte budget #1508, 11 Rust binding tests and 279 Python tests passed. The Python run used a locally built debug extension and included read, streaming scan, and BLOB suites.

@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review November 23, 2026 08:07

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All 222 Python read, streaming scan, and BLOB tests passed against a wheel built from this revision.

Comment thread bindings/python/src/read.rs Outdated
|| (self.table.rest_env().is_some()
&& options.blob_view_resolve_enabled()
&& !options.blob_view_fields().is_empty());
default_split_parallelism(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] Bound buffered BLOB bytes before enabling automatic parallelism.

The first poll starts a read for each split worker, and each worker can retain a materialized batch. The BLOB range-read permits are released when the I/O finishes. I reproduced this with 32 splits and a 16 MiB payload batch per split. After consuming and releasing the first read_arrow() batch and pausing, RSS was about 621 MiB with the default and 113 MiB with parallelism=1 on the same wheel. Larger image or video batches can exhaust memory even when the caller processes one batch at a time. Please keep the BLOB default at one worker until a shared byte budget covers the batches waiting to be consumed.

/// Without an explicit parallelism, filtered reads without a limit use up
/// to 64 splits for descriptors or 32 for BLOB payloads. Other reads keep
/// the existing single-split default.
#[pyo3(signature = (splits, *, parallelism = None, ordered = false))]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Update the shipped type stubs for both methods.

read() and read_arrow() now accept parallelism=None. The corresponding signatures in bindings/python/python/pypaimon_rust/datafusion.pyi still declare parallelism: int = 1 for both. The wheel ships py.typed, so type checkers reject an explicit None and editors show the old default. Please declare parallelism: int | None = None in both stubs and document when automatic parallelism applies.

Comment thread bindings/python/src/read.rs Outdated
// Favor the payload cap whenever this table may resolve a BLOB.
// Projection and filters can introduce hidden BLOB operands, so a
// wider default is only safe for descriptor-only reads.
let has_blob = !options.blob_fields().is_empty()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Use the descriptor cap for unresolved BLOB views.

If a table's only BLOB column is a blob-view-field and blob-view.resolve.enabled=false, Core returns the stored references. blob_fields() still includes the view, and the schema check also counts it as a scalar BLOB. With the default blob-as-descriptor=false, a filtered read with more than 32 splits therefore gets the payload cap. Please exclude view fields from the ordinary BLOB checks and use the REST and resolution conditions for views, as Core does.

@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft November 23, 2026 09:04
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review November 23, 2026 09:46
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft November 23, 2026 13:52
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review December 1, 2026 14:12
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft December 1, 2026 15:09
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.

2 participants