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

   ### What changes were proposed in this pull request?
   
   [SPARK-61176](https://issues.apache.org/jira/browse/SPARK-61176): Spark 
renders a negative year-month interval with the sign on the years, and the 
absolute value of the months: `-1` month is `-0-1`, `-12` months is `-1-0`, and 
`-13` months is `-1-1`. The Spark source is 
`SparkIntervalUtils.toYearMonthIntervalString`.
   
   The Rust client now takes the sign from the total number of months and 
formats the absolute years and months. The old code took the years and the 
months with truncating `/` and `%`, so the sign of an interval shorter than a 
year was lost.
   
   The Rust client has one such formatter, the `IntervalYearMonth` arm of 
`ArrowValueDecoder` in `crates/spark-connect/src/dataframe.rs`. The Python 
drop-in does not reach it, because it rejects collecting a year-month interval 
with `NOT_IMPLEMENTED`.
   
   ### Why are the changes needed?
   
   Collected values of negative year-month intervals had the wrong sign when 
the interval was shorter than a year. With the old code, the Rust client gave:
   
   ```
   months = -1   -> "0-1"    (expected "-0-1")
   months = -11  -> "0-11"   (expected "-0-11")
   months = -12  -> "-1-0"   (correct before and after the change)
   months = -13  -> "-1-1"   (correct before and after the change)
   ```
   
   The output for `-1` and `-11` is the output for `+1` and `+11`, so a user 
could not tell the two intervals apart.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. The Rust client's collected string value of a negative year-month 
interval of less than a year now has the sign, for example `-0-1` where it used 
to give `0-1`. Values of one year or more and non-negative values are unchanged.
   
   ### How was this patch tested?
   
   - `year_month_interval_keeps_sign` in 
`crates/spark-connect/src/dataframe.rs` checks the rendering of 0, 1, -1, 11, 
-11, 12, -12, 13, -13, 24, -24, `i32::MAX` and `i32::MIN` months. It fails 
without this change (`months = -1`: left `"0-1"`, right `"-0-1"`), and passes 
with it. `i32::MIN` renders as `-178956970-8`, so the absolute value is taken 
in `i64`.
   - `interval_types_render_as_string` is unchanged and passes.
   - Official PySpark 4.3.0 does not give a value to compare against for the 
collected form. Its Connect `collect()` raises 
`UNSUPPORTED_DATA_TYPE_FOR_ARROW_CONVERSION` for `month_interval`, and `show()` 
and `CAST(... AS STRING)` print the SQL literal form (`INTERVAL '-1' MONTH`). 
So the `-0-1` form is taken from the Spark source, not from a server output.
   - The lib tests of both crates (600 passed), the build of all tests, also 
with `wasm-udf`, the offline Python suites (2227 passed, 8 skipped), and the 
live drop-in and Arrow suites (209 passed) and live cases (10 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