HyukjinKwon opened a new pull request, #846:
URL: https://github.com/apache/spark-connect-rust/pull/846
### What changes were proposed in this pull request?
From a review of the Rust API (`spark_connect`) against PySpark 4.3.0's
surface and requests, and of the Rust migration notes of
`docs/compatibility.md`.
**1. `replace` sends strings, as PySpark's `replace` of strings.**
- `DataFrame::replace`, `NaFunctions::replace` and `plan::na_replace` sent a
string that reads as a number ("1", "nan", "inf") as a double.
- So `replace("1", "2")` replaced 1 in the numeric columns and left the
string columns as they were, where PySpark changes the strings. `replace("1",
"one")` and `replace("nan", "x")` failed with `CAST_INVALID_INPUT`.
- They now send both strings as string literals.
- For other values, `replace_literals` (and `NaFunctions::replace_literals`)
now sends an integer or a float as a double, as PySpark's
`_convert_int_to_float` does. Its requests raise `MIXED_TYPE_REPLACEMENT`
unless the values are all booleans, all strings or all numbers
(connect/dataframe.py:1550-1559).
- The Rust migration notes give the change and the typed form.
**2. PySpark's argument checks, raised at each request** (the `unbuildable`
pattern of #831's corr, so no signature changes):
- `repartition` and `coalesce` of a count of 0 or less raise
`VALUE_NOT_POSITIVE` (dataframe.py:401-425), and so does `repartition_by_id`
(dataframe.py:510-517).
- `repartition_by_expressions` raises it for a negative count. A count of
0 still sends no count, as the drop-in's column-only `repartition(*cols)` uses
that.
- `StatFunctions::approx_quantile` raises `NOT_EXPECTED_TYPE` for a
probability outside [0, 1], and `NEGATIVE_VALUE` for a negative relative error,
with Python's `str` of the float (dataframe.py:1721-1747).
- `DataStreamReader::load` of a blank path, and the stream format methods,
raise `VALUE_NOT_NON_EMPTY_STR`, where they sent `[""]`
(streaming/readwriter.py:142-146).
- Blank means of Python's whitespace (Rust's plus U+001C to U+001F), as
PySpark's `strip()`.
- The drop-in's `load` uses the same test, so a path of `"\x1c"` raises at
the call, as in PySpark, where the drop-in sent it.
- `sort`, `order_by` and `sort_within_partitions` of no columns are
unchanged. PySpark's `sort([])` sends the empty sort too, and its
`CANNOT_BE_EMPTY` is only of `sort()` without arguments.
**3. Methods of PySpark's that the core lacked:**
- `DataFrameWriter::jdbc(url, table)`. As PySpark's `jdbc`, it sets `url`
and `dbtable` over the mode and the options of the builder.
- `DataStreamReader::xml`.
- The DataFrame shortcuts of the stat functions: `approx_quantile`, `corr`,
`cov`, `crosstab`, `freq_items` and `sample_by`.
- `NaFunctions::fill_value` and `fill_map`.
- `Column::outer` (the column, as Connect's) and `Column::transform(f)`.
- `DataFrameWriterV2::partition_by` is PySpark's `partitionedBy`, which its
doc now says.
**4. Docs.**
- The Rust migration notes of the 4.3 line are corrected:
- typed interval map keys and the `Value` changes (`Map`, `Struct`,
`TimestampNtz`, `Time`), the new `DataType`, `SparkErrorKind` and `LogicalPlan`
variants;
- the `Pipeline` stages and `PipelineModel`'s private fields;
- `Raw` and `MAX_PLAN_DEPTH`;
- the seed;
- the reason of the errors that the builders raise at each request.
- The notes list the new APIs and errors.
- The zero-row Arrow batches of `create_dataframe_from_arrow` are sent with
their Arrow schema, where PySpark raises `CANNOT_INFER_EMPTY_SCHEMA`.
- `dev/parity/known-differences.md`: the drop-in raises `RecursionError` for
a plan of 747 to about 994 levels, which PySpark sends for the server to fail
with `UNKNOWN`.
### Why are the changes needed?
So that the Rust API sends PySpark's requests and raises its errors, and so
that the migration notes are accurate.
### Does this PR introduce _any_ user-facing change?
Yes, in the Rust API, as the migration notes say:
- `replace` of numeric-looking strings sends strings;
- `replace_literals` sends numbers as doubles, with PySpark's check;
- the argument checks above;
- the new methods.
The drop-in changes only for a stream path of Python whitespace, which now
raises at the call, as PySpark's does.
### How was this patch tested?
- **New unit tests** in `dataframe.rs`, `group.rs` and `column.rs`.
- **New goldens of the official client:** two jdbc writes in
`tests/golden/readwriter.jsonl`, whose capture now records the request with a
session hook; and the stream `xml` cases in `streaming_golden.rs`.
- **Tests of the heuristic moved:** `plans_golden.rs`,
`plan_arg_regression_golden.rs` and `e2e_new_methods.rs` now use the typed
form, or expect strings.
- **Live:** `e2e_new_methods` (with the stat shortcuts), `e2e_coverage`,
`e2e_ops_breadth`, `e2e_streaming`, `e2e_dataframe`, `e2e_integration` and
`e2e_statistics`, against a Spark 4.3.0 server.
- **Probes of both clients:** the checks, the `approxQuantile` errors, the
stream blank paths and the Column reprs are identical. The drop-in's replace
requests are identical to master's and to PySpark's in 9 cases.
- **Rust.** `cargo test -p apache-spark-connect -p apache-spark-connect-core
--release`, and `--features wasm-udf`.
- **Python.** The offline suite of `coverage.yml`, and the drop-in's tests
of repartition, sort, coalesce, approxQuantile, replace, the stream reader,
fillna and stat on pandas 2 and 3.
- **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -p
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`, ruff 0.14.0,
`audit_no_stubs.sh`, `scripts/tests` and `RUSTDOCFLAGS="-D warnings" cargo doc
--no-deps`.
### 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]