Skip to content

Fix column node make nullable - #95657

Merged
alexey-milovidov merged 14 commits into
masterfrom
fix-column-node-make-nullable
May 19, 2026
Merged

alexey-milovidov merged 14 commits into
masterfrom
fix-column-node-make-nullable

Conversation

@novikd

@novikd novikd commented Jan 30, 2026 •

Copy link
Copy Markdown
Member

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 column with LowCardinality type conversion to Nullable when group_by_use_nulls is enabled. Fixes #95299.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Changes nullability conversion in analyzer/planner and aggregation execution to treat LowCardinality columns correctly, which can affect result types and GROUP BY WITH ROLLUP/CUBE output schemas. Scope is small and covered by a new regression test, but it touches core aggregation/type-handling paths.

Overview
Fixes group_by_use_nulls handling so converting GROUP BY keys/results to Nullable also works for LowCardinality types by switching several call sites from makeNullableSafe to makeNullableOrLowCardinalityNullableSafe (query tree nodes, planner aggregation-key typing, and rollup/aggregation headers/columns).

Adds a stateless regression test exercising LowCardinality(String) with GROUP BY ... WITH ROLLUP SETTINGS group_by_use_nulls=1, asserting the rolled-up key becomes NULL as expected.

Written by Cursor Bugbot for commit 37102b7. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.5.1.827

@clickhouse-gh

clickhouse-gh Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7ed0ef4]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) FAIL
02180_group_by_lowcardinality FAIL cidb
Stateless tests (arm_asan_ubsan, azure, parallel) FAIL
01910_view_dictionary_check_refresh FAIL cidb

AI Review

Summary

This PR fixes group_by_use_nulls nullability handling for LowCardinality keys across analyzer and legacy paths, plus ROLLUP/CUBE/GROUPING SETS execution paths, and adds focused regression coverage for both enable_analyzer = 1 and enable_analyzer = 0. I reviewed the current diff and prior discussion threads; I did not find any remaining live correctness, safety, or performance issues in the changed code.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jan 30, 2026
@serxa serxa self-assigned this Jan 30, 2026
@serxa

serxa commented Jan 30, 2026

Copy link
Copy Markdown
Member

code seems good, but test fails for some reason

@alexey-milovidov

Copy link
Copy Markdown
Member

@novikd, tests have failed.

@novikd
novikd force-pushed the fix-column-node-make-nullable branch from 8e291c7 to a1c9b2f Compare March 5, 2026 14:18

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread src/Analyzer/ColumnNode.h Resolved
alexey-milovidov and others added 4 commits May 16, 2026 14:13
… and WITH CUBE

When `group_by_use_nulls=1`, the `AggregatingStep` output header is built via
`convertToNullable` which (after this PR) correctly maps a `LowCardinality(T)`
key to `LowCardinality(Nullable(T))`. However, the actions DAG built in
`makeCreatingMissingKeysForGroupingSetDAG` (`AggregatingStep`) and
`addGroupingSetForTotals` (`CubeStep`) guarded the `toNullable` insertion with
`canBeInsideNullable`, which returns `false` for `LowCardinality` — so for
`LowCardinality` keys the column flowed through unchanged as `LowCardinality(T)`,
producing a logical error such as `Block structure mismatch in A stream:
different types` in `AggregatingStep::transformPipeline` and
`CubeStep::transformPipeline`.

Use `removeLowCardinality(...)->canBeInsideNullable()` (the pattern already used
in `JoinStepLogical`) so that `LowCardinality` keys are routed through
`toNullable` as well, keeping the pipeline header consistent with the actual
chunk types.

Also extend `03821_analyzer_group_by_use_nulls` with `GROUPING SETS` and
`WITH CUBE` cases for both `LowCardinality(String)` and `LowCardinality(UInt16)`,
which are the failing combinations reported by Stress tests on
#95657 (commit cf5fec0).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The previous version of the regression test for the LowCardinality + GROUPING
SETS / WITH CUBE crash used a single-key GROUPING SETS with an empty `()`
set, which collapses on aggregation and does not hit the missing-keys
`makeCreatingMissingKeysForGroupingSetDAG` path. Replace it with a two-key
table (`LowCardinality(UInt16)` × 2) and use `GROUPING SETS ((a, b), (a))`
plus `WITH CUBE` / `WITH ROLLUP` on both keys — these all touch the failing
code paths reported in #95657:

- `AggregatingStep::transformPipeline` / `makeCreatingMissingKeysForGroupingSetDAG`
- `CubeStep::transformPipeline` / `addGroupingSetForTotals`

Verified by temporarily reverting the C++ fix: without it, the GROUPING SETS
case throws `Block structure mismatch in Pipe stream: different types:
__table1.b LowCardinality(UInt16) ... __table1.b LowCardinality(Nullable(UInt16))`
— matching the Stress test failure from the CI report on commit cf5fec0.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The analyzer/planner side of the fix made `convertToNullable` and the
pre-aggregation key types correctly map `LowCardinality(T)` to
`LowCardinality(Nullable(T))` under `group_by_use_nulls`. The legacy planner
had the analogous issue: in `ExpressionAnalyzer::analyzeAggregation`
(both the explicit grouping-set and the regular paths) and in
`InterpreterSelectQuery::getSampleBlockImpl` the aggregation-key type was
computed via `makeNullableSafe`, which is a no-op for `LowCardinality(T)`.

The runtime pipeline (`AggregatingStep`, `RollupTransform`,
`CubeTransform`, the missing-keys DAG) still ultimately wraps such keys
in `Nullable`, which then triggered
`CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN: Cannot convert NULL value to
non-Nullable type: while converting source column ... LowCardinality(UInt16)`
on `ROLLUP/CUBE/GROUPING SETS` with `enable_analyzer = 0`.

Switch those three legacy call sites to `makeNullableOrLowCardinalityNullableSafe`
so both planners stay consistent, and extend `03821_analyzer_group_by_use_nulls`
with `enable_analyzer = 0` variants for every modifier
(`WITH ROLLUP`, `WITH CUBE`, `GROUPING SETS`) — addresses the unresolved
review comment from the AI reviewer on
#95657.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

This was fixed by #105146. Let's update the branch.

@clickhouse-gh

clickhouse-gh Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.20% 84.10% -0.10%
Functions 91.40% 91.40% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 97.56% (40/41) | lost baseline coverage: 6 line(s) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov merged commit fa788c5 into master May 19, 2026
162 of 167 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-column-node-make-nullable branch May 19, 2026 13:33
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 19, 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.

group_by_use_nulls produces empty string instead of NULL for LowCardinality columns

4 participants