fix: DateTime64BestEffort milli/nano precision#105233
Conversation
Looks like enabling the "best_effort" as default recently caused this?
Before:
```
:) SELECT toDateTime64('1779094968417585845', 9) SETTINGS cast_string_to_date_time_mode='besteffort'
SELECT toDateTime64('1779094968417585845', 9)
SETTINGS cast_string_to_date_time_mode = 'besteffort'
Query id: f3b9bc78-9ec3-46f7-bbf3-65795a61b5ec
Received exception:
Code: 36. DB::Exception: Unexpected value of DateTimeInputFormat: 'besteffort'. Must be one of ['best_effort_us', 'best_effort', 'basic']. (BAD_ARGUMENTS) (version 26.5.1.740 (official build))
```
After:
```
:) SELECT toDateTime64('1779094968417585845', 9) SETTINGS cast_string_to_date_time_mode='best_effort'
SELECT toDateTime64('1779094968417585845', 9)
SETTINGS cast_string_to_date_time_mode = 'best_effort'
Query id: d11d292d-6183-4b2d-8bff-1af10e9bee08
┌─toDateTime64('⋯417585845', 9)─┐
1. │ 2026-05-18 11:02:48.417585845 │
└───────────────────────────────┘
1 row in set. Elapsed: 0.004 sec.
```
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
|
Workflow [PR], commit [39982a1] Summary: ✅ AI ReviewSummaryThis PR extends Final Verdict
|
|
It is a bit unclear for me, what is the actual bug. For me, it looks like an improvement than a fix. In the "before" example the only issue is
I think the PR is valuable and really nice addition, but I wouldn't call this as a bugfix. |
The gap is real. Pre 09-09-2001, unix timestamp was 9 digit. But this already a problem with existing branches (e.g: 13 ms branch on the same function). Also in the src/IO/ReadHelpers.h this behavior and shortcoming is explicitly documented. Even if we want to fix this behavior correctly, we need scale (seconds = value / 10^scale) to splitting from the right (3, 6 or 9). but parseDateTimeBestEffortImpl doesn't currently see scale and it's unaware of it. Fixing this correctly might need bigger refactoring I believe. Instead I added comments to make this behavior explicit on this function and added tests to lock this behavior to avoid future surprises Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
|
@antaljanosbenjamin sorry for the confusion. Updated the PR description. It is indeed a bug. You can reproduce the bug even without that You can see the difference in behavior simply running the queries without the settings. Before (in v26.3.9.8) - It worksBefore (in current master) - It breaksAfter (this PR) - works |
Ah, okay, now it is clear. Thanks for clarifying. |
Added tests to lock the behavior of the explicit "best_effort" and default behavior to avoid future regression Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
LLVM Coverage Report
Changed lines: 83.33% (15/18) | lost baseline coverage: 4 line(s) · Uncovered code |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
best_effortdate time parsing work correctly withtoDateTime64withmsandnsprecision.Explanation.
Looks like enabling the "best_effort" as default recently caused this?
This is exposed by the golang-client tests that runs on head of the master branch.. It used to work in previous versions correctly (because it was using
basicas default)Before:
After: