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

   ### What changes were proposed in this pull request?
   
   [SPARK-61226](https://issues.apache.org/jira/browse/SPARK-61226): Make 
`StructField.fromDDL` return the parsed type, as `DataType.fromDDL` does in 
PySpark.
   
   - `StructField.fromDDL` was a fork override that returned a `StructField`, 
split at the first whitespace. It now parses the DDL string with the same 
function as `DataType.fromDDL`, so it returns the same type and raises the same 
errors. For example, `StructField.fromDDL("a int")` is 
`StructType([StructField("a", IntegerType())])`, and 
`StructField.fromDDL("int")` is `IntegerType()`.
   - Two existing tests that asserted the old `StructField` result now assert 
the `StructType` result of PySpark.
   
   ### Why are the changes needed?
   
   With the override, `StructField.fromDDL("`x y` int")` gave the name "`x" 
with the type `struct<y`:int>`, and `StructField.fromDDL("a int not null")` 
raised `ValueError`. A `StructField` cannot be used as a schema, so 
`spark.createDataFrame([(1,)], StructField.fromDDL("a int"))` raised 
`PySparkTypeError [NOT_EXPECTED_TYPE]`. PySpark returns 
`StructType([StructField('a', IntegerType(), True)])` and the DataFrame 
`[Row(a=1)]`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `StructField.fromDDL` returns the parsed type, as PySpark does, instead 
of a `StructField`.
   
   ### How was this patch tested?
   
   - `test_struct_field_from_ddl_is_data_type_from_ddl_as_pyspark` (offline): 
the results of `StructField.fromDDL` for the "a int", "`x y` int", "a int not 
null", "int" and nested struct DDL strings.
   - `test_struct_field_from_ddl_parses_as_data_type_from_ddl_as_pyspark` 
(live): `StructField.fromDDL` equals `DataType.fromDDL` for several DDL 
strings, a parse error gives the same error condition for "a INT," and "a 
BOGUS", and the `StructType` creates `[Row(a=1)]`. The same results come from 
official PySpark 4.3.0.
   - The existing assertions of `StructField.fromDDL` in 
`test_udf_udtf_determinism_and_extras` and `test_datatype_from_ddl_parsing` now 
assert the `StructType` result. `test_datatype_from_ddl_parsing` now takes the 
`mock_connect` fixture, as DDL parsing needs the session.
   - The lib tests of both crates (658 passed), the build of all tests, also 
with `wasm-udf`, the offline Python suites (2808 passed, 8 skipped), and the 
live drop-in and Arrow suites (225 passed) and live cases (12 passed) against a 
local Spark 4.3.0 server. Clippy reports no diagnostics in the changed lines.
   
   ### 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