HyukjinKwon opened a new pull request, #775:
URL: https://github.com/apache/spark-connect-rust/pull/775

   ### What changes were proposed in this pull request?
   
   Follow-ups of #746/#753/#757 (SPARK-61758) and #759 (SPARK-61769), which 
gave the objects of a session PySpark Connect's classes and modules. A review 
of the last 100 commits found the objects they missed. Each row was probed on 
both clients against a Spark 4.3.0 Connect server:
   
   | object | before | PySpark 4.3.0, and after |
   |---|---|---|
   | `spark.dataSource` | a native class that claimed 
`pyspark.sql.datasource.DataSourceRegistration`, while a Python class of that 
name existed too; `isinstance` False against both, and the class did not pickle 
| `pyspark.sql.connect.datasource.DataSourceRegistration`; 
`register(dataSource=...)` takes PySpark's keyword |
   | `pyspark.sql.connect.avro.functions`, `protobuf.functions` | the classic 
functions | their own copies, of the connect modules, as `partitioning`'s since 
#759 |
   | `pickle.dumps(pyspark.sql.connect.functions.random)` | `PicklingError` 
(two copies of one qualname) | pickles: an alias's copy is one function |
   | `F.column`, `F.negate`, `F.power` | separate functions | `col`, 
`negative`, `pow`, as PySpark binds them |
   | `repr(spark.catalog)` | `Catalog()` | 
`<pyspark.sql.connect.catalog.Catalog object at ...>` |
   | the Connect builder's `enableHiveSupport()` | a no-op | 
`PySparkNotImplementedError [NOT_IMPLEMENTED]`; the classic builder still sets 
`spark.sql.catalogImplementation` |
   | `SparkSession.Hook` | qualname `Hook`; neither the class nor a subclass 
instance pickled | `SparkSession.Hook`; takes attributes and weak references, 
and pickles and copies as a plain object |
   | the `SparkSession.builder` descriptor | a native class that claimed 
`pyspark.sql.session.classproperty` | the vendored `classproperty(lambda cls: 
cls.Builder())`, of PySpark's class |
   | `ChannelBuilder`, `DefaultChannelBuilder`, `PlanObservedMetrics` | of 
`pyspark.sql.connect.client` | of `pyspark.sql.connect.client.core` |
   | `pyspark.sql.conf.RuntimeConfig`, `tvf.TableValuedFunction`, 
`merge.MergeIntoWriter`, `observation.Observation` | the Connect classes, so 
`isinstance(spark.conf, RuntimeConfig)` was True | PySpark's classic classes, 
so it is False; `Observation(...)` makes a 
`pyspark.sql.connect.observation.Observation`, as PySpark's `__new__` does |
   | `pyspark.sql.connect.window.Window` | the classic `Window` | a subclass of 
it, as in PySpark |
   | the connect banner | `pyspark-client-rust 4.3.0`, of `pyspark.__version__` 
| the package's version (4.4.0 on master) |
   
   How:
   - **Native classes.** `crates/pyspark-rs/src/datasource.rs`, `catalog.rs`, 
`session.rs`, `window.rs` and `lib.rs` (the qualnames, and the bare C names of 
the native classes outside the module dict too). `reduce.rs` gets 
`plain_object_state`, the state of a plain object as `object.__getstate__` 
gives it, for `Hook`'s reduce.
   - **The builder descriptor.** The native class no longer defines `builder`. 
`pyspark.sql.connect.session` makes the descriptor of the vendored 
`classproperty` and installs it with the native `_install_builder`, so no Rust 
class is patched from Python.
   - **The function aliases.** `functions/_copies.py` memoizes its copies by 
`id()`. `scripts/gen_fn_dispatch.py` emits PySpark's aliases as bindings after 
the generated functions, and `functions_generated.py` is regenerated.
   - **The classic modules.** 
`python/pyspark/sql/{conf,tvf,merge,observation}.py` are vendored from v4.3.0 
as they are, under the drift gate, the ruff excludes and the coverage omits. 
`pyspark.sql.utils` gets PySpark's `to_scala_map`, which `merge.py` imports. 
The connect modules re-export the native classes.
   
   `docs/compatibility.md` describes the classes, the full list of the 
`isinstance` differences that remain, and the protocol-0/1 note for `Hook`. 
`docs/which-client.md` shows the banner of the package version.
   
   ### Why are the changes needed?
   
   So that the objects of a session identify themselves as PySpark Connect's 
do: their classes, modules, reprs, pickles and `isinstance` relations, as #753 
and #759 did for the others. Some were real failures: a pickled `random` 
function and a pickled `Hook` subclass raised, and a `register(dataSource=...)` 
raised `TypeError`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as listed above. Two of them change behavior:
   - the Connect builder's `enableHiveSupport()` raises, as PySpark Connect's;
   - `isinstance` of `spark.conf`, `spark.tvf`, `spark.dataSource` and 
`df.mergeInto(...)` against the classic classes is now False, as in PySpark.
   
   ### How was this patch tested?
   
   - New and updated tests in `test_dropin_class_modules_offline.py` 
(`dataSource` in `EXPECTED`, the classic classes, the connect Window, the 
Catalog repr, the bare names), `test_dropin_classic_session_offline.py` 
(`classproperty`, `enableHiveSupport`, the aliases), `test_dropin_offline.py` 
(the banner, the client classes, `Hook`, the avro/protobuf modules, 
`register(dataSource=...)`), and `scripts/tests/test_gen_fn_dispatch.py`.
   - The reviewer's probes of both clients now show no difference: the data 
source, the aliases, the Hook and the builder. The only remaining difference of 
avro/protobuf is annotations, which is documented.
   - The offline suite of `coverage.yml`, and `test_dropin_e2e.py` against a 
Spark 4.3.0 server (294 passed).
   - `scripts/check_vendored_upstream.sh`, `gen_fn_dispatch.py --check`, `cargo 
fmt --all --check`, `cargo +1.100.0 clippy -p pyspark-rs --all-targets -- -D 
warnings`, ruff 0.14.0, `audit_no_stubs.sh`, `test_ruff_excludes.py` 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]

Reply via email to