From 44f6b22a5504518d9704b60596bfccff758ab8b5 Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Mon, 20 Jul 2015 18:04:40 +0300 Subject: [PATCH] dbms: fix function if() and ternary operator for same types. [#METR-17372] --- dbms/include/DB/Functions/FunctionsConditional.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dbms/include/DB/Functions/FunctionsConditional.h b/dbms/include/DB/Functions/FunctionsConditional.h index ddcf0de80ba..31b1c50ebd8 100644 --- a/dbms/include/DB/Functions/FunctionsConditional.h +++ b/dbms/include/DB/Functions/FunctionsConditional.h @@ -1315,7 +1315,7 @@ public: /// NOTE Сообщения об ошибках будут относится к типам элементов массивов, что немного некорректно. return new DataTypeArray(getReturnType({arguments[0], type_arr1->getNestedType(), type_arr2->getNestedType()})); } - else + else if (arguments[1]->getName() != arguments[2]->getName()) { const DataTypeString * type_string1 = typeid_cast(arguments[1].get()); const DataTypeString * type_string2 = typeid_cast(arguments[2].get()); @@ -1334,11 +1334,15 @@ public: { return new DataTypeString; } + + throw Exception{ + "Incompatible second and third arguments for function " + getName() + ": " + + arguments[1]->getName() + " and " + arguments[2]->getName(), + ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT + }; } - throw Exception("Incompatible second and third arguments for function " + getName() + ": " - + arguments[1]->getName() + " and " + arguments[2]->getName(), - ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + return arguments[1]; } /// Выполнить функцию над блоком.