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

   ### What changes were proposed in this pull request?
   
   [SPARK-61340](https://issues.apache.org/jira/browse/SPARK-61340): a datetime 
literal of the Python client is a TIMESTAMP_NTZ when the session prefers it, as 
PySpark's is.
   
   - In `crates/pyspark-rs/src/functions.rs`, `scalar_literal` reads 
`pyspark.sql.utils.is_timestamp_ntz_preferred()` for each datetime literal, as 
PySpark's `LiteralExpression._infer_type` does.
   - When it is true, the literal is a TIMESTAMP_NTZ of the wall clock: 
`calendar.timegm` of the time tuple, as `TimestampNTZType.toInternal` takes it, 
also for an aware datetime. Otherwise it is a TIMESTAMP of the instant, as 
before.
   - This covers every literal path: `lit`, Column comparisons, `isin`, `when`, 
the elements of `lit([...])`, and SQL args.
   
   ### Why are the changes needed?
   
   Under `spark.sql.timestampType=TIMESTAMP_NTZ`, every datetime literal was a 
TIMESTAMP of its instant. With a client zone other than the session's (here a 
client in Asia/Seoul and a UTC session):
   - `df.filter(col("t") == datetime(2020, 6, 1, 12))` on a TIMESTAMP_NTZ 
column matched 0 rows; PySpark matches 1. `isin` behaved the same.
   - `spark.sql("SELECT CAST(:t AS STRING)", args={"t": datetime(2020, 6, 1, 
12)})` gave `2020-06-01 03:00:00`; PySpark gives `12:00:00`.
   - `when(...)` and `lit([...])` were `timestamp` and `array<timestamp>`; 
PySpark gives `timestamp_ntz` and `array<timestamp_ntz>`.
   
   The drop-in's own `createDataFrame` already followed the conf.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in the Python client: under `spark.sql.timestampType=TIMESTAMP_NTZ`, 
datetime literals are TIMESTAMP_NTZ values of their wall clock, as in PySpark. 
As in PySpark, a datetime literal reads the conf of the active session.
   
   ### How was this patch tested?
   
   - Offline (`python/tests/test_dropin_offline.py`): 
`test_datetime_literals_follow_the_preferred_timestamp_type_as_pyspark`. Naive 
and aware datetimes give TIMESTAMP_NTZ literals of their wall clock under the 
conf, and TIMESTAMP literals of the instant without it. It fails without the 
change.
   - Live (`python/tests/test_dropin_e2e.py`): 
`test_datetime_literals_follow_the_preferred_timestamp_type_as_pyspark`.
     - Under the conf and a client in Asia/Seoul: a filter, `isin`, SQL args, 
`when` and `lit([...])` give PySpark's results.
     - Once the conf is unset, the literal is a TIMESTAMP again.
     - It fails without the change.
   - The reviewer's probes against official PySpark 4.3.0 (TZ=Asia/Seoul, UTC 
session) now match: no differing line, from 8 before.
   - Checks:
     - the lib tests (716 passed);
     - the build of all tests (also `wasm-udf`, `datafusion,polars`) without 
warnings;
     - `cargo fmt --all --check`, and clippy with no diagnostics on the changed 
lines;
     - the offline Python suites (2980 passed, 8 skipped);
     - the live drop-in, Arrow and ML suites against a local Spark 4.3.0 server 
(255 passed).
   
   ### 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