Skip to content

Fix precision timestamp#28919

Closed
patrickmoch wants to merge 47 commits into
trinodb:masterfrom
patrickmoch:fix-precision-timestamp
Closed

Fix precision timestamp#28919
patrickmoch wants to merge 47 commits into
trinodb:masterfrom
patrickmoch:fix-precision-timestamp

Conversation

@patrickmoch
Copy link
Copy Markdown

Description

Fixes precision loss when reading timestamp with time zone columns from Delta Lake tables backed by Parquet files written with microsecond precision (e.g. by Spark).

Additional context and related issues

The Delta Lake protocol spec defines timestamp as microsecond precision stored as int64 with isAdjustedToUTC=true in Parquet. Trino was mapping this to TIMESTAMP_TZ_MILLIS (precision 3), causing the sub-millisecond digits to be silently dropped on read. For example, a value written by Spark as 2024-01-12 09:30:47.405423 UTC would be read by Trino as 2024-01-12 09:30:47.405 UTC.
The fix maps the Delta "timestamp" type to TIMESTAMP_TZ_MICROS (precision 6) and updates the validation guard in validatePrimitiveType accordingly.
Backward compatibility with Parquet files written by older Trino versions (which used TIMESTAMP(MILLIS) physical encoding) is preserved by handling the MILLIS case in ColumnReaderFactory for LongTimestampWithTimeZone rather than throwing. These files will read correctly with zeros in the sub-millisecond digits, which accurately reflects the precision they were written with.
Note: timestamp_ntz (without timezone) was already correctly mapped to TIMESTAMP_MICROS (precision 6) — this change brings timestamp (with timezone) into alignment with it.

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(X ) Release notes are required, with the following suggested text:

## Delta Lake
* Fix precision loss when reading `timestamp with time zone` columns from
  Delta Lake tables. Values are now read at microsecond precision
  (`timestamp(6) with time zone`) instead of being silently truncated to
  millisecond precision (`timestamp(3) with time zone`). ({issue} '20359')

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@github-actions github-actions Bot added the delta-lake Delta Lake connector label Mar 30, 2026
@patrickmoch patrickmoch marked this pull request as draft March 30, 2026 08:53
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

3 similar comments
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

patrickmoch and others added 8 commits March 30, 2026 11:54
- Update type assertions from timestamp(3) to timestamp(6) with time zone
- Replace TIMESTAMP_TZ_MILLIS with TIMESTAMP_TZ_MICROS in column handle
  construction for Delta-specific tests
- Add end-to-end test verifying microsecond values are preserved on
  INSERT/SELECT roundtrip
- Add backward compatibility test verifying MILLIS-encoded parquet files
  written by older Trino versions still read correctly with zero
  sub-millisecond digits
…e precision

- update values for timestamp(6)
@patrickmoch patrickmoch force-pushed the fix-precision-timestamp branch from 356e8c6 to c9f7b44 Compare March 30, 2026 09:55
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

dependabot Bot and others added 9 commits March 30, 2026 12:41
Bumps [io.github.gitflow-incremental-builder:gitflow-incremental-builder](https://github.com/gitflow-incremental-builder/gitflow-incremental-builder) from 4.5.6 to 4.6.0.
- [Release notes](https://github.com/gitflow-incremental-builder/gitflow-incremental-builder/releases)
- [Commits](gitflow-incremental-builder/gitflow-incremental-builder@v4.5.6...v4.6.0)

---
updated-dependencies:
- dependency-name: io.github.gitflow-incremental-builder:gitflow-incremental-builder
  dependency-version: 4.6.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
- Update type assertions from timestamp(3) to timestamp(6) with time zone
- Replace TIMESTAMP_TZ_MILLIS with TIMESTAMP_TZ_MICROS in column handle
  construction for Delta-specific tests
- Add end-to-end test verifying microsecond values are preserved on
  INSERT/SELECT roundtrip
- Add backward compatibility test verifying MILLIS-encoded parquet files
  written by older Trino versions still read correctly with zero
  sub-millisecond digits
…e precision

- update values for timestamp(6)
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

patrickmoch and others added 16 commits March 30, 2026 13:38
- Update type assertions from timestamp(3) to timestamp(6) with time zone
- Replace TIMESTAMP_TZ_MILLIS with TIMESTAMP_TZ_MICROS in column handle
  construction for Delta-specific tests
- Add end-to-end test verifying microsecond values are preserved on
  INSERT/SELECT roundtrip
- Add backward compatibility test verifying MILLIS-encoded parquet files
  written by older Trino versions still read correctly with zero
  sub-millisecond digits
…e precision

- update values for timestamp(6)
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Mar 30, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@github-actions
Copy link
Copy Markdown

This pull request has gone a while without any activity. Ask for help on #core-dev on Trino slack.

@github-actions github-actions Bot added the stale label Apr 20, 2026
@github-actions
Copy link
Copy Markdown

Closing this pull request, as it has been stale for six weeks. Feel free to re-open at any time.

@github-actions github-actions Bot closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delta-lake Delta Lake connector stale

Development

Successfully merging this pull request may close these issues.

3 participants