Repository navigation
[SPARK-61181][CONNECT][PYTHON] Read the local relation settings of the server for local relations of 64 KiB or more, and raise LOCAL_RELATION_SIZE_LIMIT_EXCEEDED, in the Rust and Python clients as PySpark does - #379
Open
HyukjinKwon wants to merge 1 commit into
Open
HyukjinKwon wants to merge 1 commit into
HyukjinKwon wants to merge 1 commit into
Conversation
…e server for local relations of 64 KiB or more, and raise LOCAL_RELATION_SIZE_LIMIT_EXCEEDED, in the Rust and Python clients as PySpark does The Rust client read spark.sql.session.localRelationCacheThreshold and spark.sql.session.localRelationSizeLimit only for a local relation of at least 32 MiB. For a smaller one it sent the data inline, so the size limit was not applied. PySpark reads the settings for every relation and raises LOCAL_RELATION_SIZE_LIMIT_EXCEEDED past the limit. Now a relation of at least 64 KiB of Arrow data reads them on every createDataFrame path, and is sent as the Arrow importer sends it. A smaller relation is still sent inline without the configuration RPC. As in PySpark, the size limit is checked on the data chunks only, not on the schema chunk. Co-authored-by: Isaac <no-reply@databricks.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
SPARK-61181: PySpark Connect's
createDataFramereadsspark.sql.session.localRelationCacheThresholdandspark.sql.session.localRelationSizeLimitfor every local relation. At the threshold it uploads the relation as cache artifacts. Past the size limit it raisesLOCAL_RELATION_SIZE_LIMIT_EXCEEDED.The Rust client read these settings only for a relation of at least 32 MiB of Arrow data, and sent smaller relations inline without them. This change lowers that bound to 64 KiB. The bound is one constant,
LOCAL_RELATION_SETTINGS_BYTESincrates/spark-connect/src/session.rs, with a comment on why it is 64 KiB. It applies on every path that encodes a local relation:SparkSession::create_dataframe), and the pandas row conversion;create_dataframe_from_columns;StructTypeor a DDL schema, through the Arrow IPC bridge (create_dataframe_from_inline_arrow_ipc).These paths already called
arrow_input::create_relation, which applies the threshold and the size limit. Only the bound changes.The size limit is now checked on the data chunks only, as PySpark does. The schema chunk counts toward the size but is not checked against the limit (
crates/spark-connect/src/arrow_input.rs). Before, a schema alone above the limit failed, with anactualSizethat PySpark does not report.Why are the changes needed?
A local relation of 32 MiB or less was sent inline, so it did not fail past the server's size limit. With a session of
localRelationCacheThreshold1 andlocalRelationSizeLimit100, a 2,000-row relation of a long and a 100-character string gave:The same frame with a StructType schema on the float64 or string fast path also skipped the check. The Arrow importer, used for a DDL schema, did raise.
With the default settings too, a relation of 1 MiB (the default
localRelationCacheThreshold) to 32 MiB was sent inline, where PySpark uploads it as cache artifacts. It is now uploaded at the threshold.Relations below 64 KiB are still sent inline without reading the settings. A 200-row relation of 4,944 bytes stays inline and returns 200 rows, where PySpark 4.3.0 reads the settings and raises
LOCAL_RELATION_SIZE_LIMIT_EXCEEDED(checked against PySpark 4.3.0 on the same server). This PR does not change that difference.Does this PR introduce any user-facing change?
Yes. A local relation of 64 KiB or more under
spark.sql.session.localRelationSizeLimitnow raisesLOCAL_RELATION_SIZE_LIMIT_EXCEEDEDon the local rows, pandas, columns and fast paths, as PySpark does. A relation of 64 KiB or more at or above the threshold is uploaded as cache artifacts on those paths too. The size limit is checked on data chunks only, so a schema alone above the limit no longer fails.How was this patch tested?
python/tests/test_arrow_handoff.py, against the mock Arrow input service, for six paths (local rows, columns, pandas row conversion, float64, string and int64), each with a StructType and a DDL schema:test_local_relations_of_64_kib_read_the_settings_at_the_threshold: the settings are read; the relation is uploaded at a threshold of 1 byte and sent inline at the default threshold.test_local_relations_of_64_kib_past_the_size_limit_raise:LOCAL_RELATION_SIZE_LIMIT_EXCEEDEDis raised with the limit, and nothing is uploaded.test_local_relations_of_64_kib_the_same_for_struct_and_ddl: both schema forms have the same outcome.test_small_local_relations_stay_inline_without_reading_settingsnow uses a 500-row relation, asserted below 64 KiB of Arrow data.test_dropin_e2e.py::test_local_relations_of_64_kib_follow_the_size_limit_as_pyspark, against a live server: on a new session with a threshold of 1 and a limit of 100, local rows and a pandas frame, with StructType and DDL, raiseLOCAL_RELATION_SIZE_LIMIT_EXCEEDED, and the same data works with the defaults.LOCAL_RELATION_SIZE_LIMIT_EXCEEDEDin both, with the same limit. TheactualSizediffers by 736 bytes (225496 here, 224760 in PySpark), because the Arrow IPC bytes of the data chunk differ slightly.wasm-udf, the offline Python suites (2273 passed, 8 skipped), and the live drop-in and Arrow suites (215 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.