Skip to content

feat: support TIME(p) SQL types - #27316

Open
sdf-jkl wants to merge 1 commit into
apache:mainfrom
sdf-jkl:codex/time-precision-27271
Open

sdf-jkl wants to merge 1 commit into
apache:mainfrom
sdf-jkl:codex/time-precision-27271

Conversation

@sdf-jkl

@sdf-jkl sdf-jkl commented Nov 10, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #27271.

Rationale for this change

SQL rejects explicit precision on TIME, so users cannot name second, millisecond, or microsecond time types in casts or column declarations.

What changes are included in this PR?

Accept TIME(p) for the same precisions supported by TIMESTAMP(p):

SQL type Arrow type
TIME(0) Time32(Second)
TIME(3) Time32(Millisecond)
TIME(6) Time64(Microsecond)
TIME(9) Time64(Nanosecond)

Update the SQL type documentation with these mappings.

What is the testing strategy for this PR?

Added cases in datafusion/sqllogictest/test_files/datetime/timestamps.slt cover casts, fractional-second truncation, column declarations, nulls, WITHOUT TIME ZONE, and rejection of unsupported precisions and time zones. The new casts and table declaration fail without the implementation.

Validation passed: 718 SQL crate tests and doctests, 76 datetime/cast SQL test files, all repository lint checks, including full workspace Clippy with all targets and features and the documentation build. Full workspace tests were not run.

Are there any user-facing changes?

Yes, TIME(0/3/6/9) is now accepted, including with WITHOUT TIME ZONE. Plain TIME remains Time64(Nanosecond). Other precisions, TIMETZ, and TIME WITH TIME ZONE remain unsupported.

@github-actions github-actions Bot added documentation Improvements or additions to documentation sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Nov 10, 2026
@sdf-jkl

sdf-jkl commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

@alamb @kumarUjjawal PTAL.

Can we backport this to 56 too? 😁

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks -- makes sense to me @sdf-jkl

Can you please also update the datatype docs here with this type? https://datafusion.apache.org/user-guide/sql/data_types.html#date-time-types

@sdf-jkl

sdf-jkl commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

@kumarUjjawal kumarUjjawal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @sdf-jkl

Left few comments please take a look.

{
Ok(DataType::Time64(TimeUnit::Nanosecond))
let data_type = match precision {
Some(0) => DataType::Time32(TimeUnit::Second),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Correct me if I am wrong but TIME(0), TIME(3) and TIME(6) now give Time32(s), Time32(ms) and Time64(us), but DataFusion has no rule to compare two time values with different units, so these columns cannot be compared, joined or IN-listed against plain TIME values?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe that would be a good follow on to track in a separate ticket

}
SQLDataType::Date => Ok(DataType::Date32),
SQLDataType::Time(None, tz_info) => {
SQLDataType::Time(precision, tz_info)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The precision guard and the precision-to-TimeUnit match, including _ => unreachable!(), are copied from the TIMESTAMP arm instead of shared.


# Column declarations use the same mapping, including WITHOUT TIME ZONE.
statement ok
CREATE TABLE times (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new times table is created but never dropped, so it stays in the session for the rest of this long test file.**

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 sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support TIME(p) SQL type

3 participants