Skip to content

Add tests for parseDateTime64BestEffort duplicate fractional separator (takeover of #102890 / supersede #103717) - #104163

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix/parsedatetime64-double-dot-test-takeover-v2
May 6, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix/parsedatetime64-double-dot-test-takeover-v2

Conversation

@groeneai

@groeneai groeneai commented May 6, 2026 •

Copy link
Copy Markdown
Collaborator

Context

This is a slimmed resubmit of #103717 — itself a takeover of @Avogar's stalled #102890 — per @alexey-milovidov's directive on #103717 (the diff is too large. Keep only the relevant changes.).

While preparing this resubmit, I noticed that the actual .cpp fix from #102890 is no longer needed: the duplicate-fractional-separator bug in parseDateTimeBestEffort was fixed on master by @yariks5s's #103773 (merged 2026-04-30 by @alexey-milovidov). Both fixes use the same approach (a boolean has_fractional* flag that errors on the second . after the fractional part has been opened).

The only remaining "relevant change" from #102890 is the expanded test coverage: 3 inputs × 3 function variants (strict / OrNull / OrZero) versus the single-case test on master (tests/queries/0_stateless/04143_ub_parsing_datetime.sql). So this PR adds only those tests.

Tests added

tests/queries/0_stateless/04101_parseDateTime64BestEffort_double_dot_fractional.{sql,reference}:

  • '12:34:56..123' (double dot directly)
  • '12:34:56.123.456' (extra dot after fractional)
  • '12:34:56.123456789012345678.987654321' (long fractional + dot)

Each validated against parseDateTime64BestEffort (strict), parseDateTime64BestEffortOrNull, and parseDateTime64BestEffortOrZero. All three currently pass on master HEAD bc39c42c123e against the locally-built debug binary (errors throw CANNOT_PARSE_DATETIME on strict, \N / 1970-01-01 00:00:00.000 on OrNull / OrZero).

Attribution

Tests originally authored by @Avogar in #102890. The takeover workflow follows @alexey-milovidov's directive on #102890 (2026-04-29). Test files imported as-is; commit carries Co-authored-by: for @Avogar and @nihalzp (who reviewed the wording on the now-redundant .cpp fix).

Closes / supersedes


Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

N/A (test-only)

Documentation entry for user-facing changes

  • Documentation is unchanged.

cc @alexey-milovidov @Avogar @nihalzp @yariks5s

Version info

  • Merged into: 26.5.1.366

Adds expanded coverage (3 inputs * 3 OrNull/OrZero variants) for the
duplicate fractional-separator case in parseDateTime64BestEffort.

The underlying bug is already fixed on master by PR ClickHouse#103773 (yariks5s,
"Fix UB while parsing dateTime", merged 2026-04-30). This test PR
takes over @Avogar's stalled ClickHouse#102890 / closed ClickHouse#103717 by carrying
forward only the additional test cases — the .cpp fix from ClickHouse#102890
is now redundant.

Test cases:
  '12:34:56..123'                                  (double dot directly)
  '12:34:56.123.456'                               (extra dot after fractional)
  '12:34:56.123456789012345678.987654321'          (long fractional + dot)

Each tested against parseDateTime64BestEffort (strict),
parseDateTime64BestEffortOrNull, and parseDateTime64BestEffortOrZero.

Co-authored-by: avogar <[email protected]>
Co-authored-by: Pavel Kruglov <[email protected]>
Co-authored-by: Nihal Z. Miaji <[email protected]>
@groeneai

groeneai commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (per groeneai TASK.md)

This PR adds tests only — no C++ source changes. Gate answers:

a) Deterministic repro? Yes — without yariks5s' #103773 on master, every parseDateTime64BestEffort('12:34:56.<digits>.<digits>') call would silently parse the second-dot bytes as garbage and either return junk timestamps or trigger the chronic UBSan signed-overflow finding in function_prop_fuzzer that's been hitting ~30 unrelated PRs over the last 14 days. With #103773 merged, every input in this test errors CANNOT_PARSE_DATETIME on strict, and returns \N / 1970-01-01 00:00:00.000 on OrNull / OrZero.

b) Root cause explained? The bug is in parseDateTimeBestEffortImpl's point-symbol branch in src/IO/parseDateTimeBestEffort.cpp (line ~562). When the parser meets a . after HH:MM:SS, it reads the fractional part. Before #103773 there was no check for a second . — the parser would re-enter the fractional branch and attempt to read more digits into an already-consumed buffer, producing UB / garbage. yariks5s' fix adds bool has_fractional and errors on the second .. Avogar's #102890 did the same with has_fractional_separator; functionally identical.

c) Fix matches root cause? N/A for this PR — the fix already landed in #103773. This PR only validates that the fix is correctly catching the documented edge cases.

d) Test intent preserved? / New tests added? Yes. The 3 inputs × 3 function variants are Avogar's original test design (carried forward verbatim from #102890). The single-case test on master (04143_ub_parsing_datetime.sql) only covers '1970-01-01 00:00:00.99999999999999999.999999999999' — this PR adds 12:34:56..123 (consecutive dots), 12:34:56.123.456 (separate dots), 12:34:56.123456789012345678.987654321 (long fractional) for OrNull/OrZero variants too.

e) Demonstrated in both directions? Verified locally on master HEAD bc39c42c123e:

$ ./build/programs/clickhouse local --query "SELECT parseDateTime64BestEffort('12:34:56..123')"
Code: 41. DB::Exception: Cannot read DateTime: duplicate fractional part: ... (CANNOT_PARSE_DATETIME)
$ ./build/programs/clickhouse local --query "SELECT parseDateTime64BestEffortOrNull('12:34:56..123')"
\N
$ ./build/programs/clickhouse local --query "SELECT parseDateTime64BestEffortOrZero('12:34:56..123')"
1970-01-01 00:00:00.000

Diff against .reference is empty. The tests would FAIL if #103773 were reverted — they're a regression guard for it.

f) Fix is general, not a narrow patch? N/A for test-only PR. Note: the underlying fix (#103773) is general — it covers all parseDateTime*BestEffort* variants at the same line of code. Adding tests for OrNull/OrZero variants ensures the no-throw error paths are also exercised.

Session: cron:clickhouse-ci-task-worker:20260506-001500

@groeneai

groeneai commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov — could you review? Test-only resubmit per your directive on #103717. Diff is 19 lines (1 SQL + 1 reference). Adds 3 inputs × 3 function variants on top of the single-case test (#103773) already on master.

@Algunenano Algunenano added the can be tested Allows running workflows for external contributors label May 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [392c844]

Summary: ✅


AI Review

Summary

This PR adds a new stateless test pair for parseDateTime64BestEffort* inputs with duplicate fractional separators (.. / second . after fractional digits), covering strict, OrNull, and OrZero behavior. The change is narrowly scoped to test coverage and looks correct; I found no correctness, safety, or performance issues that require changes.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 6, 2026

@alexey-milovidov alexey-milovidov left a comment

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.

Thanks, good change!

@alexey-milovidov alexey-milovidov self-assigned this May 6, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 6, 2026
Merged via the queue into ClickHouse:master with commit f72e56e May 6, 2026
165 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci 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.

4 participants