Commit 3cf7e53
committed
[python] Add parallel split reading to to_pandas / to_arrow
Today TableRead.to_pandas / to_arrow iterate splits serially in
_arrow_batch_generator, so wall time scales linearly with the number
of splits even though PyArrow's parquet/orc readers release the GIL
during decode. Unlike Java, where Flink/Spark fan splits out across
TaskManagers/Executors, PyPaimon has no external framework above the
SDK; split-level parallelism therefore has to live inside the SDK.
This commit adds an opt-in dual-track API for split-level parallelism:
1. A new table option `read.parallelism` (default 1) sets the
persistent default for a table:
options={'read.parallelism': '4'}.
2. A new method argument `parallelism` on to_pandas / to_arrow
temporarily overrides the option for a single call:
read.to_pandas(splits, parallelism=8).
Priority: method argument > table option > built-in default of 1.
This covers both "configure once, all reads benefit" (option) and
ad-hoc tuning without altering the table schema (argument).
Behavior:
- effective == 1 (default or explicit) keeps the serial path
unchanged; no thread pool is created.
- effective >= 2 with at least 2 splits runs splits through a
ThreadPoolExecutor and assembles the final Table in the input
splits' order (results collected by submission index).
- effective < 1 (from either source) raises ValueError naming
whichever source produced the value.
Limit pushdown stays correct under parallelism via _RemainingRows, a
thread-safe row-quota counter. Quota is pre-debited under a single
lock so the combined output never exceeds self.limit, even if
individual readers decode one extra batch after the quota is gone -
that batch is simply dropped instead of being emitted.
Reader resource handling matches the serial path: each worker uses
try/finally to close its reader, and ThreadPoolExecutor's wait-on-
exit guarantees every started reader is closed before the call
returns, even when one worker raises.
Other to_* methods (to_arrow_batch_reader, to_iterator, to_duckdb,
to_ray, to_torch) are deliberately not touched in this round - their
order-preserving / streaming semantics deserve a separate look.
Tests cover:
- _RemainingRows correctness under unbounded, bounded, zero-request,
and 8-thread contention scenarios.
- Append-only multi-partition: parallel via method argument matches
serial byte-for-byte; parallel via table option also matches.
- Priority matrix: method argument overrides option (both directions),
option overrides default, explicit 1 keeps serial path.
- PK merge-on-read multi-bucket: parallel + serial produce the same
merged rows.
- Limit + parallel: 10 repeated runs return exactly the configured
row count.
- Edge cases: empty splits with parallelism=4, parallelism exceeding
split count, invalid method argument and invalid option value each
raise ValueError with a source-specific message.
- Reader error propagation: when one split's create_reader raises,
the exception surfaces from to_pandas and sibling readers are
cleaned up.1 parent be19168 commit 3cf7e53
3 files changed
Lines changed: 631 additions & 4 deletions
File tree
- paimon-python/pypaimon
- common/options
- read
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
449 | 449 | | |
450 | 450 | | |
451 | 451 | | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
452 | 464 | | |
453 | 465 | | |
454 | 466 | | |
| |||
702 | 714 | | |
703 | 715 | | |
704 | 716 | | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
705 | 720 | | |
706 | 721 | | |
707 | 722 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
35 | 72 | | |
36 | 73 | | |
37 | 74 | | |
| |||
52 | 89 | | |
53 | 90 | | |
54 | 91 | | |
| 92 | + | |
55 | 93 | | |
56 | 94 | | |
57 | 95 | | |
| |||
104 | 142 | | |
105 | 143 | | |
106 | 144 | | |
107 | | - | |
108 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
109 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
110 | 164 | | |
111 | 165 | | |
112 | 166 | | |
113 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
114 | 173 | | |
115 | 174 | | |
116 | 175 | | |
| |||
183 | 242 | | |
184 | 243 | | |
185 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
186 | 385 | | |
187 | 386 | | |
188 | 387 | | |
| |||
216 | 415 | | |
217 | 416 | | |
218 | 417 | | |
219 | | - | |
220 | | - | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
221 | 428 | | |
222 | 429 | | |
223 | 430 | | |
| |||
0 commit comments