JingsongLi commented on code in PR #1504:
URL: https://github.com/apache/paimon-rust/pull/1504#discussion_r4663596802
##########
bindings/python/src/read.rs:
##########
@@ -1044,12 +1093,15 @@ impl PyTableRead {
/// Lazily read the given splits as PyArrow RecordBatches.
/// Core owns split scheduling, the global row limit and cancellation.
/// ordered=True retains the supplied split order; the default emits ready
groups first.
- #[pyo3(signature = (splits, *, parallelism = 1, ordered = false))]
+ /// 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))]
Review Comment:
**[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.
##########
bindings/python/src/read.rs:
##########
@@ -992,15 +992,64 @@ pub struct PyTableRead {
include_row_kind: bool,
}
+const DEFAULT_DESCRIPTOR_SPLIT_PARALLELISM: usize = 64;
+const DEFAULT_BLOB_SPLIT_PARALLELISM: usize = 32;
+
+fn default_split_parallelism(
+ split_count: usize,
+ resolves_blob: bool,
+ filtered_without_limit: bool,
+) -> usize {
+ let cap = if !filtered_without_limit {
+ 1
+ } else if resolves_blob {
+ DEFAULT_BLOB_SPLIT_PARALLELISM
+ } else {
+ DEFAULT_DESCRIPTOR_SPLIT_PARALLELISM
+ };
+ split_count.min(cap).max(1)
+}
+
+fn is_managed_blob_type(data_type: &DataType) -> bool {
+ match data_type {
+ DataType::Blob(_) => true,
+ DataType::Array(array) => array.element_type().is_blob_type(),
+ DataType::Map(map) => map.value_type().is_blob_type(),
+ _ => false,
+ }
+}
+
impl PyTableRead {
fn read_stream(
&self,
py: Python<'_>,
splits: &Bound<'_, PyAny>,
- parallelism: usize,
+ parallelism: Option<usize>,
ordered: bool,
) -> PyResult<ArrowRecordBatchStream> {
let splits = extract_splits(splits)?;
+ let parallelism = parallelism.unwrap_or_else(|| {
+ let options = self.table.schema().core_options();
+ // 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()
Review Comment:
**[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.
##########
bindings/python/src/read.rs:
##########
@@ -992,15 +992,64 @@ pub struct PyTableRead {
include_row_kind: bool,
}
+const DEFAULT_DESCRIPTOR_SPLIT_PARALLELISM: usize = 64;
+const DEFAULT_BLOB_SPLIT_PARALLELISM: usize = 32;
+
+fn default_split_parallelism(
+ split_count: usize,
+ resolves_blob: bool,
+ filtered_without_limit: bool,
+) -> usize {
+ let cap = if !filtered_without_limit {
+ 1
+ } else if resolves_blob {
+ DEFAULT_BLOB_SPLIT_PARALLELISM
+ } else {
+ DEFAULT_DESCRIPTOR_SPLIT_PARALLELISM
+ };
+ split_count.min(cap).max(1)
+}
+
+fn is_managed_blob_type(data_type: &DataType) -> bool {
+ match data_type {
+ DataType::Blob(_) => true,
+ DataType::Array(array) => array.element_type().is_blob_type(),
+ DataType::Map(map) => map.value_type().is_blob_type(),
+ _ => false,
+ }
+}
+
impl PyTableRead {
fn read_stream(
&self,
py: Python<'_>,
splits: &Bound<'_, PyAny>,
- parallelism: usize,
+ parallelism: Option<usize>,
ordered: bool,
) -> PyResult<ArrowRecordBatchStream> {
let splits = extract_splits(splits)?;
+ let parallelism = parallelism.unwrap_or_else(|| {
+ let options = self.table.schema().core_options();
+ // 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()
+ || self
+ .table
+ .schema()
+ .fields()
+ .iter()
+ .any(|field| is_managed_blob_type(field.data_type()));
+ let resolves_blob = (!options.blob_as_descriptor() && has_blob)
+ || (self.table.rest_env().is_some()
+ && options.blob_view_resolve_enabled()
+ && !options.blob_view_fields().is_empty());
+ default_split_parallelism(
Review Comment:
**[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.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]