Skip to content

Conversation

@kumarUjjawal
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

Previously we needed to create timestamp and then extract the time component from that.

What changes are included in this PR?

  • Added the function for to_time
  • Relevant slt test
  • Relevant unit tests
  • Updated docs

Are these changes tested?

  • All tests pass

Are there any user-facing changes?

@github-actions github-actions bot added documentation Improvements or additions to documentation sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Dec 29, 2025
@Omega359
Copy link
Contributor

Thank you for this PR. I would like to see some additional slt tests

  • negative times
  • out of range hours, seconds
  • HH:MM default parsing

Support timestamp as input, extract time from it.

@kumarUjjawal
Copy link
Contributor Author

Thank you for this PR. I would like to see some additional slt tests

  • negative times
  • out of range hours, seconds
  • HH:MM default parsing

Support timestamp as input, extract time from it.

Sure, I will add those. Thanks for feedback.

- Extract magic numbers to NANOS_PER_SECOND, NANOS_PER_MINUTE, NANOS_PER_HOUR constants
- Use Arrow's NANOSECONDS constant as base
- Add timestamp input support (extracts time portion)
- Add SLT tests for:
  - HH:MM default parsing (no seconds)
  - Out of range minutes/seconds
  - Timestamp input (various timestamp types)
  - Null timestamp handling
Comment on lines 3456 to 3467
query D
select to_time(to_timestamp('2024-01-15T14:30:45-05:00'));
----
19:30:45

# Timezone test using timestamp value directly
# The timestamp is converted from -05:00 to UTC, so 14:30:45-05:00 = 19:30:45 UTC

query D
select to_time('2024-03-20 09:15:30'::timestamp AT TIME ZONE 'America/Los_Angeles');
----
09:15:30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look a little odd to me; so if we specify a timestamp with an offset like -05:00 then it returns the UTC time, but if we use AT TIME ZONE it returns the local time for America/Los_Angeles? Am I missing something here, or is it inconsistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should return time as is without AT TIME ZONE.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I can't understand what the reply means here in relation to my question

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I should have explained was that yes the behavior appears inconsistent bu the inconsistency comes from how DataFusion creates timestamps, not from the new to_time itself.

image
  • to_timestamp() with offset parses and converts to UTC → stores 19:30:45
  • ::timestamp AT TIME ZONE creates a naive timestamp first, then just labels it → stores 09:15:30-07:00(same time value, different metadata)

to_time behaves consistently, it extracts whatever time value it receives. The different results come from the timestamp creation step.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. Could we retain the test that had a timestamp with timezone then, for coverage? Since to_timestamp('2024-01-15T14:30:45-05:00') doesn't actually have a timezone

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Jefffrey Jefffrey added this pull request to the merge queue Jan 1, 2026
Merged via the queue into apache:main with commit 818706a Jan 1, 2026
29 checks passed
@Jefffrey
Copy link
Contributor

Jefffrey commented Jan 1, 2026

Thanks @kumarUjjawal & @Omega359

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants