Fix assertion failure in IfTransformStringsToEnumPass for Nullable result types#97002
Open
alexey-milovidov wants to merge 2 commits intomasterfrom
Open
Fix assertion failure in IfTransformStringsToEnumPass for Nullable result types#97002alexey-milovidov wants to merge 2 commits intomasterfrom
alexey-milovidov wants to merge 2 commits intomasterfrom
Conversation
…result types The `if` branch of `IfTransformStringsToEnumPass` was missing a check on the function result type before attempting the string-to-enum optimization. When `group_by_use_nulls = true` is combined with `GROUP BY ... WITH CUBE`, the `if` function's result type becomes `Nullable(String)` instead of `String`. The optimization then wraps into `toString`, which returns `Nullable(String)`, triggering the debug assertion `isString(function_node.getResultType())`. The `transform` branch already had this guard (line 157). Added the same `isString(function_node->getResultType())` check to the `if` branch. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96712&sha=ebc729143128f68f2f99c7a88691dc085c4574d0&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Workflow [PR], commit [6c06367] Summary: ⏳
|
| @@ -0,0 +1,8 @@ | |||
| -- Regression test: IfTransformStringsToEnumPass should not crash when | |||
Member
Author
There was a problem hiding this comment.
The test reproduces the issue.
The previous fix (adding `isString` check on the `if` branch) caused a mismatch between GROUP BY key and projection expressions when `group_by_use_nulls` is used with CUBE/ROLLUP. The analyzer clones GROUP BY keys for the projection and calls `convertToNullable` on the clones, setting `wrap_with_nullable = true`. The `isString` check would skip the optimization for the projection node (Nullable(String)) but apply it to the GROUP BY key (String), creating a structural mismatch that causes NOT_FOUND_COLUMN_IN_BLOCK errors. The correct fix: allow the optimization to run on both nodes consistently, and fix the assertion in `wrapIntoToString` to accept `Nullable(String)` via `removeNullable`. Also fix the `transform` branch's `isString` check similarly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
IfTransformStringsToEnumPassassertionassert(isString(function_node.getResultType()))inwrapIntoToStringfails whengroup_by_use_nulls = 1is used withGROUP BY ... WITH CUBE/ROLLUP.Root cause: When
group_by_use_nullsis enabled with CUBE/ROLLUP, the analyzer clones GROUP BY key expressions for the projection and callsconvertToNullableon the clones, settingwrap_with_nullable = trueon theFunctionNode. This makesgetResultType()returnNullable(String)for the projection copy while the GROUP BY key retains typeString. After the optimization transforms theiftotoString(if(..., Enum, Enum)), the assertionisString(...)fails becausetoString(Nullable(Enum8))returnsNullable(String).Fix: Use
removeNullablein the assertion to accept bothStringandNullable(String). The optimization is applied consistently to both the GROUP BY key and projection nodes, preserving structural equality so the planner can match them. Also apply the sameremoveNullablefix to thetransformbranch's result type check.Reproducer query from the AST fuzzer:
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96712&sha=ebc729143128f68f2f99c7a88691dc085c4574d0&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix assertion failure in
IfTransformStringsToEnumPasswhen theifortransformfunction returnsNullable(String)(e.g. withGROUP BY ... WITH CUBEandgroup_by_use_nulls = true).🤖 Generated with Claude Code