Skip to content

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

Description

@YutaLin

What is the problem the feature request solves?

What is the problem the feature request solves?
This is #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

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions