HyukjinKwon opened a new pull request, #848:
URL: https://github.com/apache/spark-connect-rust/pull/848
### What changes were proposed in this pull request?
From a review of the documented differences of the data types
(`docs/compatibility.md` and `dev/parity/known-differences.md`) against PySpark
4.3.0. Each item was probed on both clients.
**1. Copies and pickles of a type with metadata. This fixes a regression of
#832 (SPARK-61960).**
- A `StructType`, or an `ArrayType` or `MapType` of one, whose fields hold
metadata that JSON does not keep, was copied and pickled through its JSON. Such
metadata is `{'k': (1, 2)}` or `{1: 'a'}`.
- So `copy.copy(s) == s`, `copy.deepcopy(s) == s` and
`pickle.loads(pickle.dumps(s)) == s` were false, where PySpark's are true.
`s.toNullable()` of `{'k': 10**30}` gave `1e+30`.
- Such a type now pickles and copies of the types that it is made of,
`(StructType, ([fields],))`, which the Python workers load as PySpark's. A
struct without metadata still reduces by its JSON.
- `toNullable` of a struct, array or map takes PySpark's `_as_nullable`,
which passes `metadata=field.metadata` (types.py:1601-1611).
- A type of the drop-in's own classes with user attributes in its `__dict__`
pickles and copies as PySpark's: `copyreg.__newobj__` and PySpark's `__dict__`,
byte-identical to PySpark's pickles at protocols 2 and 5. So does one with a
`hasPrecisionInfo` that is not `True`, or a struct whose `names` or
`_needConversion` no longer match its fields.
**2. The extension's warnings are of PySpark's modules and lines.**
- These warnings named the user's file and module:
- `registerTempTable`;
- `replace` and `na.replace` of a dict and a value;
- the type hints of `applyInPandas` and `applyInArrow`, and
`GroupedData.apply`;
- `catalog.registerFunction`, `createExternalTable`, and the deprecated
`dbName` of `functionExists`, `listColumns` and `tableExists`;
- `Column.getItem` and `getField` of a Column;
- `samplingRatio` and `verifySchema` of `createDataFrame`, and `config` of
the builder;
- the conf's `set` and `unset`;
- the listener bus;
- the window of no partition.
- So `filterwarnings("ignore", module="pyspark")` did not silence them.
- They now go through `warnings.warn_explicit` with PySpark 4.3.0's module
and line, and that module's `__warningregistry__`, as `_warn_as` of the ML
shims does for `computeCost`. So the filters of a module and of a line, and the
actions of a location, take them as PySpark's.
- The window warning is now raised from the extension, and its Python helper
in `connect/expressions.py` is removed.
**3. `pyspark.sql.types.DataTypeSingleton`**, PySpark's metaclass of the
singleton types (types.py:238-246), is defined. So PySpark's cloudpickles of a
`__main__` subclass of `LongType` (the class, an instance, a struct of it),
which name it, load as singletons. `test_type_stubs_offline.py` no longer lists
it as a name of the stubs only.
**4. The order of the errors of `repartition`.** `repartition(n, *cols)` and
`repartitionById` build the count last, as PySpark's
`RepartitionByExpression.plan` builds the partition expressions, then the
input, then the count (connect/plan.py:1590-1600). So `df.repartition(2**40,
F.col("a\ud800b"))` raises the `UnicodeEncodeError` of the column, as PySpark
does, not `ValueError: Value out of range`.
**5. `schema`, `columns` and `dtypes` of a plan that fails with an
AttributeError**, as of a join on a tuple, read `__getattr__("_schema")`, as
PySpark's properties do (connect/dataframe.py:365-366, 2040-2050). So they give
the Column of `_schema`, or its `NOT_ITERABLE`, as PySpark does. `__repr__`,
`__dir__`, `_ipython_key_completions_`, `toArrow` and `printSchema` read them
as PySpark's do.
`docs/compatibility.md` and `dev/parity/known-differences.md` describe
these, and the remaining differences, among them:
- the positional counts of PyO3's `__init__` errors, which count without
`self`;
- the constructors' assertions under `python -O`;
- `__slots__` subclasses at protocols 0 and 1;
- user attributes in `==`;
- the source line that a warning does not show.
### Why are the changes needed?
So that copies and pickles of types equal the originals, as in PySpark,
which #832 had broken for metadata that JSON does not keep. So that warning
filters work as with PySpark, PySpark's pickles of singleton subclasses load,
and the errors come in PySpark's order.
### Does this PR introduce _any_ user-facing change?
Yes, as above.
### How was this patch tested?
- **New tests.**
- `test_dropin_types_columns_offline.py`: copies, pickles and `toNullable`
of metadata; types with set attributes, against PySpark's pickle bytes;
PySpark's cloudpickle bytes of a `__main__` singleton subclass.
- `test_dropin_offline.py`: a 19-case warning test of the module, line and
filters; the properties of a plan that fails; the repartition order; `dir` and
key completions; the warning locations of the window, the listener bus and the
handler thread (also `streaming_listener_cases.py`).
- **Probes of both clients:**
- copies and pickles: PySpark loads all 72 of the drop-in's pickles (12
cases × protocols 0-5) as equal;
- warnings, at all call sites;
- the singleton cloudpickles;
- the attribute pickles;
- the repartition order;
- the properties.
- **Python.** The offline suite of `coverage.yml` on pandas 2 and 3. Live
`test_dropin_e2e.py`. The type-stub drift check and test, with mypy and pyright.
- **Rust.** `cargo test -p pyspark-rs --lib`, linked as `rust.yml` links it.
- **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -p pyspark-rs
--all-targets -- -D warnings`, ruff 0.14.0, `audit_no_stubs.sh` and
`scripts/tests`.
### 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]