Repository navigation
Make JSONExtract honour cast_string_to_date_time_mode when parsing DateTime values - #109252
alexey-milovidov merged 9 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes JSONExtract parsing of DateTime/DateTime64 extracted from JSON string values so it follows cast_string_to_date_time_mode (consistent with CAST), rather than incorrectly keying off date_time_input_format.
Changes:
- Update
FunctionsJSONto overrideFormatSettings::date_time_input_formatfromcast_string_to_date_time_modefor JSON extraction. - Add a stateless query test covering
best_effort,basic, andbest_effort_usbehavior forJSONExtractintoDateTime/DateTime64.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Functions/FunctionsJSON.cpp |
Switch JSONExtract DateTime parsing mode to honor cast_string_to_date_time_mode. |
tests/queries/0_stateless/04498_json_extract_cast_string_to_date_time_mode.sql |
New stateless regression test for DateTime/DateTime64 extraction respecting cast mode. |
tests/queries/0_stateless/04498_json_extract_cast_string_to_date_time_mode.reference |
Expected outputs for the new stateless regression test. |
|
Friendly ping for review — this is a small, self-contained fix for #109126 with a stateless test. Happy to adjust the approach if maintainers prefer keying off date_time_input_format instead. |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
|
Workflow [PR], commit [6276cab] Summary: ✅
AI ReviewSummaryThis PR makes the string-JSON parser path for Findings❌ Blockers
Tests
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 3/5 (60.00%) · Uncovered code |
| /// Extracting a string JSON value into a DateTime/DateTime64 column is a string-to-type | ||
| /// cast, so we honour `cast_string_to_date_time_mode` (rather than `date_time_input_format`), | ||
| /// same as HivePartitioningUtils::buildHiveFormatSettings. | ||
| format_settings.date_time_input_format = context->getSettingsRef()[Setting::cast_string_to_date_time_mode]; |
There was a problem hiding this comment.
This only fixes the string-input parser path. When the first argument is native JSON, runForObjectColumn still converts the extracted subcolumn via castColumnAccurateOrNull ([src/Functions/FunctionsJSON.cpp:321]), and castColumn builds that internal cast with ContextPtr{} ([src/Interpreters/castColumn.cpp:33]). That falls back to cast_string_to_date_time_mode = Basic ([src/Functions/FunctionsConversion.h:151]), so JSONExtract(json_col, 'date', 'DateTime64(...)') still ignores the session setting whenever the JSON path is stored as String. The PR contract says JSONExtract now honours cast_string_to_date_time_mode, but native JSON input remains divergent. Please thread the current Context/cast settings through the object-column fast path and add a regression test for JSON-typed input.
There was a problem hiding this comment.
This sent me down a bit of a rabbit hole, it seems that the castColumn function that eventually does the casting doesn't even accept a context object and so cannot honor any of these settings without some non-trivial changes. However, I think this is outside the scope of this PR. There is an issue already tracking it: #102079.
george-larionov
left a comment
There was a problem hiding this comment.
This change looks good to me, it's a bit hacky but I agree it's the best fix currently. Now we just need to deal with any failing tests (we have a new policy to not merge PRs without a green CI).
| /// Extracting a string JSON value into a DateTime/DateTime64 column is a string-to-type | ||
| /// cast, so we honour `cast_string_to_date_time_mode` (rather than `date_time_input_format`), | ||
| /// same as HivePartitioningUtils::buildHiveFormatSettings. | ||
| format_settings.date_time_input_format = context->getSettingsRef()[Setting::cast_string_to_date_time_mode]; |
There was a problem hiding this comment.
This sent me down a bit of a rabbit hole, it seems that the castColumn function that eventually does the casting doesn't even accept a context object and so cannot honor any of these settings without some non-trivial changes. However, I think this is outside the scope of this PR. There is an issue already tracking it: #102079.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 3/5 (60.00%) · Uncovered code |
|
The failing test is a flaky test with an issue that is assigned and is actively being discussed. Merging master and rerunning tests. |
|
Merged current master (the base was 303 commits behind) to get a clean CI run. For the record, both red checks on
The failing query was: SELECT __table1.x AS x FROM merge('.*[0-9].*')which is #111945 — a Why a
If the rename flake reappears on this run, the data above should be enough to treat it as known rather than as a regression from this PR. |
|
CI on
I will take a look at failure 2, in the meantime merging master. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
|
CI is green apart from The failure is It is pre-existing and fleet-wide: 3 failures on Tracked by #112213 (root cause) and #114368 (CI matcher). Fix in progress: #112484 Merging |
|
@george-larionov @alexey-milovidov The CI checks are fully green and the PR is approved. Could we go ahead and get this merged? Thanks for the help getting it across the line. |
ReproducerSET cast_string_to_date_time_mode = 'best_effort', date_time_input_format = 'basic';
SELECT JSONExtract('{"date":"2020-01-01 00:00:00.123Z"}', 'date', 'DateTime64(3, ''UTC'')');
-- 26.7.5.10: 1970-01-01 00:00:00.000 (CAST of the same string: 2020-01-01 00:00:00.123)
SET cast_string_to_date_time_mode = 'basic', date_time_input_format = 'best_effort';
SELECT JSONExtract('{"date":"2020-01-01 00:00:00.123Z"}', 'date', 'DateTime64(3, ''UTC'')');
-- 26.7.5.10: 2020-01-01 00:00:00.123 (date_time_input_format must not apply here)Results:
Backport the fix to CC component owner: @alexey-milovidov @bharatnc Analysis metadata
Introducing change: not searched
|
|
Hi — this looks like a backport candidate for |
|
@Utkal059 @george-larionov @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
|
@george-larionov Thanks again for reviewing this — following up to ask if there's a path for a Jan 2027 internship or junior role on Core given current openings are senior-level. |
|
@Utkal059 thanks for contributing! Unfortunately we currently don't have an intern program, however there are currently a few Core Software Engineer (non senior) jobs open on clickhouse.com/careers, your best bet is to apply there. Best of luck! |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
JSONExtractnow honourscast_string_to_date_time_modewhen converting string JSON values toDateTime/DateTime64, consistently withCAST. Closes #109126.Extracting a string JSON value into
DateTime/DateTime64is a string-to-type cast, butJSONExtractkeyed its parsing mode offdate_time_input_format(an input-format parsing setting), while the equivalentCASThonourscast_string_to_date_time_mode. Withdate_time_input_format = 'basic'andcast_string_to_date_time_mode = 'best_effort'(reproduced on current master):