Skip to content

fix: accept up to 9 fractional digits for micros timestamps - #4142

Open
Shahzeb-DataEngineer wants to merge 1 commit into
apache:mainfrom
Shahzeb-DataEngineer:fix/timestamp-fraction-digits
Open

Shahzeb-DataEngineer wants to merge 1 commit into
apache:mainfrom
Shahzeb-DataEngineer:fix/timestamp-fraction-digits

Conversation

@Shahzeb-DataEngineer

Copy link
Copy Markdown

Closes #4141

Rationale for this change

timestamp_to_micros and timestamptz_to_micros rejected valid ISO-8601 strings with 7-9 fractional second digits because ISO_TIMESTAMP / ISO_TIMESTAMPTZ capped the fraction at 6 digits, and ISO_TIMESTAMPTZ did not accept zone offsets with seconds. These converters are used when binding string literals to timestamp/timestamptz columns and when parsing JSON single values (partition values and initial defaults), so timestamps written by other engines with nanosecond precision failed to load or filter.

The Java implementation accepts 0-9 fractional digits (appendFraction(NANO_OF_SECOND, 0, 9, true)) and truncates to the target precision. This change mirrors that behavior:

  • Widen ISO_TIMESTAMP and ISO_TIMESTAMPTZ to accept 1-9 fractional digits, and allow optional seconds in the zone offset (also in ISO_TIMESTAMPTZ_NANO).
  • Parse micros timestamps through the existing nanosecond path and truncate to microseconds with nanos_to_micros, so the sub-microsecond handling stays in one place. Nanosecond types keep full precision.

Are these changes tested?

Yes. Added parametrized cases for 7, 8, and 9 fractional digits for both timestamp_to_micros and timestamptz_to_micros in tests/utils/test_datetime.py, including the offset-with-seconds form and the existing specific error messages, plus a JSON single-value deserialization test with 9-digit fractions in tests/test_conversions.py. Ran tests/utils/test_datetime.py, tests/test_conversions.py, and tests/expressions/test_literals.py locally; all pass (283 + 172 tests).

Are there any user-facing changes?

Yes: strings that were previously rejected with ValueError are now accepted and truncated to microsecond precision, matching the Java implementation. No previously valid input changes meaning.

Widen ISO_TIMESTAMP and ISO_TIMESTAMPTZ to accept 1-9 fractional digits
and zone offsets with optional seconds, and parse micros timestamps
through the nanosecond path, truncating to microseconds, mirroring the
Java implementation. Previously, valid ISO-8601 strings with nanosecond
precision were rejected with a ValueError when binding string literals
to timestamp/timestamptz columns or parsing JSON single values.

Signed-off-by: Shahzeb Ali <126076773+Shahzeb-DataEngineer@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 07:25

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

Timestamp strings with more than 6 fractional digits are rejected for micros timestamp/timestamptz columns

2 participants