Repository navigation
Fix formatDateTime with a LowCardinality time zone - #117006
Conversation
`formatDateTime`, `formatDateTimeInJodaSyntax`, `fromUnixTimestamp` and
`fromUnixTimestampInJodaSyntax` accept a non-constant time zone argument. When
that argument is a `LowCardinality` column, the function is executed on the
column's dictionary, which always contains the default value - the empty string
- even when no row references it. The empty string is not a valid time zone, so
the query failed before reading a single row:
:) WITH number % 2 ? 'UTC' : 'Europe/Amsterdam' AS tz
SELECT DISTINCT formatDateTime(now(), '%F %T', toLowCardinality(tz)) FROM numbers(1e8)
Code: 43. DB::Exception: Provided time zone must be non-empty:
while executing function formatDateTime ... (ILLEGAL_TYPE_OF_ARGUMENT)
Report that these functions cannot be executed on default arguments, the same
way `CAST` and `toString` already do, so that only the values the rows actually
reference are formatted. An empty time zone in the data is still an error.
|
Workflow [PR], commit [3be07a3] Summary: ❌
AI ReviewSummaryThis PR fixes the Missing context / blind spots
Findings💡 Nits
Final VerdictNeeds one documentation follow-up. I found no remaining correctness or performance blocker in the LLVM Coverage ReportMeasured on commit 3be07a3.
Changed lines: Changed C/C++ lines covered: 36/37 (97.30%) · Uncovered code |
Build profile diff (arm_release)Comparing commit See the job log for details. |
The fix lives in the shared `FunctionFormatDateTimeImpl<support_integer, format_syntax>`, so add a regression query for the remaining `support_integer` + Joda instantiation - `fromUnixTimestampInJodaSyntax` - which was the only one of the four entrypoints named in the description without direct coverage. Renumber the test from `05048` to `05054`: `05048` was taken on master in the meantime.
…ardinality-timezone
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117006&sha=d2ec1eaef74e8f12048cd4261d262736ce4f5cef&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. It is a TLP
I have merged |
AST fuzzer (amd_release, oracle): not caused by this PR, and #118484 already covers itThe job's own So the relation the oracle read twice is an in-memory buffer unioned with a merge-collapsing destination read without No partition over-counts. The arms partition on Reproduced on master reproducer and outputCREATE TABLE s (key UInt32, val_minmax UInt32, val_set UInt32) ENGINE = SummingMergeTree ORDER BY key SETTINGS index_granularity = 10;
SYSTEM STOP MERGES s;
INSERT INTO s SELECT number, number + 1, number + 1 FROM numbers(1000); -- x 150
SELECT count() FROM s; -- 150000
SELECT count() FROM s FINAL; -- 1000
SYSTEM START MERGES s;
-- clickhouse local --ast_fuzzer_runs=300 --ast_fuzzer_oracle=1 --ast_fuzzer_any_query=0
SELECT ' iryaP:kmrey' FROM s WHERE key = 2000;The fix for this report is already in progress: #118484 rejects a query naming a table whose That is not the whole hole, and I will send the rest as a separate PR: the reproducer above names no |
|
The separate fix PR is up: #119465. It generalizes the reference-stability guard The report on this pull request needs nothing further: #118484 already skips a query whose read reaches a |
The AI review pointed out that `canBeExecutedOnDefaultArguments` is global for the whole `FunctionFormatDateTimeImpl`, so returning `false` also dropped the dictionary-only execution for a call whose only `LowCardinality` argument is the value itself, such as `formatDateTime(lc_datetime, '%F')` or the one-argument `fromUnixTimestamp(lc_uint32)`. Those went through `getMinimalDictionaryEncodedColumn`, which remaps every row index, even though the dictionary default is harmless for a date, a date with time or an integer. The hook is asked without the arguments, so it cannot make the distinction by itself. Register the family through `FunctionWithLowCardinalityFastPath` and add a `tryExecuteLowCardinality` that declines only when the third `timezone` argument is a non-constant `LowCardinality` column - the one case whose dictionary holds the empty string - and otherwise redoes the call on a delegate that keeps `canBeExecutedOnDefaultArguments` enabled. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ardinality-timezone
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Update on 2026-09-18. AI Review blocker adopted. The test covers the preserved path for all four entrypoints, a constant and a non-constant
|
| {description_fromUnixTimestamp, syntax_fromUnixTimestamp, arguments_fromUnixTimestamp, {}, returned_value_fromUnixTimestamp, examples_fromUnixTimestamp, introduced_in_fromUnixTimestamp, category_fromUnixTimestamp}; | ||
|
|
||
| factory.registerFunction<FunctionFromUnixTimestamp>(documentation_fromUnixTimestamp); | ||
| factory.registerFunction<FunctionWithLowCardinalityFastPath<FunctionFromUnixTimestamp>>(documentation_fromUnixTimestamp); |
There was a problem hiding this comment.
The PR contract and the new regression test both rely on a non-constant timezone argument here, but the structured FunctionDocumentation for fromUnixTimestamp and fromUnixTimestampInJodaSyntax still says the third argument is an optional constant time zone string.
Because those strings feed the reference docs and system.functions, users will still be told that the fixed call shape is unsupported. Please update those descriptions and argument docs in the same change.
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Closes: #117437
formatDateTime,formatDateTimeInJodaSyntax,fromUnixTimestampandfromUnixTimestampInJodaSyntaxaccept a non-constant time zone argument. When that argument is aLowCardinalitycolumn, the function is executed on the column's dictionary, which always contains the default value - the empty string - even when no row references it. The empty string is not a valid time zone, so the query failed before reading a single row:The same query without
toLowCardinalityworks.The fix reports that these functions cannot be executed on default arguments, the same way
CASTalready does, so that only the values the rows actually reference are formatted. An empty time zone in the data is still an error.canBeExecutedOnDefaultArgumentsis asked without the arguments, so it cannot on its own tell aLowCardinalitytime zone from aLowCardinalitydate or integer, for which the dictionary default is harmless. To keep the dictionary-only execution offormatDateTime(lc_datetime, '%F')and of the one-argumentfromUnixTimestamp(lc_uint32), the family is registered throughFunctionWithLowCardinalityFastPathand implementstryExecuteLowCardinality, which declines - and so asks for a minimal dictionary of the referenced values - only when the thirdtimezoneargument is a non-constantLowCardinalitycolumn, and otherwise redoes the call on a delegate that keepscanBeExecutedOnDefaultArgumentsenabled.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix the error
Provided time zone must be non-emptywhen the time zone argument offormatDateTime,formatDateTimeInJodaSyntax,fromUnixTimestamporfromUnixTimestampInJodaSyntaxis aLowCardinalitycolumn.Workflow [PR]
Sync PR [sync-upstream/pr/117006]
Version info
26.10.1.295-master(included in26.10and later)