From 3a0a6d1514066f0b885b4f30cdc02257937cd115 Mon Sep 17 00:00:00 2001 From: xiaohongbo Date: Sun, 22 Nov 2026 23:50:17 -0800 Subject: [PATCH 1/3] Improve Python split read parallelism defaults --- bindings/python/README.md | 5 +- bindings/python/src/read.rs | 93 ++++++++++++++++++++++++++++++++++--- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/bindings/python/README.md b/bindings/python/README.md index 7674ff9c4..7d602d668 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -152,10 +152,13 @@ plan = scan.plan() batches = read_builder.new_read().read(plan.splits()) # Core schedules a bounded set of split readers and owns their global limit. +# By default, filtered reads without a limit use up to 64 splits for +# descriptors or 32 when the table may resolve BLOBs. Other reads use +# available CPU parallelism. The split count always caps the worker count. # Set ordered=True to retain the supplied split order. The default emits # whichever split group is ready first. Ordered parallel reads disable background # Parquet row-group prefetch; split workers still read concurrently. -reader = read_builder.new_read().read_arrow(plan.splits(), parallelism=4, ordered=False) +reader = read_builder.new_read().read_arrow(plan.splits()) try: for batch in reader: print(batch) diff --git a/bindings/python/src/read.rs b/bindings/python/src/read.rs index 4f2839927..cbc7947f0 100644 --- a/bindings/python/src/read.rs +++ b/bindings/python/src/read.rs @@ -992,15 +992,69 @@ 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, + available_parallelism: usize, +) -> usize { + let cap = if !filtered_without_limit { + available_parallelism + } 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, ordered: bool, ) -> PyResult { 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()); + let available_parallelism = std::thread::available_parallelism() + .map(|count| count.get()) + .unwrap_or(1); + default_split_parallelism( + splits.len(), + resolves_blob, + self.filter.is_some() && self.limit.is_none(), + available_parallelism, + ) + }); py.detach(|| { let mut builder = self.table.new_read_builder(); apply_read_config( @@ -1044,12 +1098,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 use + /// the available CPU parallelism. + #[pyo3(signature = (splits, *, parallelism = None, ordered = false))] fn read_arrow( &self, py: Python<'_>, splits: &Bound<'_, PyAny>, - parallelism: usize, + parallelism: Option, ordered: bool, ) -> PyResult { Ok(PyRecordBatchReader::from_stream(self.read_stream( @@ -1061,12 +1118,12 @@ impl PyTableRead { } /// Read the given splits into a list of PyArrow RecordBatches. - #[pyo3(signature = (splits, *, parallelism = 1, ordered = false))] + #[pyo3(signature = (splits, *, parallelism = None, ordered = false))] fn read( &self, py: Python<'_>, splits: &Bound<'_, PyAny>, - parallelism: usize, + parallelism: Option, ordered: bool, ) -> PyResult>> { let stream = self.read_stream(py, splits, parallelism, ordered)?; @@ -1404,11 +1461,35 @@ mod tests { use paimon::catalog::Identifier; use paimon::io::FileIOBuilder; - use paimon::spec::{IntType, Schema, TableSchema}; + use paimon::spec::{ArrayType, BlobType, IntType, MapType, Schema, TableSchema, VarCharType}; use pyo3::types::PyList; use super::*; + #[test] + fn default_parallelism_follows_split_count_and_payload_cap() { + assert_eq!(default_split_parallelism(0, false, true, 8), 1); + assert_eq!(default_split_parallelism(20, false, true, 8), 20); + assert_eq!(default_split_parallelism(100, false, true, 8), 64); + assert_eq!(default_split_parallelism(20, true, true, 8), 20); + assert_eq!(default_split_parallelism(100, true, true, 8), 32); + assert_eq!(default_split_parallelism(100, false, false, 8), 8); + } + + #[test] + fn payload_policy_includes_nested_managed_blob_fields() { + let blob = DataType::Blob(BlobType::new()); + assert!(is_managed_blob_type(&blob)); + assert!(is_managed_blob_type(&DataType::Array(ArrayType::new( + blob.clone() + )))); + assert!(is_managed_blob_type(&DataType::Map(MapType::new( + DataType::VarChar(VarCharType::string_type()), + blob, + )))); + assert!(!is_managed_blob_type(&DataType::Int(IntType::new()))); + } + #[test] fn row_id_plan_binding_routes_arrow_and_keeps_read_selection_separate() { Python::attach(|py| { From 0c3c7614926233ca686746705065f5e0bb2ee182 Mon Sep 17 00:00:00 2001 From: xiaohongbo Date: Mon, 23 Nov 2026 00:31:12 -0800 Subject: [PATCH 2/3] Make Python row-order tests request ordered reads --- bindings/python/tests/test_read.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bindings/python/tests/test_read.py b/bindings/python/tests/test_read.py index 7f98cc55c..f6892d6bd 100644 --- a/bindings/python/tests/test_read.py +++ b/bindings/python/tests/test_read.py @@ -1868,7 +1868,7 @@ def test_append_row_position_slices_and_shards_are_native_readable(row_tracking) ): plan = builder.new_scan().with_row_position_slice(start, end).plan() restored = [Split.deserialize(split.serialize()) for split in plan.splits()] - batches = builder.new_read().read(restored) + batches = builder.new_read().read(restored, ordered=True) actual = pa.Table.from_batches(batches).column("id").to_pylist() if batches else [] assert actual == expected assert plan.snapshot_id() == 3 @@ -1876,7 +1876,7 @@ def test_append_row_position_slices_and_shards_are_native_readable(row_tracking) shards = [] for index, expected in enumerate(([0, 1, 2], [3, 4], [5, 6], [7, 8])): plan = builder.new_scan().with_row_position_shard(index, 4).plan() - actual = pa.Table.from_batches(builder.new_read().read(plan.splits())) + actual = pa.Table.from_batches(builder.new_read().read(plan.splits(), ordered=True)) values = actual.column("id").to_pylist() assert values == expected shards.extend(values) @@ -1898,9 +1898,14 @@ def test_append_row_positions_follow_stats_pruned_file_order_before_limit(row_tr plan = builder.new_scan().with_row_position_slice(1, 5).plan() # Stats remove the first file before positions are assigned. LIMIT # must not truncate the candidate files before applying the slice. - full_selection = table.new_read_builder().with_projection(["id"]).new_read().read(plan.splits()) + full_selection = ( + table.new_read_builder() + .with_projection(["id"]) + .new_read() + .read(plan.splits(), ordered=True) + ) assert pa.Table.from_batches(full_selection).column("id").to_pylist() == [4, 5, 6, 7] - actual = pa.Table.from_batches(builder.new_read().read(plan.splits())) + actual = pa.Table.from_batches(builder.new_read().read(plan.splits(), ordered=True)) # The configured reader enforces the final LIMIT after selection. assert actual.column("id").to_pylist() == expected @@ -1919,7 +1924,7 @@ def test_append_incremental_row_positions_use_combined_delta_order(): .plan() ) restored = [pickle.loads(pickle.dumps(split)) for split in plan.splits()] - actual = pa.Table.from_batches(builder.new_read().read(restored)) + actual = pa.Table.from_batches(builder.new_read().read(restored, ordered=True)) assert actual.column("id").to_pylist() == expected From 03bb880d7a77b635b98e09b7af171ac476a96856 Mon Sep 17 00:00:00 2001 From: xiaohongbo Date: Mon, 23 Nov 2026 00:33:52 -0800 Subject: [PATCH 3/3] Limit automatic split parallelism to filtered reads --- bindings/python/README.md | 4 ++-- bindings/python/src/read.rs | 23 +++++++++-------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/bindings/python/README.md b/bindings/python/README.md index 7d602d668..b3ea5f657 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -153,8 +153,8 @@ batches = read_builder.new_read().read(plan.splits()) # Core schedules a bounded set of split readers and owns their global limit. # By default, filtered reads without a limit use up to 64 splits for -# descriptors or 32 when the table may resolve BLOBs. Other reads use -# available CPU parallelism. The split count always caps the worker count. +# descriptors or 32 when the table may resolve BLOBs. Other reads retain +# the single-split default. The split count always caps the worker count. # Set ordered=True to retain the supplied split order. The default emits # whichever split group is ready first. Ordered parallel reads disable background # Parquet row-group prefetch; split workers still read concurrently. diff --git a/bindings/python/src/read.rs b/bindings/python/src/read.rs index cbc7947f0..eceba50ef 100644 --- a/bindings/python/src/read.rs +++ b/bindings/python/src/read.rs @@ -999,10 +999,9 @@ fn default_split_parallelism( split_count: usize, resolves_blob: bool, filtered_without_limit: bool, - available_parallelism: usize, ) -> usize { let cap = if !filtered_without_limit { - available_parallelism + 1 } else if resolves_blob { DEFAULT_BLOB_SPLIT_PARALLELISM } else { @@ -1045,14 +1044,10 @@ impl PyTableRead { || (self.table.rest_env().is_some() && options.blob_view_resolve_enabled() && !options.blob_view_fields().is_empty()); - let available_parallelism = std::thread::available_parallelism() - .map(|count| count.get()) - .unwrap_or(1); default_split_parallelism( splits.len(), resolves_blob, self.filter.is_some() && self.limit.is_none(), - available_parallelism, ) }); py.detach(|| { @@ -1099,8 +1094,8 @@ impl PyTableRead { /// Core owns split scheduling, the global row limit and cancellation. /// ordered=True retains the supplied split order; the default emits ready groups first. /// Without an explicit parallelism, filtered reads without a limit use up - /// to 64 splits for descriptors or 32 for BLOB payloads. Other reads use - /// the available CPU parallelism. + /// 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))] fn read_arrow( &self, @@ -1468,12 +1463,12 @@ mod tests { #[test] fn default_parallelism_follows_split_count_and_payload_cap() { - assert_eq!(default_split_parallelism(0, false, true, 8), 1); - assert_eq!(default_split_parallelism(20, false, true, 8), 20); - assert_eq!(default_split_parallelism(100, false, true, 8), 64); - assert_eq!(default_split_parallelism(20, true, true, 8), 20); - assert_eq!(default_split_parallelism(100, true, true, 8), 32); - assert_eq!(default_split_parallelism(100, false, false, 8), 8); + assert_eq!(default_split_parallelism(0, false, true), 1); + assert_eq!(default_split_parallelism(20, false, true), 20); + assert_eq!(default_split_parallelism(100, false, true), 64); + assert_eq!(default_split_parallelism(20, true, true), 20); + assert_eq!(default_split_parallelism(100, true, true), 32); + assert_eq!(default_split_parallelism(100, false, false), 1); } #[test]