HyukjinKwon opened a new pull request, #762:
URL: https://github.com/apache/spark-connect-rust/pull/762
### What changes were proposed in this pull request?
PySpark 4.3.0's `createDataFrame` (`pyspark/sql/connect/session.py`) reads
13 settings in one Config `get`, in a fixed order. It does so for every kind of
data that is not empty (rows, dicts, pandas, numpy, pyarrow, generators), after
it parses a DDL schema and checks for empty data and an array's dimensions, and
before it converts any data:
`spark.sql.timestampType`, `spark.sql.session.timeZone`, the five
`spark.sql.session.localRelation*` settings,
`spark.sql.execution.pandas.convertToArrowArraySafely`,
`spark.sql.execution.pandas.inferPandasDictAsMap`, the three inference settings
(`spark.sql.pyspark.inferNestedDictAsStruct.enabled` and the two
`legacy.infer*`), and `spark.sql.execution.arrow.useLargeVarTypes`.
The drop-in read them piecemeal, so its requests differed. Through a
recording proxy on a live server:
| data | PySpark | before this PR |
|---|---|---|
| rows, a struct schema, a generator | 1 get of 13 keys | none |
| a DDL schema | `ddl_parse`, then the get | `ddl_parse` only |
| dicts or datetimes (inference) | the get | a get of 4 inference keys |
| pandas | the get | a get of 8 keys of another order, then 2 single gets |
| numpy, pyarrow | the get | the get of 8 keys |
| empty data with a schema | none | none |
Small local rows also never read the server's `localRelationCacheThreshold`,
so they were sent inline even when the server's threshold asked for an upload.
This PR:
- makes the core's `ArrowInputOptions` read PySpark's 13 keys in PySpark's
order and carry all of them. The 8 keys it already read remain required; the
other 5 default to false when the server omits them;
- reads that snapshot once per `createDataFrame`, at PySpark's point, and
makes every conversion path take its settings from it:
- inference (it replaces `LazyConfs`);
- the pandas sub-paths (`convertToArrowArraySafely`,
`inferPandasDictAsMap` and the session time zone);
- numpy, where the read now comes before the checks of the columns, as
PySpark's;
- pyarrow;
- rows and the integer-column fast path, through new `*_with_options`
entry points of the core;
- applies the cache threshold at any size when the snapshot is given. Below
it, the plans stay byte-identical to the old ones.
The Rust API's `create_dataframe`, which has no inference or pandas, is
unchanged.
`docs/architecture.md` describes the one read.
The test suites had cases that created DataFrames on a session to a refused
port and expected no request. PySpark tries the server first there, so those
cases now run against the mock server, and the mock answers the three inference
settings as a 4.3.0 server does. `python/tests/conftest.py`'s session-finish
hook also no longer fails when the tests run on official PySpark, which has no
`pyspark._pyspark`.
### Why are the changes needed?
To send the same requests as PySpark 4.3.0's `createDataFrame`, and to apply
the server's settings, the cache threshold included, as PySpark does.
### Does this PR introduce _any_ user-facing change?
Yes:
- `createDataFrame` of data that is not empty now sends one Config request
of PySpark's settings, where small local rows sent none.
- A session's `localRelationCacheThreshold` now applies to small local data
too.
### How was this patch tested?
- Through a recording proxy on a live Spark 4.3.0 server, the requests of
`createDataFrame` for 12 kinds of data are identical to official PySpark
4.3.0's: tuples with names, a struct schema and a DDL schema, inferred Rows,
dicts and datetimes, pandas, numpy, pyarrow, empty data, a generator, and data
above the cache threshold.
- New `python/tests/test_create_dataframe_configs_offline.py` (15 cases),
added to the offline gate in `coverage.yml`. It checks:
- the one get of the 13 keys for each kind of data;
- the `ddl_parse` before it;
- no request for empty data;
- the get before numpy's `AXIS_LENGTH_MISMATCH`, and before a rejected row.
- `cargo test -p apache-spark-connect -p apache-spark-connect-core
--release` passes (1566 passed).
- `test_arrow_handoff.py` now expects PySpark's 13 keys in its pinned
requests. The CI-order offline and live suites are running locally; any further
tests that pinned the old requests are updated in follow-up commits on this PR,
and this description will be updated with the results.
### 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.
--
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]