Repository navigation
Description
Describe what's wrong
- Selecting
key.null/key.sizeof a Hive partition column reads values from the file, not the path. - Triggered by selecting only a subcolumn of a partition column, e.g.
key.null,key.sizewithuse_hive_partitioning = 1. - Expected both rows to show
key.null = 0andkey.size = 3from the path valueabc. - Instead values vary per row and are inconsistent with
keyitself, e.g.key.null = 1whilekeyisabc.
Root cause: In prepareReadingFromFormat.cpp:132, the block refilling an empty format_header fires whenever the header is empty, not only for the partition-only case it was meant for; requesting just a subcolumn of a partition column also empties the header, so key gets read from the file and key.null/key.size are derived from that file value instead of the path.
Analysis details (evidence, affected locations, impact)
Why we believe this is a bug: - key.null is not a key of hive_partition_columns_to_read_from_file_path_map (prepareReadingFromFormat.cpp:54, exact-name lookup), so it lands in columns_to_read, is widened to the storage column key, and line 127 drops key from format_header.
- The new block (
prepareReadingFromFormat.cpp:132-134) refills the empty header withcolumns_description, i.e.keyfrom the file;ExtractColumnsTransformderiveskey.null/key.sizefrom the file values, thenkeyis appended from the path. formatReadsHivePartitionColumnsstays false (keyis not in the requested partition list), so Fix 0 rows from Hive-partitioned files when a query needs no column of the data file #123381 (where this was found; not confirmed as the cause)'s filter / top-K guard does not see this header either.
Affected locations:
src/Storages/prepareReadingFromFormat.cpp:132— new block refills an empty header with partition columns read from the filesrc/Storages/prepareReadingFromFormat.cpp:54— partition columns matched by exact name;key.nullis treated as a file columnsrc/Storages/prepareReadingFromFormat.cpp:358—formatReadsHivePartitionColumnsmisses partition columns that were not requested by name
Impact: A query that selects a subcolumn of a Hive partition column (.null, .size, ...) and no other file column gets values computed from the data file instead of the path, inconsistent with the column itself in the same row. Before #123381 (where this was found; not confirmed as the cause) it failed with NOT_FOUND_COLUMN_IN_BLOCK.
Does it reproduce on most recent release?
Confirmed on master (4127c65654d0); not checked on a release.
How to reproduce
Requires use_hive_partitioning = 1 and a file path containing key=abc, with the data file holding differing values for key.
-- A subcolumn of a hive partition column must be taken from the value in the path, like the column itself.
INSERT INTO FUNCTION file(currentDatabase() || '/05321/key=abc/data.jsonl', JSONEachRow, 's String, key Nullable(String)') SETTINGS engine_file_truncate_on_insert = 1 VALUES ('x', NULL), ('y', 'zz');
SET use_hive_partitioning = 1;
SELECT key, key.null, key.size FROM file(currentDatabase() || '/05321/key=abc/data.jsonl', JSONEachRow, 's String, key Nullable(String)') ORDER BY ALL;Verified: this block reproduces on current master (4127c65654d0) when pasted as is.
Expected behavior
key.null and key.size should be derived from the same path-derived value as key, giving consistent results across rows.
Expected output of the reproducer above:
abc 0 3
abc 0 3
Error message and/or stacktrace
key.null and key.size are computed from the file's data for key, giving values that contradict the path-derived key.
Actual output of the reproducer above on master (4127c65654d0):
abc 0 2
abc 1 \N
Suggested fix
Refill the header only in the fallback that found no non-partition candidate (set a flag in the columns_to_read.empty() branch), and resolve a requested subcolumn of a partition column from the path value, or reject it, instead of widening it to the file column. Rejecting restores the 26.x exception; resolving from the path needs subcolumn extraction after addPartitionColumnsToChunk.
Additional context
Same pattern as #87515 (found by: vector, fix_path; vector: cosine distance 0.23).
Found during automated review of PR #123381; whether that PR introduced it could not be established, so nobody is tagged. Severity P3 · Finding h_pr123381_002
Activity