talz-a opened a new pull request, #7832:
URL: https://github.com/apache/datafusion-comet/pull/7832
## Which issue does this PR close?
Closes #6193.
## Rationale for this change
As the issues states, Spark lowers `extract(field FROM interval)` and
`date_part('field', interval)` to one of twelve `ExtractIntervalPart`
subclasses, and since none of them have a serde, a projection that uses one
falls back to Spark.
We want these twelve expressions to run through the the JVM codegen
dispatcher instead.
This also keeps `date +/- DAY interval` in Comet. Spark rewrites it to
`DateAdd(date, ExtractANSIIntervalDays(interval))`, and `DateAdd` is already
native, so the extractor was the only reason those projections fell back.
## What changes are included in this PR?
- Register the twelve `ExtractANSIInterval*` and `ExtractInterval*`
expressions as `CometCodegenDispatch` serdes in `datetime.scala` and
`QueryPlanSerde.temporalExpressions`. Each one is a single
`IntervalUtils.getX(child)` call, and the classes and result types are the same
on every supported Spark version, so no shim is needed.
- Add a note to the `extract`, `date_part` and `datepart` rows in
`expressions.md`.
## How are these changes tested?
A new SQL file test, `expressions/datetime/extract_interval.sql`, checks
every extractor with `expect_dispatch(...)`, using both `extract` and
`date_part`, over Parquet data with negative, NULL and out-of-range values. It
covers:
- year-month, day-time and calendar intervals built from columns
- literal interval input
- boundary values
- narrower ANSI types such as `INTERVAL MONTH` and `INTERVAL HOUR TO SECOND`
- `date +/- CAST(n AS INTERVAL DAY)` and `date +/- INTERVAL '30' DAY` for
the `DateAdd` rewrite
`date +/- (d1 - d2)` from the issue is not tested, because `d1 - d2` needs
#5864 (`SubtractDates`). The same `DateAdd(ExtractANSIIntervalDays)` path is
covered by casting an int column to `INTERVAL DAY`.
#5864 also adds `+` / `-` notes to `expressions.md` saying a DAY interval
column falls back because `ExtractANSIIntervalDays` has no serde. Whichever of
the two PRs merges second should drop that sentence and add the `d1 - d2` case.
--
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]