Skip to content

[SPARK-61143][CONNECT] Decode the Arrow batches that the server compresses with zstd or lz4 in the Rust client, as PySpark does - #336

Closed
HyukjinKwon wants to merge 1 commit into
apache:masterfrom
HyukjinKwon:SPARK-61143-arrow-compression
Closed

HyukjinKwon wants to merge 1 commit into
apache:masterfrom
HyukjinKwon:SPARK-61143-arrow-compression

Conversation

@HyukjinKwon

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

SPARK-61143: With spark.sql.execution.arrow.compression.codec set to zstd or lz4, the Spark Connect server compresses the Arrow batches of the results. PySpark reads them with PyArrow.

The Rust client now builds arrow with its ipc_compression feature, so it decodes the batches of either codec. Both clients get this: the Rust client, and the Python client, which decodes the results in Rust.

The only change to Cargo.lock is the zstd dependency of arrow-ipc. zstd, of polars-arrow, and lz4_flex, of arrow-ipc, were already in the lock file.

Why are the changes needed?

The client failed to decode the compressed batches:

PySparkRuntimeError: Failed to decode Arrow batch: Invalid argument error: zstd IPC decompression requires the zstd feature

So under that conf, collect, toArrow and toPandas failed, also on the results of pandas UDFs and applyInPandas. Nine tests of Apache Spark failed on this client, the *_with_compression_codec* tests of test_parity_arrow.py, test_parity_pandas_grouped_map.py and test_parity_pandas_udf_scalar.py.

Does this PR introduce any user-facing change?

Yes. The results compressed by the server with zstd or lz4 are decoded, as with PySpark 4.3.0.

How was this patch tested?

  • A new Rust unit test encodes batches with each codec and checks that they decode to the same rows and record batches as uncompressed ones.
  • A new live test collects a DataFrame, and converts it to Arrow and pandas, under each codec and none. It passes with official PySpark 4.3.0, and fails without this change.
  • The 10 compression tests of Apache Spark's test_parity_arrow.py, test_parity_pandas_grouped_map.py and test_parity_pandas_udf_scalar.py pass on this client against a local server.
  • The lib tests of both crates (591 passed), the build of all tests, also with wasm-udf, the offline Python suites (2202 passed, 8 skipped), and the live drop-in and Arrow suites (186 passed) and live cases (10 passed) against a local Spark 4.3.0 server. Clippy reports no diagnostics in the changed lines.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 5.5

This pull request and its description were written by Isaac.

…esses with zstd or lz4 in the Rust client, as PySpark does

With spark.sql.execution.arrow.compression.codec set to zstd or lz4, the server compresses the
Arrow batches of the results, which PySpark reads with PyArrow. The client built arrow without
the ipc_compression feature, so it failed to decode them ("zstd IPC decompression requires the
zstd feature"), in collect, toArrow and toPandas, also of the results of pandas UDFs. arrow now
has the feature, which adds no crate to the lock file but the zstd dependency of arrow-ipc.

Co-authored-by: Isaac <no-reply@databricks.com>
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.

1 participant