Skip to content

Subcolumn of Hive partition column read from file instead of path #123718

Description

@clickgapai

Describe what's wrong

  • Selecting key.null/key.size of 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.size with use_hive_partitioning = 1.
  • Expected both rows to show key.null = 0 and key.size = 3 from the path value abc.
  • Instead values vary per row and are inconsistent with key itself, e.g. key.null = 1 while key is abc.

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 with columns_description, i.e. key from the file; ExtractColumnsTransform derives key.null / key.size from the file values, then key is appended from the path.
  • formatReadsHivePartitionColumns stays false (key is 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:

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.

▶ Run on ClickHouse Fiddle

-- 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

  1. added
    comp-table-functions
    on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai_p2comp-table-functions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions