Skip to content

Honour date_time_overflow_behavior on parsing Date[Time] from text - #116099

Merged
alexey-milovidov merged 21 commits into
masterfrom
yarik/date-time-overflow-behavior-from-string
Sep 21, 2026
Merged

alexey-milovidov merged 21 commits into
masterfrom
yarik/date-time-overflow-behavior-from-string

Conversation

@yariks5s

@yariks5s yariks5s commented Aug 24, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixes a case where date_time_overflow_behavior was ignored on parsing Date and DateTime. Closes #113151.


Workflow [PR]
Sync PR [sync-upstream/pr/116099]

Version info

  • Backported to: 26.9.2.4, 26.8.11.15, 26.7.14.35

@clickhouse-gh

clickhouse-gh Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6f59486]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR threads date_time_overflow_behavior through most Date / DateTime text-parsing paths, including CAST / to*, row-input serializers, tentative parsers, and the JSONExtractTree Date / DateTime carriers. That closes most of the original bug, but I still found two DateTime carriers that violate the new overflow contract, and the previously reported DateTime64 gaps are still present in the current code. Final verdict: request changes.

PR Metadata
  • Changelog category: Bug Fix is correct for the actual change.
  • Changelog entry: the current wording is specific enough, but it embeds Closes https://github.com/ClickHouse/ClickHouse/issues/113151 inside the entry instead of using a standalone relationship line, and that close relationship is too strong while the remaining DateTime64 part of #113151 is still explicitly being left for follow-up work.
  • Exact replacement:
Related: https://github.com/ClickHouse/ClickHouse/issues/113151

### Changelog entry (a [user-readable short description](https://github.com/ClickHouse/ClickHouse/blob/master/docs/changelog_entry_guidelines.md) of the changes that goes into CHANGELOG.md):
Honor `date_time_overflow_behavior` when parsing `Date` and `DateTime` from text, including input formats and typed `JSON` columns.
Missing context / blind spots
  • ⚠️ No local ClickHouse build or binary was present in the workspace, so I could not run targeted repro queries; the findings below come from concrete code traces through the checked-out merge result.
Findings

❌ Blockers

  • src/Functions/FunctionsConversion.h:1132 Digit-only DateTime strings still stop at the time_t parser width. readDateTimeText now honors throw for values like 4294967296, but a quoted timestamp wider than Int64 still overflows in readIntTextImpl<time_t> before date_time_overflow_behavior can clamp or report it. That leaves toDateTime('18446744073709551616') and the quoted-string input-format path outside the new contract, while the unquoted JSON / Values path now clamps the same numeric token via readDateTimeAsNumber.
    Suggested fix: route digit-only string timestamps through the same wide Int128 / Decimal128 helper used by readDateTimeAsNumber, or add an overflow-aware wide integer path before falling back to time_t.
  • src/Formats/JSONExtractTree.cpp:760 Typed JSON DateTime ingestion still diverges from declared DateTime columns in input_format_read_datetime_number_as_raw_value mode. The early negative-Int64 rejection fires before the new overflow check, so {"j":{"d":-1}} with read_datetime_number_as_raw_value = 1 is rejected even in ignore / saturate, while the declared-column serializer uses readDateTimeAsRawValue(..., saturate_on_overflow = true) and clamps the same value to the epoch.
    Suggested fix: reuse readDateTimeAsRawValue / tryReadDateTimeAsRawValue for the integer raw-value branch so typed JSON columns share the same overflow behavior as the regular serializer.
  • [dismissed by author -- https://github.com/Honour date_time_overflow_behavior on parsing Date[Time] from text #116099#discussion_r3844854555] src/Functions/FunctionsConversion.h:1459, src/DataTypes/Serializations/SerializationDateTime64.cpp:73, src/Formats/JSONExtractTree.cpp:1010, src/IO/ReadHelpers.cpp:2701 The DateTime64 half of #113151 is still outside the new overflow plumbing. String conversions, input-format deserializers, and typed-JSON carriers continue to call readDateTime64Text, parseDateTime64BestEffort*, and readDateTime64As(Number|RawValue) without a throw vs saturate mode, so high-scale text and JSON parses still saturate or fail with DECIMAL_OVERFLOW independently of date_time_overflow_behavior.
    Suggested fix: keep #113151 open and thread the same overflow mode through the DateTime64 helpers before using Closes.
Final Verdict

Request changes. The Date / DateTime coverage is much better now, but I still see two user-visible DateTime contract holes, and the PR metadata should stop closing #113151 until the remaining DateTime64 paths are fixed.

LLVM Coverage Report

Measured on commit 6f59486.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 80.50% 80.50% +0.00%

Changed lines: Changed C/C++ lines covered: 369/424 (87.03%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 24, 2026
@mintlify

mintlify Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Sep 15, 2026, 3:56 PM

}

/// Nothing to wrap around when parsing text, so `ignore` behaves like `saturate`
const bool saturate_on_overflow [[maybe_unused]]

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.

DateTime64 is still outside the new date_time_overflow_behavior plumbing. This new saturate_on_overflow / overflow state never reaches the basic DateTime64 branches below (readDateTime64Text / tryReadDateTime64Text at FunctionsConversion.h:1486 and :1598), and the best-effort DateTime64 helpers still have no DateTimeOverflow parameter (parseDateTime64BestEffort* / tryParseDateTime64BestEffort*). That leaves high-scale text parses outside the contract: at scale 8 the representable whole-second range only goes to about year 4892, and at scale 9 to 2262-04-11 (DateTimeTransforms.h), so inputs like toDateTime64('9999-12-31 23:59:59', 8) still will not honor throw / saturate / ignore here. Could you thread the setting through the DateTime64 text helpers too, or narrow the PR/test claim back to Date and DateTime only?

Comment thread src/Functions/FunctionsConversion.h Resolved
Comment thread src/Functions/FunctionsConversion.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 6f5948699d084855d407981ecc8375b1d9242c16 with master failed: RuntimeError: CI logs cluster query failed: SELECT count() AS c FROM binary_sizes W….

See the job log for details.

break;
case FormatSettings::DateTimeInputFormat::BestEffort:
parseDateTimeBestEffort(x, istr, time_zone, utc_time_zone);
parseDateTimeBestEffort(x, istr, time_zone, utc_time_zone, overflow);

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.

DateTime64's serializer still bypasses the new overflow mode. SerializationDateTime64::readText / tryReadText and the whole-text helpers continue to call readDateTime64Text / parseDateTime64BestEffort without any throw vs saturate plumbing, so format(..., 'v DateTime64(...)', ...) SETTINGS date_time_overflow_behavior = 'throw' will keep saturating (or hitting DECIMAL_OVERFLOW at high scale) instead of honoring the setting. The DateTime serializer pattern changed here, but the sibling DateTime64 path is still on the old behavior.

@rschu1ze rschu1ze self-assigned this Aug 27, 2026
Comment thread src/IO/ReadHelpers.cpp Outdated
return ReturnType(false);
}

if (!saturate_on_overflow && !datetime64TicksInRange(x.value, scale))

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.

DateTime64's new numeric-token path still doesn't implement date_time_overflow_behavior = 'saturate'. For example, with format(JSONEachRow, 'v DateTime64(3)', '{"v":253402300800}') the helper first turns the input into 253402300800000 ticks via datetime64TicksFromNumber, and then this new guard only checks the throw branch. When saturate_on_overflow is true, that out-of-range tick is inserted unchanged instead of being clamped to the nearest in-range DateTime64 boundary; readDateTime64AsRawValueImpl has the same gap a few lines below.

Could you clamp both helpers on the saturating path before returning, and keep the current VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE behavior only for throw?

@clickhouse-gh clickhouse-gh Bot added the comp-datetime Date/DateTime/TimeZone datatypes and date-time semantics. label Sep 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 21, 2026
Merged via the queue into master with commit d4f90ad Sep 21, 2026
174 of 176 checks passed
@alexey-milovidov
alexey-milovidov deleted the yarik/date-time-overflow-behavior-from-string branch September 21, 2026 19:35
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 21, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 21, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 22, 2026
Backport #116099 to 26.9: Honour `date_time_overflow_behavior` on parsing Date[Time] from text
robot-clickhouse added a commit that referenced this pull request Sep 22, 2026
Cherry pick #116099 to 26.8: Honour `date_time_overflow_behavior` on parsing Date[Time] from text
robot-clickhouse added a commit that referenced this pull request Sep 22, 2026
robot-clickhouse added a commit that referenced this pull request Sep 22, 2026
Cherry pick #116099 to 26.7: Honour `date_time_overflow_behavior` on parsing Date[Time] from text
robot-clickhouse added a commit that referenced this pull request Sep 22, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 22, 2026
Backport #116099 to 26.8: Honour `date_time_overflow_behavior` on parsing Date[Time] from text
yariks5s added a commit that referenced this pull request Sep 24, 2026
Backport #116099 to 26.7: Honour `date_time_overflow_behavior` on parsing Date[Time] from text
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
@yariks5s yariks5s added v26.4-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Sep 29, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Sep 30, 2026

This branch was successfully deployed

1 active deployment
staging - docs — 6f594869 Deployed Sep 15, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-datetime Date/DateTime/TimeZone datatypes and date-time semantics. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.4-must-backport v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

date_time_overflow_behavior is ignored when the conversion source is a String

5 participants