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

   ### What changes were proposed in this pull request?
   
   A follow-up of #780 (SPARK-61859), which made the base data type classes 
instantiable. Wherever a plan converts a type, PySpark's 
`pyspark_types_to_proto_types` refuses a type that it has no proto of: a type 
of its class only, such as `AtomicType()`, or a `StructField` given as a type. 
Its error is `UNSUPPORTED_OPERATION`, also when the type is nested in another. 
Four paths of the drop-in sent such a type to the server instead, as a 
`DataType.Unparsed` of its JSON, which the server rejects with 
`CONNECT_INVALID_PLAN.DATA_TYPE_UNSUPPORTED_PROTO_TO_CATALYST`. They now 
convert the type as PySpark does, at the same time PySpark raises the error:
   
   - **The return type of a UDTF call**, `udtf(...)(...)`, raises the error at 
each request of the DataFrame, such as `df.schema`.
     - The error is recorded in the plan's arguments, as the type of a `cast` 
is.
     - The errors of the UDTF's arguments still come first, as in PySpark's 
`PythonUDTF.to_plan`.
   - **The return type of `spark.udtf.register`** raises at the call.
   - **The return type of `spark.udf.registerJavaFunction`** raises at the 
call, whether the type is at the top level or nested.
   - **The schema of `Catalog.createTable` and `createExternalTable`** raises 
at the call. As in PySpark's `CreateTable` plan:
     - it comes after the errors of the name, the path and the description;
     - it comes before the errors of the options.
   
   Before, on master:
   - for an abstract type, these four paths raised the server's 
`InvalidPlanInput`, or `PARSE_SYNTAX_ERROR '"atomic"'` for a top-level Java UDF 
type;
   - for a nested `DataType()`, the drop-in sent `void`, and `createTable` 
created a table with a void column.
   
   **`createDataFrame` reads a schema that is a type object by its class**, as 
PySpark's `isinstance(schema, (AtomicType, StructType))` does:
   - `DataType()`, and a Python subclass of it that is not an `AtomicType`, 
raise `NOT_EXPECTED_TYPE` named by their class, for every kind of data. Before, 
the error named `UnparsedDataType`, and `NullType` before SPARK-61859.
   - An abstract `AtomicType` subclass, such as `AtomicType()` or 
`IntegralType()`, is accepted as the type of the single column, as in PySpark. 
Then:
     - local rows raise `UNSUPPORTED_DATA_TYPE_FOR_ARROW_CONVERSION`;
     - a pandas DataFrame raises `UNSUPPORTED_DATA_TYPE_FOR_ARROW`;
     - data of no rows, a NumPy array and a pyarrow Table make a local relation 
of no data whose schema is the type's own `json()`, `'"atomic"'`. The server 
fails to parse it with PySpark's `PARSE_SYNTAX_ERROR`.
   - Before, all of these raised `NOT_EXPECTED_TYPE`, or sent the JSON of the 
core's unparsed type.
   - Rows of no length, such as those of an iterator, are now checked as a 
list's are. PySpark's conversion takes them apart first and then checks the 
schema:
     - a type of no proto nested in the schema, also a `StructField` given as a 
type, raises `UNSUPPORTED_DATA_TYPE_FOR_ARROW_CONVERSION`;
     - a nullable flag that is not a bool raises the `AssertionError` of its 
converter.
   
     Before, the drop-in checked neither for an iterator. It raised `TypeError: 
unsupported value type for createDataFrame`, or created the DataFrame.
   
   **Docs**: `docs/compatibility.md` now says the following. Its paragraph of 
the abstract types conflicts with SPARK-61917, which rewrites the sentence 
about nesting; the one that lands second keeps SPARK-61917's sentence.
   - where these refusals are raised and when;
   - that a struct, array or map compares and names an abstract type that it 
holds by its JSON, which SPARK-61917 changes;
   - that a copy, a deep copy or a pickle of a singleton type, `IntegralType()` 
among them, is the one instance, where PySpark makes another object of the 
class.
   
   ### Why are the changes needed?
   
   So that these types fail in the drop-in with PySpark's errors, at the same 
point as in PySpark. Before, the drop-in either sent a plan that the server 
rejects with another error or, for a nested `DataType()`, ran a wrong plan. It 
also fixes the two sentences of `docs/compatibility.md` that claimed more than 
the drop-in did.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, the errors above, which are now PySpark 4.3.0's. `createDataFrame` with 
a top-level abstract `AtomicType` subclass is accepted where it was refused, as 
in PySpark.
   
   ### How was this patch tested?
   
   - Each behavior above was compared on official pyspark-client 4.3.0 and on 
the drop-in, against a Spark 4.3.0 server:
     - `createDataFrame` of 17 schemas, from `AtomicType()` and `DataType()` to 
`'void'`, `VectorUDT()` and `IntegerType()`, over 10 kinds of data, and of 
iterators;
     - the UDTF, `registerJavaFunction` and `createTable` paths, with their 
error orders.
   
     All match, apart from a difference that this change does not touch: the 
parameters of `MALFORMED_VARIANT`, which are `{}` on the drop-in and `None` on 
official.
   - New tests in `python/tests/test_dropin_types_columns_offline.py`, offline 
with `mock_connect_session`, pin official's errors as literals and check that 
no request is sent. The file has 118 passed, and its 11 new tests fail on 
master.
   - New live tests in `python/tests/test_dropin_e2e.py` cover the server's 
`PARSE_SYNTAX_ERROR` of the abstract type's JSON and the table that 
`createTable` no longer creates. They pass on the drop-in and on official 
pyspark-client 4.3.0.
   - On master 99e3a819: the offline suite of `coverage.yml` has 6180 passed 
and 76 skipped. `test_dropin_e2e.py` has 305 passed.
   - `cargo test -p pyspark-rs --lib` (12 passed), `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