tdcmeehan opened a new pull request, #444:
URL: https://github.com/apache/spark-connect-rust/pull/444

   ### What changes were proposed in this pull request?
   
   [SPARK-61262](https://issues.apache.org/jira/browse/SPARK-61262): Allow 
Arrow batch chunking in ExecutePlan, so that a value over 128 MB can be 
collected, as PySpark does.
   
   - `SparkConnectClient::execute_plan` and `execute_plan_reattachable` 
(`spark-connect-core`) add `result_chunking_options { 
allow_arrow_batch_chunking: true }` to each ExecutePlan request, before the 
session hooks run, as PySpark's client does. No preferred chunk size is set. 
The protocol's ReattachExecute request has no request options, so the reattach 
does not carry the option; the server keeps the chunking of the execution it 
started.
   - The new `arrow_chunks` module of `spark-connect` joins the chunks of an 
Arrow batch, in order. `ExecutionStream::message`, which every execution 
consumer reads through (collect, collect with schema, collect record batches, 
`to_local_iterator` with and without prefetch, catalog operations, command 
results), applies it, so the batch is joined in one place. A chunk that is not 
the last one of its batch is returned without a batch; the last one carries the 
whole batch.
   - Errors: a chunk out of order and a batch that starts at a later chunk, as 
PySpark's iterator raises them; and, stricter than PySpark, chunks of one batch 
whose count or row count differ, a negative chunk count, and a stream that ends 
inside a batch (PySpark drops such a batch silently, which would return fewer 
rows). PySpark's checks of every batch's `start_offset` and decoded row count 
are not added here, as they are not specific to chunking.
   
   ### Why are the changes needed?
   
   The server sends an Arrow batch larger than the gRPC message limit (128 MiB) 
as one message unless the client asks for chunking. Without the option, 
`collect` of a single value over 128 MiB fails with `decoded message length too 
large`. PySpark asks for chunking and joins the chunks, so the same query 
returns the row there.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A collect, or a stream of rows, whose Arrow batch is larger than the 
message limit now succeeds instead of failing with a gRPC message-size error. 
No API changes. A chunked batch left unfinished at the end of the stream is an 
error rather than a truncated result.
   
   ### How was this patch tested?
   
   - Offline unit tests in `arrow_chunks` (`apache-spark-connect --lib`): 
chunks are joined in order into the batch; a batch that is not chunked passes 
through; responses without a batch may come between chunks; out-of-order 
chunks, a batch starting at a later chunk, a whole batch in the middle of 
chunks, chunks that disagree on the count or the row count, a negative count, 
and a stream that ends inside a batch are errors.
   - `executions_ask_the_server_to_chunk_arrow_batches` 
(`spark-connect-core/tests/server_session.rs`, against the loopback mock 
server): the ExecutePlan requests of both execution paths carry exactly one 
chunking option with `allow_arrow_batch_chunking: true` and no preferred chunk 
size. It fails when the option is not added.
   - `collect_joins_the_chunks_of_a_value_over_the_message_limit` 
(`spark-connect/tests/e2e_dataframe.rs`, server-gated): collects `repeat('x', 
129 MiB)`, one row, and checks its length.
   - Live e2e: `collect_joins_the_chunks_of_a_value_over_the_message_limit` 
passes against a local Spark 4.3.0 Connect server (`--test-threads=1`, 3.1 s, 
peak RSS about 525 MB). With the chunking option removed from the reattachable 
path, it fails with `decoded message length too large: found 135266902 bytes, 
the limit is: 134217728 bytes`.
   - Issue repro, `repeat('x', 140 * 1024 * 1024)` collected on the same 
server: the reference PySpark 4.3.0 client returns the row (length 146800640), 
and the drop-in built from this change returns the same row.
   - Pre-push checks: `cargo test -p apache-spark-connect --release --lib`, 
`--no-run`, and `--features wasm-udf --no-run`; `cargo fmt --all --check`; 
`cargo clippy --workspace --all-targets --release` reports no diagnostic on a 
changed line.
   - The Python client reads its results through the same stream: the offline 
Python suites (2927 passed, 8 skipped) and the live drop-in, Arrow and ML 
suites against a local Spark 4.3.0 server (236 passed, 1 skipped) pass.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5 and Claude Haiku 5.5
   
   This pull request and its description were written by Isaac.
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to