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

   ### What changes were proposed in this pull request?
   
   A follow-up of #780 (SPARK-61859).
   
   A struct, an array, a map or a field keeps the type objects it was made of 
(`KeptType`, `StructField.dataType`). The core holds the types that the client 
keeps as Python objects only by their JSON:
   - user-defined types;
   - `StructField`s given as types;
   - types of their class only, such as `AtomicType()`.
   
   The drop-in compared and named such types through that JSON, and a 
process-wide registry gave back, for each JSON, the object last lowered with 
it. So two types of the same JSON were one to the container that held them:
   - of one class with different `__dict__`s, such as two `AtomicType()`s with 
different attributes;
   - of two classes of one name, so of one `typeName`;
   - a `UserDefinedType` with other parameters, which its JSON does not hold.
   
   As PySpark compares the `__dict__`s and calls the methods of the objects 
that a type holds, the containers now go through those objects:
   - **Equality**: `ArrayType`, `MapType`, `StructField` and `StructType` first 
compare their core types as before. Then they compare, with `==`, the objects 
at each place whose type holds such a type. So `ArrayType(ScaleUDT(2)) != 
ArrayType(ScaleUDT(10))`, and a struct of `t1` is not equal to one of `t2`, a 
`t2` of another `__dict__`. Hashes are unchanged: they are of the repr, as 
PySpark's.
   - **`simpleString()`**: a struct, array, map or field names each type it 
holds by that object's own `simpleString()`:
     - `struct<a:x1,b:x2>` where it was `struct<a:x2,b:x2>`;
     - `struct<a:scale2,b:scale10>` of the UDTs above;
     - `array<unparsed('int')>` of an `UnparsedDataType`, as PySpark's.
   - **The tree string**: a type of its class only is named by the `typeName()` 
of the object at its path. This uses the paths of the types, which the core's 
hidden `tree_string_with_names` now passes to its name function.
   - **`toNullable()`**: of a type that holds such a type, it is made of the 
objects, as PySpark's `_as_nullable` makes it. The UDTs and the types of their 
class only stay the same objects.
   
   A type that is not kept as an object is still made from its core type and 
the registry, as before. That is the case of one made of core types, such as 
`StructType.fromJson` of a user-defined type.
   
   `docs/compatibility.md` says so. This conflicts with the sentence that 
SPARK-61916 adds there, which describes the behavior before this change: keep 
this one.
   
   ### Why are the changes needed?
   
   So that the data types that a struct, an array or a map holds stay distinct 
as in PySpark. Before, two such structs were equal where PySpark's are not. A 
struct also named one type by another's `simpleString`, and its `toNullable()` 
swapped in another type object of the same JSON: of a `UserDefinedType` of 
parameters, another instance with other parameters.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as above, as PySpark 4.3.0 behaves. Before this change, on the drop-in:
   - `StructType([StructField("a", ScaleUDT(2)), StructField("b", 
ScaleUDT(10))])` was equal to the struct with the two swapped;
   - its `simpleString()` was `struct<a:scale10,b:scale10>`;
   - its `toNullable()` had scales `[10, 10]`.
   
   ### How was this patch tested?
   
   - Probes compared official pyspark-client 4.3.0 with the drop-in, and they 
now match:
     - equality, `simpleString`, the tree string, `toNullable`, `copy` and the 
conversions;
     - for types of the same JSON in arrays, maps, fields and structs: tagged 
`AtomicType()`s, two classes of one name, two classes of one JSON and different 
`typeName`s, and a UDT of a parameter.
   - The probes of the other types are unchanged from master:
     - the object model of 49 types, with their equality matrix and their 
pickles at every protocol;
     - JSON parsing, and a live run of createDataFrame, casts, UDFs and `df.to` 
of 25 types and 4 UDTs.
   - There are two new tests in 
`python/tests/test_dropin_types_columns_offline.py`. They fail on master and 
pass on official pyspark-client 4.3.0 as well. The file has 109 passed.
   - Other tests:
     - on master 99e3a819, the offline suite of `coverage.yml`: 6171 passed, 76 
skipped;
     - `test_dropin_e2e.py`: 303 passed;
     - `cargo test -p apache-spark-connect --release --lib`, 772 passed, 
including its tree-string test, which now checks the paths;
     - `--test types_roundtrip`, 26 passed;
     - `cargo test -p pyspark-rs --lib`: 12 passed;
     - `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p apache-spark-connect` 
has no warning from this change. Its only errors are the three links of 
`merge.rs` to the private `assignment_pairs`, which master has since 
SPARK-61911.
   - `cargo fmt --all --check`, `cargo +1.100.0 clippy -p pyspark-rs -p 
apache-spark-connect --all-targets -- -D warnings`, ruff 0.14.0 `check` and 
`format --check`, and `scripts/audit_no_stubs.sh` all pass.
   
   ### 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