Skip to content

Fix inserting into Time data type during JSON parsing - #102690

Merged
Avogar merged 6 commits into
masterfrom
json-time-type-read
May 15, 2026
Merged

Avogar merged 6 commits into
masterfrom
json-time-type-read

Conversation

@Avogar

@Avogar Avogar commented Apr 14, 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):

Fix inserting into Time data type during JSON parsing. Closes #102016

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.683

@clickhouse-gh

clickhouse-gh Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [24de88d]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_msan, WasmEdge, parallel, 2/2) FAIL
02005_log_formatted_queries FAIL cidb IGNORED
Unit tests (asan_ubsan, function_prop_fuzzer) FAIL
FunctionsStress.stress FAIL cidb, issue ISSUE EXISTS
AllTests FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This PR makes JSONExtract accept signed JSON integers for Time and DateTime and adds stateless coverage, but one correctness issue is still live: out-of-range signed integer input for DateTime is silently wrapped when inserted into UInt32, producing incorrect timestamps.

Findings
  • ⚠️ Majors
    • [src/Formats/JSONExtractTree.cpp:724] The new signed-integer path for DateTime still inserts directly into ColumnDateTime (UInt32) without bounds handling. For example, {"t": 5000000000} is accepted and stored as 705032704 (mod 2^32) instead of being rejected (or consistently clamped), which violates data-correctness expectations for out-of-range input.
      • Suggested fix: validate integer range before insert (for example with accurate::convertNumeric<..., UInt32, false> and a clear conversion error on failure), then add a focused regression test for this boundary.
  • 💡 Nits
    • [tests/queries/0_stateless/04094_json_extract_time_numeric.sql:34] The comment says 4294967295 is > INT64_MAX, but it is actually UInt32 max and below INT64_MAX. Please reword the comment to reflect the real boundary under test.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    1. Add explicit out-of-range handling for signed numeric DateTime conversion in JSONExtract.
    2. Add a regression check for the out-of-range boundary (for example 5000000000).

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 14, 2026
Comment thread src/Formats/JSONExtractTree.cpp Resolved
@yariks5s yariks5s self-assigned this Apr 15, 2026
return false;
}

value = element.isInt64() ? element.getInt64() : element.getUInt64();

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.

DateTime conversion here still inserts into ColumnDateTime (UInt32) without range handling, so positive Int64 values above 4294967295 will wrap instead of being clamped/rejected.

Concrete trace: for {"t": 5000000000} as Int64, this branch sets value = 5000000000, then ColumnDateTime::insert stores static_cast<UInt32>(5000000000) = 705032704 (unexpected timestamp around 1992-05-05).

Please align this path with convertFromTime<DataTypeDateTime> semantics (clamp to MAX_DATETIME_TIMESTAMP or throw according to overflow policy) before insert.

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.

This is still live on the current HEAD.

DateTimeNode now accepts signed JSON integers, but it still inserts directly into ColumnDateTime (UInt32) without range handling:

value = element.isInt64() ? element.getInt64() : element.getUInt64();
assert_cast<ColumnDateTime &>(column).insert(value);

For {"t": 5000000000}, this stores 5000000000 mod 2^32 = 705032704 instead of rejecting the out-of-range value (or clamping consistently). Can we add explicit bounds handling before insert (for example via accurate::convertNumeric to UInt32)?

SELECT 'DateTime64 from Int64 numeric';
SELECT JSONExtract('{"t": 1234567890123}', 't', 'DateTime64(3)') SETTINGS date_time_output_format = 'iso';

-- Large UInt64 value that is genuinely UInt64 (> INT64_MAX) for DateTime

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 comment says > INT64_MAX, but 4294967295 is below INT64_MAX. That makes the test intent misleading.

Please reword this to match the actual boundary being tested, e.g. UInt32 max for DateTime.

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.

This is still inaccurate in the current diff: 4294967295 is not > INT64_MAX; it is exactly UInt32 max.

Please reword the comment so the boundary being tested is clear (for example, "DateTime upper boundary (UInt32 max)").

@Avogar
Avogar added this pull request to the merge queue May 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 77.78% (7/9) | lost baseline coverage: 2 line(s) · Uncovered code

Full report · Diff report

@Avogar
Avogar added this pull request to the merge queue May 15, 2026
Merged via the queue into master with commit b93459a May 15, 2026
164 of 167 checks passed
@Avogar
Avogar deleted the json-time-type-read branch May 15, 2026 15:27
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 15, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @Avogar @yariks5s — while reviewing this PR I found the following:

Could you review the test PR and add the can be tested label if it looks good?
Happy to discuss — close anything that's wrong or already addressed.

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

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TimeNode only handles isUInt64() but JSON parser returns Int64 for positive integers

4 participants