Skip to content

feat: Add TimestampNTZType support for unix_timestamp#4039

Open
parthchandra wants to merge 4 commits intoapache:mainfrom
parthchandra:complete_ntz
Open

feat: Add TimestampNTZType support for unix_timestamp#4039
parthchandra wants to merge 4 commits intoapache:mainfrom
parthchandra:complete_ntz

Conversation

@parthchandra
Copy link
Copy Markdown
Contributor

@parthchandra parthchandra commented Apr 22, 2026

Part of #378

Summary

Add TimestampNTZ support for temporal expressions and fix DST offset calculation in date_trunc.

Key changes:

  • Add TimestampNTZ support to unix_timestamp (no timezone conversion — simply divides microseconds by 1,000,000)
  • Fix DST offset calculation in as_micros_from_unix_epoch_utc so date_trunc produces correct results when truncation crosses DST boundaries (e.g., December/PST to October/PDT)
  • Add TimestampNTZ tests for hour/minute/second, date_trunc, and date_format
  • Document chrono-tz limitation: DST calculations may be inaccurate for dates beyond ~2100

Not included in this PR: TimestampNTZ cast support (to/from String, Date, Timestamp, Long) — that will come in a separate PR.

Test plan

  • Run temporal expression tests: mvn test -pl spark -Pspark-4.0 -Dsuites="org.apache.comet.CometTemporalExpressionSuite"
  • Rust compilation: cargo check -p datafusion-comet-spark-expr
  • Full test suite

// without timezone, so no conversion should be applied.
expr.children.head.dataType match {
case TimestampType | DateType => true
case dt if dt.typeName == "timestamp_ntz" => true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can just just match on TimestampNTZType rather than use typeName. I know we had to do this in the past, but Spark 3.4 and later have TimestampNTZType

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. Changed.

// calculate DST transitions, which can result in incorrect offsets. See the compatibility
// guide for more information.
#[inline]
fn as_micros_from_unix_epoch_utc(dt: Option<DateTime<Tz>>) -> i64 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the changes here may introduce a regression in DST handling.

Could we merge #4040 first to add new regression test and make sure they still pass with this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, let's merge #4040 first

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#4040 is merged. Rebased to make sure tests all pass

@parthchandra parthchandra marked this pull request as ready for review April 23, 2026 21:58
@parthchandra
Copy link
Copy Markdown
Contributor Author

@andygrove rebased, updated, and ready for review. (Original PR: #3253)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants