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

   ### What changes were proposed in this pull request?
   
   [SPARK-61317](https://issues.apache.org/jira/browse/SPARK-61317): Raise for 
nanosecond timestamps on every schema surface, as PySpark does.
   
   PySpark 4.3.0 cannot convert a nanosecond-precision timestamp 
(`TIMESTAMP_NTZ(p)` or `TIMESTAMP_LTZ(p)` with p > 6) from the proto of a 
schema, so every schema surface raises `PySparkValueError` with 
`UNSUPPORTED_OPERATION` (`data type timestamp_ntz_nanos {precision: 9} is not 
supported.`). The collecting APIs already raised it (SPARK-61249). This change 
raises the same error from:
   
   - the schema of a DataFrame (`df.schema`, and `df.schema.json()`), 
`df.columns`, `df.dtypes`, `df.printSchema()` and `repr(df)`;
   - a DDL string of a schema: `DataType.fromDDL`, `StructType.fromDDL`, 
`createDataFrame(data, "a timestamp_ntz(9)")`, the return type of a UDF, and 
the schema of `from_json` with such a DDL string (its result schema raises at 
the schema surface, as in PySpark);
   - `StructType.add("t", "timestamp_ntz(9)")`, which raises 
`CANNOT_PARSE_DATATYPE` as PySpark does, since a name of a type takes only the 
JSON names of PySpark's types.
   
   The check runs on the schema from the server, before the Python types are 
built, so the Rust types and the picklable nanosecond classes are unchanged. 
`count`, `show`, `describe` and `isEmpty` keep working, as in PySpark.
   
   ### Why are the changes needed?
   
   A user could still read the schema of such a frame: `spark.sql("SELECT 
CAST('2020-01-01 00:00:00.123456789' AS TIMESTAMP_NTZ(9)) c").schema` returned 
`struct<c:timestamp_ntz(7)>`, and `spark.createDataFrame([(1,)], "a 
timestamp_ntz(9)")` raised a bare `AssertionError`. Official PySpark raises 
`UNSUPPORTED_OPERATION` for each of these.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. The schema surfaces listed above raise `PySparkValueError` 
(`UNSUPPORTED_OPERATION`, or `CANNOT_PARSE_DATATYPE` for `StructType.add`) for 
nanosecond timestamps, as PySpark does, instead of returning a schema or 
failing with an `AssertionError`.
   
   ### How was this patch tested?
   
   - `test_nanosecond_timestamps_are_not_collected_as_pyspark` (offline, 
`test_dropin_offline.py`, extended with the schema surfaces, the DDL strings 
and `StructType.add`; the mock returns the schema of the type) and the live 
test of the same name (`test_dropin_e2e.py`, extended the same way, the 
`spark.sql.timestampNanosTypes.enabled` conf set and unset as before).
   - Checked against official PySpark 4.3.0 on the same server: for 
`TIMESTAMP_NTZ(9)` and `TIMESTAMP_LTZ(7)` results, `schema`, `columns`, 
`dtypes`, `printSchema`, `repr`, `schema.json()`, `createDataFrame` with a DDL 
schema, `DataType.fromDDL`, `StructType.fromDDL` (a struct field too), 
`from_json` with a DDL schema, `udf` with a DDL return type and 
`StructType.add` raise the same error class, condition and message parameters. 
`count`, `show`, `describe` and `isEmpty` give the same results.
   - The offline test fails without this change (the schema surfaces return the 
schema) and passes with it.
   - The build of all tests, the offline Python suites (2927 passed, 8 skipped) 
with the rebuilt extension, the extended tests also under pytest 9.2, and the 
live drop-in tests `-k "timestamp or ntz or lit"` (10 passed) against a local 
Spark 4.3.0 server. Clippy reports no new 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