Latest Results
feat(temporal): add Spark-style temporal aliases (#6830)
## Summary
Implements eight Spark-style temporal aliases (#3798) as thin wrappers
over Daft's existing canonical temporal functions, so users migrating
from Spark can use the names they already know without learning Daft's
naming.
This PR adds Python and SQL aliases for `dayofmonth`, `dayofyear`,
`weekofyear`, `date_format`, `trunc`, `dateadd`, `datediff`, and
`datepart`. Every alias is a pure delegation to an already-tested Daft
function — no new logic except `trunc`'s interval normalization and
`datepart`'s dispatch table.
## Why
The issue asks for Spark-name parity. This PR focuses on three practical
pieces:
- The camelCase / no-underscore Spark variants of existing extractors
(`dayofmonth`, `dayofyear`, `weekofyear`, `dateadd`, `datediff`).
- `date_format` as a Spark alias for `strftime`.
- Two functions with Spark-specific behavior: `trunc(date, format)`
(argument order opposite to `date_trunc`) and `datepart(part, expr)`
(dispatches to the right extractor based on the `part` literal).
## Changes Made
- Add eight Python alias functions in `daft/functions/datetime.py`:
- `dayofmonth`, `dayofyear`, `weekofyear` → delegate to `day_of_month`,
`day_of_year`, `week_of_year`.
- `date_format` → delegates to `strftime`.
- `trunc(input, interval)` → normalizes bare unit strings (`"day"` → `"1
day"`) then delegates to `date_trunc(interval, input)` with arguments
swapped to match Spark.
- `dateadd`, `datediff` → delegate to `date_add`, `date_diff`.
- `datepart(part, expr)` → dispatches to the appropriate extractor
(`year`, `month`, `day`, etc.) based on the `part` string literal.
- Export all eight names from `daft/functions/__init__.py`
(alphabetical, both in the import block and `__all__`).
- Add SQL handlers in `src/daft-sql/src/modules/temporal.rs`:
- Direct `ScalarUDF` registrations for `dayofmonth`, `dayofyear`,
`weekofyear`, `date_format`.
- `SQLTrunc` handler for Spark-style `trunc(input, interval)` argument
order with interval normalization.
- `SQLDatePart` handler with the part-string dispatch.
- `dateadd` and `datediff` reuse the existing `SQLDateAdd` /
`SQLDateDiff` handlers.
- Re-export `ToString` from `src/daft-functions-temporal/src/lib.rs` so
the SQL layer can wire `date_format` to it.
- Add regression coverage:
- `tests/dataframe/test_temporals.py::test_temporal_alias_functions` —
every alias compared against its canonical counterpart on a leap-day
timestamp.
- `tests/sql/test_temporal_exprs.py::test_temporal_sql_aliases` — same
on the SQL side.
## Behavior
- All eight aliases produce identical output to their canonical Daft
counterparts.
- `trunc(ts, 'month')` works as a Spark user expects — `(input,
interval)` order — and is functionally equivalent to `date_trunc('1
month', ts)`.
- `datepart('year', ts)` returns the year as `Int32`; other parts
(`month`, `day`, `hour`, `minute`, `second`, `quarter`, `week`,
`dayofweek`, `dayofyear`) return the same dtypes as the underlying
extractors.
- Invalid `datepart` parts raise a clear `ValueError`.
## Test Plan
- `cargo check -p daft-functions-temporal -p daft-sql`
- `make build`
- `DAFT_RUNNER=native pytest -q
tests/dataframe/test_temporals.py::test_temporal_alias_functions
tests/sql/test_temporal_exprs.py::test_temporal_sql_aliases`
## Related Issues
- Part of #3798 Latest Branches
-2%
QuakeWang:fix/paimon-column-order -12%
BABTUNA:perf/packed-symbol-groupby -1%
BABTUNA:feat/show-preview-defaults © 2026 CodSpeed Technology