apache / apache/datafusion-comet

Implement TimeType support - Time extraction (from TimeType to Int/Decimal)

Open
#4,983 1 comment 0 reactions 1 assignee Claimed by @YutaLin View on GitHub
area:expressions enhancement
Dominant language
Scala
Stars
1.3k
Forks
373
Avg merge
2d 6h
Merged PRs (30d)
190

Description

### What is the problem the feature request solves?

What is the problem the feature request solves?
This is https://github.com/apache/datafusion-comet/issues/4288 sub-issue

These are the dedicated TimeType expressions from timeExpressions.scala. All are
RuntimeReplaceable and resolve to StaticInvoke(DateTimeUtils, methodName, ...).
They follow the same shim pattern as make_time.

### Describe the potential solution

time extraction (from TimeType to Int/Decimal)

| SQL | Spark expression | StaticInvoke method | Return type |
|---|---|---|---|
| `extract(HOUR FROM t)` | `HoursOfTime` | `getHoursOfTime` | IntegerType |
| `extract(MINUTE FROM t)` | `MinutesOfTime` | `getMinutesOfTime` | IntegerType |
| `extract(SECOND FROM t)` | `SecondsOfTime` | `getSecondsOfTime` | IntegerType |
| `extract(SECOND FROM t)` (with fraction) | `SecondsOfTimeWithFraction` | `getSecondsOfTimeWithFraction` | DecimalType |

**Shim pattern**: Match `StaticInvoke` where `staticObject == classOf[DateTimeUtils.type]`
and `functionName` is one of the above.

**Rust implementation**: Simple arithmetic on nanoseconds since midnight:
- hours = nanos / NANOS_PER_HOUR
- minutes = (nanos % NANOS_PER_HOUR) / NANOS_PER_MINUTE
- seconds = (nanos % NANOS_PER_MINUTE) / NANOS_PER_SECOND

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.