From d17a49f127b59348299963fde4fb7368007f4f8f Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenkov Date: Fri, 23 Oct 2020 15:20:07 +0300 Subject: [PATCH 1/3] Add more context to error messages --- src/Interpreters/InDepthNodeVisitor.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Interpreters/InDepthNodeVisitor.h b/src/Interpreters/InDepthNodeVisitor.h index 3e0a8e16185..7b537f0daa0 100644 --- a/src/Interpreters/InDepthNodeVisitor.h +++ b/src/Interpreters/InDepthNodeVisitor.h @@ -29,7 +29,15 @@ public: if constexpr (!_top_to_bottom) visitChildren(ast); - Matcher::visit(ast, data); + try + { + Matcher::visit(ast, data); + } + catch (Exception & e) + { + e.addMessage("While processing {}", ast->formatForErrorMessage()); + throw; + } if constexpr (_top_to_bottom) visitChildren(ast); From b0a14a41c384f3544405d848bb46be1eb3dc5025 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenkov Date: Fri, 23 Oct 2020 17:28:55 +0300 Subject: [PATCH 2/3] fixup --- src/Functions/if.cpp | 72 +++-- src/Interpreters/ExpressionActions.cpp | 2 + .../00921_datetime64_compatibility.reference | 302 +++++++++--------- .../00921_datetime64_compatibility.sh | 2 +- 4 files changed, 194 insertions(+), 184 deletions(-) diff --git a/src/Functions/if.cpp b/src/Functions/if.cpp index dd67f922ddf..8f7647a8899 100644 --- a/src/Functions/if.cpp +++ b/src/Functions/if.cpp @@ -154,22 +154,6 @@ struct NumIfImpl, Decimal, Decimal> } }; -template -struct NumIfImpl -{ -private: - [[noreturn]] static void throwError() - { - throw Exception("Invalid types of arguments 2 and 3 of if", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } -public: - template static void vectorVector(Args &&...) { throwError(); } - template static void vectorConstant(Args &&...) { throwError(); } - template static void constantVector(Args &&...) { throwError(); } - template static void constantConstant(Args &&...) { throwError(); } -}; - - class FunctionIf : public FunctionIfBase { public: @@ -205,17 +189,29 @@ private: const IColumn * col_right_untyped = columns[arguments[2]].column.get(); UInt32 scale = decimalScale(columns, arguments); - if (const auto * col_right_vec = checkAndGetColumn(col_right_untyped)) + if constexpr (std::is_same_v) { - NumIfImpl::vectorVector( - cond_col->getData(), col_left->getData(), col_right_vec->getData(), columns, result, scale); - return true; + const auto & arg_left = columns[arguments[1]]; + const auto & arg_right = columns[arguments[2]]; + throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Incompatible types of arguments of function {}:" + " '{}' and '{}'", getName(), arg_left.type->getName(), + arg_right.type->getName()); } - else if (const auto * col_right_const = checkAndGetColumnConst(col_right_untyped)) + else { - NumIfImpl::vectorConstant( - cond_col->getData(), col_left->getData(), col_right_const->template getValue(), columns, result, scale); - return true; + if (const auto * col_right_vec = checkAndGetColumn(col_right_untyped)) + { + NumIfImpl::vectorVector( + cond_col->getData(), col_left->getData(), col_right_vec->getData(), columns, result, scale); + return true; + } + else if (const auto * col_right_const = checkAndGetColumnConst(col_right_untyped)) + { + NumIfImpl::vectorConstant( + cond_col->getData(), col_left->getData(), col_right_const->template getValue(), columns, result, scale); + return true; + } } return false; @@ -234,17 +230,29 @@ private: const IColumn * col_right_untyped = columns[arguments[2]].column.get(); UInt32 scale = decimalScale(columns, arguments); - if (const auto * col_right_vec = checkAndGetColumn(col_right_untyped)) + if constexpr (std::is_same_v) { - NumIfImpl::constantVector( - cond_col->getData(), col_left->template getValue(), col_right_vec->getData(), columns, result, scale); - return true; + const auto & arg_left = columns[arguments[1]]; + const auto & arg_right = columns[arguments[2]]; + throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Incompatible types of arguments of function {}:" + " '{}' and '{}'", getName(), arg_left.type->getName(), + arg_right.type->getName()); } - else if (const auto * col_right_const = checkAndGetColumnConst(col_right_untyped)) + else { - NumIfImpl::constantConstant( - cond_col->getData(), col_left->template getValue(), col_right_const->template getValue(), columns, result, scale); - return true; + if (const auto * col_right_vec = checkAndGetColumn(col_right_untyped)) + { + NumIfImpl::constantVector( + cond_col->getData(), col_left->template getValue(), col_right_vec->getData(), columns, result, scale); + return true; + } + else if (const auto * col_right_const = checkAndGetColumnConst(col_right_untyped)) + { + NumIfImpl::constantConstant( + cond_col->getData(), col_left->template getValue(), col_right_const->template getValue(), columns, result, scale); + return true; + } } return false; diff --git a/src/Interpreters/ExpressionActions.cpp b/src/Interpreters/ExpressionActions.cpp index 1bb2fd8e96b..6432ae90809 100644 --- a/src/Interpreters/ExpressionActions.cpp +++ b/src/Interpreters/ExpressionActions.cpp @@ -316,6 +316,7 @@ void ExpressionAction::prepare(Block & sample_block, const Settings & settings, { auto & result = sample_block.getByName(result_name); result.type = result_type; + result.name = result_name; result.column = source.column; } else @@ -1561,6 +1562,7 @@ const ActionsDAG::Node & ActionsDAG::addFunction( ColumnWithTypeAndName argument; argument.column = child.column; argument.type = child.result_type; + argument.name = child.result_name; if (!argument.column || !isColumnConst(*argument.column)) all_const = false; diff --git a/tests/queries/0_stateless/00921_datetime64_compatibility.reference b/tests/queries/0_stateless/00921_datetime64_compatibility.reference index a42517104b9..398da88e460 100644 --- a/tests/queries/0_stateless/00921_datetime64_compatibility.reference +++ b/tests/queries/0_stateless/00921_datetime64_compatibility.reference @@ -1,6 +1,6 @@ SELECT toTimeZone(N, \'UTC\') -Code: 43: Illegal type Date of argument of function toTimeZone. Should be DateTime or DateTime64. +Code: 43 "DateTime('UTC')","2019-09-16 16:20:11" "DateTime64(3, 'UTC')","2019-09-16 16:20:11.234" ------------------------------------------ @@ -36,19 +36,19 @@ SELECT toDayOfWeek(N) ------------------------------------------ SELECT toHour(N) -Code: 43: Illegal type Date of argument for function toHour. +Code: 43 "UInt8",19 "UInt8",19 ------------------------------------------ SELECT toMinute(N) -Code: 43: Illegal type Date of argument for function toMinute. +Code: 43 "UInt8",20 "UInt8",20 ------------------------------------------ SELECT toSecond(N) -Code: 43: Illegal type Date of argument for function toSecond. +Code: 43 "UInt8",11 "UInt8",11 ------------------------------------------ @@ -94,31 +94,31 @@ SELECT toStartOfDay(N) ------------------------------------------ SELECT toStartOfHour(N) -Code: 43: Illegal type Date of argument for function toStartOfHour. +Code: 43 "DateTime('Europe/Minsk')","2019-09-16 19:00:00" "DateTime('Europe/Minsk')","2019-09-16 19:00:00" ------------------------------------------ SELECT toStartOfMinute(N) -Code: 43: Illegal type Date of argument for function toStartOfMinute. +Code: 43 "DateTime('Europe/Minsk')","2019-09-16 19:20:00" "DateTime('Europe/Minsk')","2019-09-16 19:20:00" ------------------------------------------ SELECT toStartOfFiveMinute(N) -Code: 43: Illegal type Date of argument for function toStartOfFiveMinute. +Code: 43 "DateTime('Europe/Minsk')","2019-09-16 19:20:00" "DateTime('Europe/Minsk')","2019-09-16 19:20:00" ------------------------------------------ SELECT toStartOfTenMinutes(N) -Code: 43: Illegal type Date of argument for function toStartOfTenMinutes. +Code: 43 "DateTime('Europe/Minsk')","2019-09-16 19:20:00" "DateTime('Europe/Minsk')","2019-09-16 19:20:00" ------------------------------------------ SELECT toStartOfFifteenMinutes(N) -Code: 43: Illegal type Date of argument for function toStartOfFifteenMinutes. +Code: 43 "DateTime('Europe/Minsk')","2019-09-16 19:15:00" "DateTime('Europe/Minsk')","2019-09-16 19:15:00" ------------------------------------------ @@ -139,7 +139,7 @@ SELECT toStartOfInterval(N, INTERVAL 1 day) ------------------------------------------ SELECT toStartOfInterval(N, INTERVAL 15 minute) -Code: 43: Illegal type Date of argument for function toStartOfInterval. +Code: 43 "DateTime('Europe/Minsk')","2019-09-16 19:15:00" "DateTime('Europe/Minsk')","2019-09-16 19:15:00" ------------------------------------------ @@ -160,13 +160,13 @@ SELECT date_trunc(\'day\', N) ------------------------------------------ SELECT date_trunc(\'minute\', N) -Code: 43: Illegal type Date of argument for function date_trunc. +Code: 43 "DateTime('Europe/Minsk')","2019-09-16 19:20:00" "DateTime('Europe/Minsk')","2019-09-16 19:20:00" ------------------------------------------ SELECT toTime(N) -Code: 43: Illegal type Date of argument for function toTime. +Code: 43 "DateTime('Europe/Minsk')","1970-01-02 19:20:11" "DateTime('Europe/Minsk')","1970-01-02 19:20:11" ------------------------------------------ @@ -232,7 +232,7 @@ SELECT toYearWeek(N) ------------------------------------------ SELECT timeSlot(N) -Code: 43: Illegal type Date of argument for function timeSlot. +Code: 43 "DateTime('Europe/Minsk')","2019-09-16 19:00:00" "DateTime('Europe/Minsk')","2019-09-16 19:00:00" ------------------------------------------ @@ -375,15 +375,15 @@ SELECT N - N "Int32",0 "Int32",0 -Code: 43: Illegal types DateTime64(3, 'Europe/Minsk') and DateTime64(3, 'Europe/Minsk') of arguments of function minus. +Code: 43 ------------------------------------------ SELECT N + N -Code: 43: Illegal types Date and Date of arguments of function plus. +Code: 43 -Code: 43: Illegal types DateTime('Europe/Minsk') and DateTime('Europe/Minsk') of arguments of function plus. +Code: 43 -Code: 43: Illegal types DateTime64(3, 'Europe/Minsk') and DateTime64(3, 'Europe/Minsk') of arguments of function plus. +Code: 43 ------------------------------------------ SELECT N != N "UInt8",0 @@ -417,47 +417,47 @@ SELECT N >= N ------------------------------------------ SELECT N - DT -Code: 43: Illegal types Date and DateTime('Europe/Minsk') of arguments of function minus. +Code: 43 "Int32",0 -Code: 43: Illegal types DateTime64(3, 'Europe/Minsk') and DateTime('Europe/Minsk') of arguments of function minus. +Code: 43 ------------------------------------------ SELECT DT - N -Code: 43: Illegal types DateTime('Europe/Minsk') and Date of arguments of function minus. +Code: 43 "Int32",0 -Code: 43: Illegal types DateTime('Europe/Minsk') and DateTime64(3, 'Europe/Minsk') of arguments of function minus. +Code: 43 ------------------------------------------ SELECT N - D "Int32",0 -Code: 43: Illegal types DateTime('Europe/Minsk') and Date of arguments of function minus. +Code: 43 -Code: 43: Illegal types DateTime64(3, 'Europe/Minsk') and Date of arguments of function minus. +Code: 43 ------------------------------------------ SELECT D - N "Int32",0 -Code: 43: Illegal types Date and DateTime('Europe/Minsk') of arguments of function minus. +Code: 43 -Code: 43: Illegal types Date and DateTime64(3, 'Europe/Minsk') of arguments of function minus. +Code: 43 ------------------------------------------ SELECT N - DT64 -Code: 43: Illegal types Date and DateTime64(3, 'Europe/Minsk') of arguments of function minus. +Code: 43 -Code: 43: Illegal types DateTime('Europe/Minsk') and DateTime64(3, 'Europe/Minsk') of arguments of function minus. +Code: 43 -Code: 43: Illegal types DateTime64(3, 'Europe/Minsk') and DateTime64(3, 'Europe/Minsk') of arguments of function minus. +Code: 43 ------------------------------------------ SELECT DT64 - N -Code: 43: Illegal types DateTime64(3, 'Europe/Minsk') and Date of arguments of function minus. +Code: 43 -Code: 43: Illegal types DateTime64(3, 'Europe/Minsk') and DateTime('Europe/Minsk') of arguments of function minus. +Code: 43 -Code: 43: Illegal types DateTime64(3, 'Europe/Minsk') and DateTime64(3, 'Europe/Minsk') of arguments of function minus. +Code: 43 ------------------------------------------ SELECT N != DT "UInt8",1 @@ -726,11 +726,11 @@ SELECT N - toUInt8(1) ------------------------------------------ SELECT toUInt8(1) - N -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 ------------------------------------------ SELECT N - toInt8(-1) "Date","2019-09-17" @@ -739,11 +739,11 @@ SELECT N - toInt8(-1) ------------------------------------------ SELECT toInt8(-1) - N -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 ------------------------------------------ SELECT N - toUInt16(1) "Date","2019-09-15" @@ -752,11 +752,11 @@ SELECT N - toUInt16(1) ------------------------------------------ SELECT toUInt16(1) - N -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 ------------------------------------------ SELECT N - toInt16(-1) "Date","2019-09-17" @@ -765,11 +765,11 @@ SELECT N - toInt16(-1) ------------------------------------------ SELECT toInt16(-1) - N -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 ------------------------------------------ SELECT N - toUInt32(1) "Date","2019-09-15" @@ -778,11 +778,11 @@ SELECT N - toUInt32(1) ------------------------------------------ SELECT toUInt32(1) - N -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 ------------------------------------------ SELECT N - toInt32(-1) "Date","2019-09-17" @@ -791,11 +791,11 @@ SELECT N - toInt32(-1) ------------------------------------------ SELECT toInt32(-1) - N -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 ------------------------------------------ SELECT N - toUInt64(1) "Date","2019-09-15" @@ -804,11 +804,11 @@ SELECT N - toUInt64(1) ------------------------------------------ SELECT toUInt64(1) - N -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 ------------------------------------------ SELECT N - toInt64(-1) "Date","2019-09-17" @@ -817,585 +817,585 @@ SELECT N - toInt64(-1) ------------------------------------------ SELECT toInt64(-1) - N -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 -Code: 43: Wrong order of arguments for function minus: argument of type Interval cannot be first.. +Code: 43 ------------------------------------------ SELECT N == toUInt8(1) -Code: 43: Illegal types of arguments (Date, UInt8) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt8(1) == N -Code: 43: Illegal types of arguments (UInt8, Date) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N == toInt8(-1) -Code: 43: Illegal types of arguments (Date, Int8) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt8(-1) == N -Code: 43: Illegal types of arguments (Int8, Date) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N == toUInt16(1) -Code: 43: Illegal types of arguments (Date, UInt16) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt16(1) == N -Code: 43: Illegal types of arguments (UInt16, Date) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N == toInt16(-1) -Code: 43: Illegal types of arguments (Date, Int16) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt16(-1) == N -Code: 43: Illegal types of arguments (Int16, Date) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N == toUInt32(1) -Code: 43: Illegal types of arguments (Date, UInt32) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt32(1) == N -Code: 43: Illegal types of arguments (UInt32, Date) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N == toInt32(-1) -Code: 43: Illegal types of arguments (Date, Int32) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt32(-1) == N -Code: 43: Illegal types of arguments (Int32, Date) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N == toUInt64(1) -Code: 43: Illegal types of arguments (Date, UInt64) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt64(1) == N -Code: 43: Illegal types of arguments (UInt64, Date) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N == toInt64(-1) -Code: 43: Illegal types of arguments (Date, Int64) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt64(-1) == N -Code: 43: Illegal types of arguments (Int64, Date) of function equals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N != toUInt8(1) -Code: 43: Illegal types of arguments (Date, UInt8) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt8(1) != N -Code: 43: Illegal types of arguments (UInt8, Date) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N != toInt8(-1) -Code: 43: Illegal types of arguments (Date, Int8) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt8(-1) != N -Code: 43: Illegal types of arguments (Int8, Date) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N != toUInt16(1) -Code: 43: Illegal types of arguments (Date, UInt16) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt16(1) != N -Code: 43: Illegal types of arguments (UInt16, Date) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N != toInt16(-1) -Code: 43: Illegal types of arguments (Date, Int16) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt16(-1) != N -Code: 43: Illegal types of arguments (Int16, Date) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N != toUInt32(1) -Code: 43: Illegal types of arguments (Date, UInt32) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt32(1) != N -Code: 43: Illegal types of arguments (UInt32, Date) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N != toInt32(-1) -Code: 43: Illegal types of arguments (Date, Int32) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt32(-1) != N -Code: 43: Illegal types of arguments (Int32, Date) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N != toUInt64(1) -Code: 43: Illegal types of arguments (Date, UInt64) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt64(1) != N -Code: 43: Illegal types of arguments (UInt64, Date) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N != toInt64(-1) -Code: 43: Illegal types of arguments (Date, Int64) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt64(-1) != N -Code: 43: Illegal types of arguments (Int64, Date) of function notEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N < toUInt8(1) -Code: 43: Illegal types of arguments (Date, UInt8) of function less. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt8(1) < N -Code: 43: Illegal types of arguments (UInt8, Date) of function less. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N < toInt8(-1) -Code: 43: Illegal types of arguments (Date, Int8) of function less. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt8(-1) < N -Code: 43: Illegal types of arguments (Int8, Date) of function less. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N < toUInt16(1) -Code: 43: Illegal types of arguments (Date, UInt16) of function less. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt16(1) < N -Code: 43: Illegal types of arguments (UInt16, Date) of function less. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N < toInt16(-1) -Code: 43: Illegal types of arguments (Date, Int16) of function less. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt16(-1) < N -Code: 43: Illegal types of arguments (Int16, Date) of function less. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N < toUInt32(1) -Code: 43: Illegal types of arguments (Date, UInt32) of function less. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt32(1) < N -Code: 43: Illegal types of arguments (UInt32, Date) of function less. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N < toInt32(-1) -Code: 43: Illegal types of arguments (Date, Int32) of function less. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt32(-1) < N -Code: 43: Illegal types of arguments (Int32, Date) of function less. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N < toUInt64(1) -Code: 43: Illegal types of arguments (Date, UInt64) of function less. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt64(1) < N -Code: 43: Illegal types of arguments (UInt64, Date) of function less. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N < toInt64(-1) -Code: 43: Illegal types of arguments (Date, Int64) of function less. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt64(-1) < N -Code: 43: Illegal types of arguments (Int64, Date) of function less. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N <= toUInt8(1) -Code: 43: Illegal types of arguments (Date, UInt8) of function lessOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt8(1) <= N -Code: 43: Illegal types of arguments (UInt8, Date) of function lessOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N <= toInt8(-1) -Code: 43: Illegal types of arguments (Date, Int8) of function lessOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt8(-1) <= N -Code: 43: Illegal types of arguments (Int8, Date) of function lessOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N <= toUInt16(1) -Code: 43: Illegal types of arguments (Date, UInt16) of function lessOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt16(1) <= N -Code: 43: Illegal types of arguments (UInt16, Date) of function lessOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N <= toInt16(-1) -Code: 43: Illegal types of arguments (Date, Int16) of function lessOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt16(-1) <= N -Code: 43: Illegal types of arguments (Int16, Date) of function lessOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N <= toUInt32(1) -Code: 43: Illegal types of arguments (Date, UInt32) of function lessOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt32(1) <= N -Code: 43: Illegal types of arguments (UInt32, Date) of function lessOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N <= toInt32(-1) -Code: 43: Illegal types of arguments (Date, Int32) of function lessOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt32(-1) <= N -Code: 43: Illegal types of arguments (Int32, Date) of function lessOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N <= toUInt64(1) -Code: 43: Illegal types of arguments (Date, UInt64) of function lessOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toUInt64(1) <= N -Code: 43: Illegal types of arguments (UInt64, Date) of function lessOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N <= toInt64(-1) -Code: 43: Illegal types of arguments (Date, Int64) of function lessOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT toInt64(-1) <= N -Code: 43: Illegal types of arguments (Int64, Date) of function lessOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT N > toUInt8(1) -Code: 43: Illegal types of arguments (Date, UInt8) of function greater. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt8(1) > N -Code: 43: Illegal types of arguments (UInt8, Date) of function greater. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N > toInt8(-1) -Code: 43: Illegal types of arguments (Date, Int8) of function greater. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt8(-1) > N -Code: 43: Illegal types of arguments (Int8, Date) of function greater. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N > toUInt16(1) -Code: 43: Illegal types of arguments (Date, UInt16) of function greater. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt16(1) > N -Code: 43: Illegal types of arguments (UInt16, Date) of function greater. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N > toInt16(-1) -Code: 43: Illegal types of arguments (Date, Int16) of function greater. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt16(-1) > N -Code: 43: Illegal types of arguments (Int16, Date) of function greater. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N > toUInt32(1) -Code: 43: Illegal types of arguments (Date, UInt32) of function greater. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt32(1) > N -Code: 43: Illegal types of arguments (UInt32, Date) of function greater. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N > toInt32(-1) -Code: 43: Illegal types of arguments (Date, Int32) of function greater. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt32(-1) > N -Code: 43: Illegal types of arguments (Int32, Date) of function greater. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N > toUInt64(1) -Code: 43: Illegal types of arguments (Date, UInt64) of function greater. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt64(1) > N -Code: 43: Illegal types of arguments (UInt64, Date) of function greater. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N > toInt64(-1) -Code: 43: Illegal types of arguments (Date, Int64) of function greater. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt64(-1) > N -Code: 43: Illegal types of arguments (Int64, Date) of function greater. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N >= toUInt8(1) -Code: 43: Illegal types of arguments (Date, UInt8) of function greaterOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt8(1) >= N -Code: 43: Illegal types of arguments (UInt8, Date) of function greaterOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N >= toInt8(-1) -Code: 43: Illegal types of arguments (Date, Int8) of function greaterOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt8(-1) >= N -Code: 43: Illegal types of arguments (Int8, Date) of function greaterOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N >= toUInt16(1) -Code: 43: Illegal types of arguments (Date, UInt16) of function greaterOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt16(1) >= N -Code: 43: Illegal types of arguments (UInt16, Date) of function greaterOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N >= toInt16(-1) -Code: 43: Illegal types of arguments (Date, Int16) of function greaterOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt16(-1) >= N -Code: 43: Illegal types of arguments (Int16, Date) of function greaterOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N >= toUInt32(1) -Code: 43: Illegal types of arguments (Date, UInt32) of function greaterOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt32(1) >= N -Code: 43: Illegal types of arguments (UInt32, Date) of function greaterOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N >= toInt32(-1) -Code: 43: Illegal types of arguments (Date, Int32) of function greaterOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt32(-1) >= N -Code: 43: Illegal types of arguments (Int32, Date) of function greaterOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N >= toUInt64(1) -Code: 43: Illegal types of arguments (Date, UInt64) of function greaterOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toUInt64(1) >= N -Code: 43: Illegal types of arguments (UInt64, Date) of function greaterOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ SELECT N >= toInt64(-1) -Code: 43: Illegal types of arguments (Date, Int64) of function greaterOrEquals. +Code: 43 "UInt8",1 "UInt8",1 ------------------------------------------ SELECT toInt64(-1) >= N -Code: 43: Illegal types of arguments (Int64, Date) of function greaterOrEquals. +Code: 43 "UInt8",0 "UInt8",0 ------------------------------------------ diff --git a/tests/queries/0_stateless/00921_datetime64_compatibility.sh b/tests/queries/0_stateless/00921_datetime64_compatibility.sh index 8f5d9081719..3e5de1a552c 100755 --- a/tests/queries/0_stateless/00921_datetime64_compatibility.sh +++ b/tests/queries/0_stateless/00921_datetime64_compatibility.sh @@ -12,4 +12,4 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) "${CURDIR}"/00921_datetime64_compatibility.python \ | ${CLICKHOUSE_CLIENT} --ignore-error -T -nm --calculate_text_stack_trace 0 --log-level 'error' 2>&1 \ - | sed -Ee 's/Received exception from server .*//g; s/(Code: [0-9]+). DB::Exception: Received from .* DB::Exception/\1/g' + | sed 's/Received exception .*//g; s/^\(Code: [0-9]\+\).*$/\1/g' From 77654eeee870d9d7f894d56026b75e40230975d2 Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenkov Date: Fri, 23 Oct 2020 17:35:03 +0300 Subject: [PATCH 3/3] fixup --- src/Functions/if.cpp | 72 ++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/src/Functions/if.cpp b/src/Functions/if.cpp index 8f7647a8899..dd67f922ddf 100644 --- a/src/Functions/if.cpp +++ b/src/Functions/if.cpp @@ -154,6 +154,22 @@ struct NumIfImpl, Decimal, Decimal> } }; +template +struct NumIfImpl +{ +private: + [[noreturn]] static void throwError() + { + throw Exception("Invalid types of arguments 2 and 3 of if", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); + } +public: + template static void vectorVector(Args &&...) { throwError(); } + template static void vectorConstant(Args &&...) { throwError(); } + template static void constantVector(Args &&...) { throwError(); } + template static void constantConstant(Args &&...) { throwError(); } +}; + + class FunctionIf : public FunctionIfBase { public: @@ -189,29 +205,17 @@ private: const IColumn * col_right_untyped = columns[arguments[2]].column.get(); UInt32 scale = decimalScale(columns, arguments); - if constexpr (std::is_same_v) + if (const auto * col_right_vec = checkAndGetColumn(col_right_untyped)) { - const auto & arg_left = columns[arguments[1]]; - const auto & arg_right = columns[arguments[2]]; - throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Incompatible types of arguments of function {}:" - " '{}' and '{}'", getName(), arg_left.type->getName(), - arg_right.type->getName()); + NumIfImpl::vectorVector( + cond_col->getData(), col_left->getData(), col_right_vec->getData(), columns, result, scale); + return true; } - else + else if (const auto * col_right_const = checkAndGetColumnConst(col_right_untyped)) { - if (const auto * col_right_vec = checkAndGetColumn(col_right_untyped)) - { - NumIfImpl::vectorVector( - cond_col->getData(), col_left->getData(), col_right_vec->getData(), columns, result, scale); - return true; - } - else if (const auto * col_right_const = checkAndGetColumnConst(col_right_untyped)) - { - NumIfImpl::vectorConstant( - cond_col->getData(), col_left->getData(), col_right_const->template getValue(), columns, result, scale); - return true; - } + NumIfImpl::vectorConstant( + cond_col->getData(), col_left->getData(), col_right_const->template getValue(), columns, result, scale); + return true; } return false; @@ -230,29 +234,17 @@ private: const IColumn * col_right_untyped = columns[arguments[2]].column.get(); UInt32 scale = decimalScale(columns, arguments); - if constexpr (std::is_same_v) + if (const auto * col_right_vec = checkAndGetColumn(col_right_untyped)) { - const auto & arg_left = columns[arguments[1]]; - const auto & arg_right = columns[arguments[2]]; - throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, - "Incompatible types of arguments of function {}:" - " '{}' and '{}'", getName(), arg_left.type->getName(), - arg_right.type->getName()); + NumIfImpl::constantVector( + cond_col->getData(), col_left->template getValue(), col_right_vec->getData(), columns, result, scale); + return true; } - else + else if (const auto * col_right_const = checkAndGetColumnConst(col_right_untyped)) { - if (const auto * col_right_vec = checkAndGetColumn(col_right_untyped)) - { - NumIfImpl::constantVector( - cond_col->getData(), col_left->template getValue(), col_right_vec->getData(), columns, result, scale); - return true; - } - else if (const auto * col_right_const = checkAndGetColumnConst(col_right_untyped)) - { - NumIfImpl::constantConstant( - cond_col->getData(), col_left->template getValue(), col_right_const->template getValue(), columns, result, scale); - return true; - } + NumIfImpl::constantConstant( + cond_col->getData(), col_left->template getValue(), col_right_const->template getValue(), columns, result, scale); + return true; } return false;