dongjoon-hyun opened a new pull request, #523:
URL: https://github.com/apache/spark-connect-swift/pull/523
### What changes were proposed in this pull request?
This PR aims to support 10 interval and timestamp constructor functions in
`DateTimeFunctions`.
Interval constructors (`3.5.0`):
- `make_interval`, `make_dt_interval`, `make_ym_interval`
Timestamp constructors (`3.5.0`):
- `make_timestamp`, `make_timestamp_ltz`, `make_timestamp_ntz`
`try_*` variants that return `NULL` instead of raising an error (`4.0.0`):
- `try_make_interval`, `try_make_timestamp`, `try_make_timestamp_ltz`,
`try_make_timestamp_ntz`
**On optional arguments.** The interval constructors have *only* optional
fields
(7 for `make_interval`, 4 for `make_dt_interval`, 2 for `make_ym_interval`),
so
they are declared with Swift default argument values instead of arity
overloads:
```swift
public func make_interval(
years: Column = lit(0), months: Column = lit(0), weeks: Column = lit(0),
days: Column = lit(0), hours: Column = lit(0), mins: Column = lit(0),
secs: Column = lit(0)
) -> Column
```
Modeling these as Scala-style prefix overloads would need 8 declarations for
`make_interval` alone (16 with `try_make_interval`) and still could not
express a
call that sets only `hours`. For that reason, and unlike the rest of this
codebase, the interval constructors keep their argument labels: without
labels,
default values could only be dropped from the tail, which defeats the
purpose.
The labels also match how these functions are called in PySpark
(`make_interval(hours=...)`).
Following the PySpark implementation, omitted fields are filled with a zero
literal, so the full argument list is always sent to the server, e.g.
`make_interval(hours: col("h"))` sends `make_interval(0, 0, 0, 0, h, 0, 0)`.
PySpark uses `lit(decimal.Decimal(0))` for `secs`; a `long` zero is
implicitly
coerced to `DECIMAL(18,6)` by the server, so no new `lit` overload is
required.
The timestamp constructors take six required fields, so they follow the
existing
convention of unlabeled arguments used by `make_date` and `make_time`. Their
optional `timezone` field is expressed as an overload pair, matching the
existing
`to_timestamp_ltz`/`to_timestamp_ntz` precedent.
### Why are the changes needed?
For feature parity with Apache Spark's Scala and Python clients. These are
the
only remaining `make_*` datetime constructors missing from this client;
`make_date` and `make_time` are already supported.
### Does this PR introduce _any_ user-facing change?
No, this only adds new functions.
### How was this patch tested?
Pass the CIs with newly added test cases in `DateTimeFunctionsTests`
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5
--
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]