Repository navigation
Conversation
The file-like readers (`StorageObjectStorageSource::createReader`, `StorageFileSource`, `StorageURLSource`) evaluate column defaults with `AddingDefaultsTransform` inside the per-file reader pipeline, but append the Hive partition columns to the chunk only after that pipeline, and `prepareReadingFromFormat` never lets the format read a Hive column (ClickHouse#87515). A default over a Hive column therefore had no input: for formats that read a subset of columns it failed with `UNKNOWN_IDENTIFIER`, for formats that read every column (CSV, TSV, ... on File/URL) it silently took the Hive column's own default or the type default. For S3Queue the file was marked Failed. `prepareReadingFromFormat` now records the Hive columns that a default of `columns_description` reads (`hive_partition_columns_read_by_defaults`, matched with `isSameOrNestedColumn`, so a subcolumn reference records its parent), `updateFormatPrewhereInfo` carries the field, and the three readers add those columns as constants from the file's path in front of `AddingDefaultsTransform` through `HivePartitioningUtils::addPartitionColumnsForDefaults` (the same parse/convert functions as `addPartitionColumnsToChunk`). `ExtractColumnsTransform` drops them again, so the source header and reads whose defaults do not use a Hive column are unchanged. `AddingDefaultsTransform` indexed `BlockMissingValues`, which is sized to the format header, by the block position of every defaulted column; a Hive column with its own DEFAULT appended after the format's columns would be read out of bounds (libc++ hardening abort in debug builds), so positions the format did not produce are skipped. `04829_lazy_materialization_hive_partition_defaults` asserted the old `UNKNOWN_IDENTIFIER`; it now checks the values. Related: ClickHouse#131975 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the header comment of addPartitionColumnsForDefaults (the name says it) and shorten two comments to the invariant they state. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings; 1 full pass).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261120-175200 |
|
Workflow [PR], commit [47a5f50] Summary: ✅
AI ReviewSummaryThe PR supplies Hive partition values to Findings❌ Blockers
Final VerdictStatus: ❌ Block Preserve the successful conditional read above, or add a versioned compatibility path and regression coverage. No new inline findings were posted; the remaining finding already has a thread and was explicitly dismissed. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes37 object files changed (+67.94 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units138 translation units recompiled, 1115 s compile time in total, 138 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
The previous commit added the Hive partition columns that a `DEFAULT` reads to the stream in front of `AddingDefaultsTransform`, converting the path value when the file was opened. A read that never evaluates such a default then failed if the value does not fit the column's type or the path lacks the key: `SELECT d` over a file where `d` is always present, `SELECT c0` and `count()` over a `CSV` file (the format reads every column), or `SELECT d, e` where only the unrelated default of `e` is evaluated. Such reads worked before. `AddingDefaultsTransform` now takes a callback that builds extra inputs. It is called only for a chunk where some default is evaluated, with the columns those defaults read (transitively), and the Hive helper builds only the partition columns among them. The stream itself is unchanged, so the bound check on `BlockMissingValues` is no longer needed. Reported in ClickHouse#133299 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
`AddingDefaultsTransform` collects the columns a default reads and descends into the defaults of the ones the format does not produce, because those defaults are inlined into the evaluation. It also descended into the defaults of Hive partition columns, which the transform takes from the path instead, so their own inputs were built (and converted) too. For CSV with `c0 Int32, k String DEFAULT toString(q), q UInt32, d String DEFAULT k` and the path `k=abc/q=bad/f.csv`, `SELECT d` threw `TYPE_MISMATCH` converting `bad` to `UInt32` instead of returning `abc`. The transform now gets the columns the path supplies up front and treats them as available, like the header columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI review of a later commit does not approve the PR, see the AI Review comment.
…lumns A physical column named `k.value` can coexist with a Hive partition column `k`; the dot does not make it a subcolumn of `k`. Both the collection in `prepareReadingFromFormat` and the per-chunk filter of `makePartitionColumnsForDefaults` matched by name prefix, so a default that reads `k.value` converted the unrelated path value of `k`, and an unconvertible key (`k=abc`, `k UInt32`) failed a read that 26.10.5.57 returns. `prepareReadingFromFormat` now resolves each identifier of a default with `tryGetColumnOrSubcolumn` on the storage columns (exact names first, then subcolumns) and records the Hive columns among the results. `AddingDefaultsTransform` resolves subcolumns of the extra inputs too (a Hive column is not in the format's columns description), so the names it passes to the callback are columns, and the callback matches them exactly. The defaults are evaluated over the read columns, so a default over an unread physical `k.null` would resolve to the null map of a Nullable Hive `k` given to another default, and return `0` where master fails with `UNKNOWN_IDENTIFIER`. A Hive column with a subcolumn of the same name as such an unread column is not given to the defaults, which keeps master's behaviour there. 05839 gets the reported CSV case, one where another default that reads `k` is populated, which only the exact filter keeps from converting `k`, and the unread `k.null` case over JSONEachRow. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In the AsyncInsert job the `INSERT INTO FUNCTION s3(s3_conn, filename = currentDatabase() || ...) VALUES` fixture write is queued and flushed in a context without the session database, so `currentDatabase()` evaluates to `default` there and the object lands at `default/k=abc/f.jsonl`. The following `s3()` read of `<test db>/k=abc/f.jsonl` then fails with `S3_ERROR` 404 (deterministic: 11/11 and 48/48 in the CI diagnosis). The `file()` writes are not affected: their path argument is folded to a literal before the flush. Same remedy as 05315 (4ab8ff6): set `async_insert = 0` on that INSERT. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵️ @groeneai The fix works on the CI build of 47a5f50. With the Hive columns listed in the structure, all 48 combinations I ran return the right values:
On master all of them fail with One gap: a Hive column that is not in the structure. With -- data/k=abc/n=5/dt=2020-01-05/f.jsonl holds {"c0":1,"d":"x"} and {"c0":2}
SELECT c0, k FROM file('data/k=*/n=*/dt=*/f.jsonl', JSONEachRow, 'c0 Int32') SETTINGS use_hive_partitioning = 1;
-- 1 abc, ...
SELECT c0, d FROM file('data/k=*/n=*/dt=*/f.jsonl', JSONEachRow, 'c0 Int32, d String DEFAULT k') SETTINGS use_hive_partitioning = 1;
-- Code: 47. Unknown expression or function identifier `k` ... In scope SELECT _CAST(k, 'String') AS d, ...It is the same for |
|
Yes, this is intended, and it does not come from the read path. The structure is rejected while it is parsed, before any file is listed: Listing the column works with any type. On your files, A clearer error needs the path's keys when the structure is parsed, and they are not known there yet. It would be a separate change to the table functions, which I can do if you want it. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed reading a column whose
DEFAULTexpression uses a Hive partition column (use_hive_partitioningorpartition_strategy = 'hive') fromfile,url,s3,azureBlobStorage,hdfs, their*Clustervariants, the matching table engines andS3Queue/AzureQueue: such a query failed withUNKNOWN_IDENTIFIER, or returned the type default for formats that read every column, such asCSV.Description
On 26.8.18.2 and 26.10.5.57,
SELECT * FROM file('data/k=*/f.jsonl', JSONEachRow, 'c0 Int32, k String, d String DEFAULT k') SETTINGS use_hive_partitioning = 1fails withUNKNOWN_IDENTIFIER k, and the same read of a CSV file returns an emptydinstead ofabc. ForS3Queuethe file is markedFailedand its rows are never ingested. Reported on #131975 (#131975 (comment)).Cause:
StorageObjectStorageSource,StorageFileandStorageURLevaluate defaults (AddingDefaultsTransform) inside the per-file reader, but append the Hive columns only after it, and the format never reads them (#87515).Change:
prepareReadingFromFormatrecords the Hive columns that aDEFAULTreads (hive_partition_columns_read_by_defaults, subcolumns included, an exact column name such ask.valuefirst). The three readers pass them through one helper,HivePartitioningUtils::makePartitionColumnsForDefaults, toAddingDefaultsTransform, which builds them as constants from the file's path only for a chunk where it evaluates a default that reads them, and adds them only to the block the defaults are computed from. Their ownDEFAULTs are not used, and a path value that does not fit the type fails the read, asSELECT kdoes. A read that needs no such default behaves as before, even if the path lacks the key or holds a value that does not fit its type.Tests: new
05839_hive_partition_column_in_default(file JSONEachRow/CSV, s3, url, unselected and transitive cases, a Hive column with its ownDEFAULT, columns namedk.valueandk.null, and reads that need no such default over a key that does not fit its type or is missing);04829_lazy_materialization_hive_partition_defaultsasserted the oldUNKNOWN_IDENTIFIERand now checks the values. Also verified locally: S3Queue materialized view,fileCluster/s3Cluster/urlCluster, Parquet with PREWHERE and lazy materialization.Not changed: a
DEFAULTover a file column the query does not read fails the same way for any column kind; the legacyHiveengine has the same ordering in its own reader.Workflow [PR]
Sync PR [sync-upstream/pr/133299]