Merge pull request #62059 from ClickHouse/fix-type-after-IfChainToMultiIfPass

Ignore IfChainToMultiIfPass if returned type changed.
This commit is contained in:
Nikolai Kochetov 2024-03-29 19:26:55 +01:00 committed by GitHub
commit dc45666b4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 0 deletions

View File

@ -65,6 +65,12 @@ public:
auto multi_if_function = std::make_shared<FunctionNode>("multiIf");
multi_if_function->getArguments().getNodes() = std::move(multi_if_arguments);
multi_if_function->resolveAsFunction(multi_if_function_ptr->build(multi_if_function->getArgumentColumns()));
/// Ignore if returned type changed.
/// Example : SELECT now64(if(Null, NULL, if(Null, nan, toFloat64(number))), Null) FROM numbers(2)
if (!multi_if_function->getResultType()->equals(*function_node->getResultType()))
return;
node = std::move(multi_if_function);
}

View File

@ -2,3 +2,5 @@ SELECT if(number = 1, \'hello\', if(number = 2, \'world\', \'xyz\'))
FROM numbers(10)
SELECT multiIf(number = 1, \'hello\', number = 2, \'world\', \'xyz\')
FROM numbers(10)
\N
\N

View File

@ -3,3 +3,6 @@ SET optimize_if_chain_to_multiif = 0;
EXPLAIN SYNTAX SELECT number = 1 ? 'hello' : (number = 2 ? 'world' : 'xyz') FROM numbers(10);
SET optimize_if_chain_to_multiif = 1;
EXPLAIN SYNTAX SELECT number = 1 ? 'hello' : (number = 2 ? 'world' : 'xyz') FROM numbers(10);
-- fuzzed
SELECT now64(if(Null, NULL, if(Null, nan, toFloat64(number))), Null) FROM numbers(2);