Fix `flattenTuple` and `tupleToNameValuePairs` not propagating NULLs for `Nullable(Tuple)` by nihalzp · Pull Request #103383 · ClickHouse/ClickHouse · GitHub
Skip to content

Fix flattenTuple and tupleToNameValuePairs not propagating NULLs for Nullable(Tuple)#103383

Merged
nihalzp merged 8 commits into
ClickHouse:masterfrom
nihalzp:fix-flatten-nullable-tuple
May 16, 2026
Merged

Fix flattenTuple and tupleToNameValuePairs not propagating NULLs for Nullable(Tuple)#103383
nihalzp merged 8 commits into
ClickHouse:masterfrom
nihalzp:fix-flatten-nullable-tuple

Conversation

@nihalzp

@nihalzp nihalzp commented Apr 22, 2026

Copy link
Copy Markdown
Member

For tupleToNameValuePairs, old behavior is not completely irrational but I feel the new semantics make more sense.

SET allow_experimental_nullable_tuple_type = 1;

SELECT flattenTuple(CAST(NULL AS Nullable(Tuple(a UInt32, b Tuple(c String)))));
-- Before: (0,'')
-- After:  \N

SELECT tupleToNameValuePairs(CAST(NULL AS Nullable(Tuple(a UInt32, b UInt32))));
-- Before: [('a',0),('b',0)]
-- After:  [('a',NULL),('b',NULL)]

-- Element cannot be inside Nullable, so emit default.
SELECT tupleToNameValuePairs(CAST(NULL AS Nullable(Tuple(a Array(UInt32), b Array(UInt32)))));
-- Unchanged: [('a',[]),('b',[])]       — return type Array(Tuple(String, Array(UInt32)))

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix incorrect handling of NULL rows for Nullable(Tuple(...)) inputs in flattenTuple and tupleToNameValuePairs. flattenTuple now preserves the outer null map so NULL rows stay NULL. tupleToNameValuePairs now changes the result's value type to Nullable(T) when possible when the input is Nullable(Tuple(...)), so NULL rows produce [('a', NULL), ('b', NULL)] instead of [('a', 0), ('b', 0)]. When the element type cannot be wrapped in Nullable (e.g. Array), default values are used instead of NULL. Closes #103312.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.702

@clickhouse-gh

clickhouse-gh Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 22, 2026
@Avogar Avogar self-assigned this Apr 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 76.60% 76.50% -0.10%

Changed lines: 97.78% (44/45) · Uncovered code

Full report · Diff report

@nihalzp nihalzp added this pull request to the merge queue May 16, 2026
Merged via the queue into ClickHouse:master with commit e5abec9 May 16, 2026
328 of 330 checks passed
@nihalzp nihalzp deleted the fix-flatten-nullable-tuple branch May 16, 2026 07:14
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flattenTuple discards null map from Nullable(Tuple) columns via removeNullable, returns default values instead of NULL

3 participants