Merge pull request #57622 from ClickHouse/vdimir/analyzer_multiif_logical_err

Analyzer: Fix logical error in MultiIfToIfPass
This commit is contained in:
vdimir 2023-12-08 10:28:55 +01:00 committed by GitHub
commit 86bdd883f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -33,8 +33,17 @@ public:
if (function_node->getArguments().getNodes().size() != 3)
return;
auto result_type = function_node->getResultType();
function_node->resolveAsFunction(if_function_ptr->build(function_node->getArgumentColumns()));
auto if_function_value = if_function_ptr->build(function_node->getArgumentColumns());
if (!if_function_value->getResultType()->equals(*function_node->getResultType()))
{
/** We faced some corner case, when result type of `if` and `multiIf` are different.
* For example, currently `if(NULL`, a, b)` returns type of `a` column,
* but multiIf(NULL, a, b) returns supertypetype of `a` and `b`.
*/
return;
}
function_node->resolveAsFunction(std::move(if_function_value));
}
private:

View File

@ -1 +1,3 @@
SELECT sum(A) FROM (SELECT multiIf(1, 1, NULL) as A);
SELECT sum(multiIf(number = NULL, 65536, 3)) FROM numbers(3);
SELECT multiIf(NULL, 65536 :: UInt32, 3 :: Int32);