From dee8775c6af86151edda3607704a9f7afa32ff60 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Thu, 2 Nov 2023 20:43:51 +0000 Subject: [PATCH] Use FunctionArgumentDescriptors in getReturnTypeImpl() --- src/DataTypes/IDataType.h | 2 ++ src/Functions/fromDaysSinceYearZero.cpp | 10 +++++----- .../0_stateless/02907_fromDaysSinceYearZero.sql | 12 ++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/DataTypes/IDataType.h b/src/DataTypes/IDataType.h index 7f5cd88fa2b..f334cd9ff24 100644 --- a/src/DataTypes/IDataType.h +++ b/src/DataTypes/IDataType.h @@ -458,6 +458,8 @@ inline bool isUInt32(const T & data_type) { return WhichDataType(data_type).isUI template inline bool isUInt64(const T & data_type) { return WhichDataType(data_type).isUInt64(); } template +inline bool isNativeUnsignedInteger(const T & data_type) { return WhichDataType(data_type).isNativeUInt(); } +template inline bool isUnsignedInteger(const T & data_type) { return WhichDataType(data_type).isUInt(); } template diff --git a/src/Functions/fromDaysSinceYearZero.cpp b/src/Functions/fromDaysSinceYearZero.cpp index 532a9e4c02c..24be151f5f9 100644 --- a/src/Functions/fromDaysSinceYearZero.cpp +++ b/src/Functions/fromDaysSinceYearZero.cpp @@ -77,13 +77,13 @@ public: size_t getNumberOfArguments() const override { return 1; } - DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override + DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override { - WhichDataType which_first(arguments[0]->getTypeId()); + FunctionArgumentDescriptors args{ + {"days", &isNativeUnsignedInteger, nullptr, "UInt*"} + }; - if (!which_first.isInt() && !which_first.isUInt()) - throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of argument of function {}", - arguments[0]->getName(), getName()); + validateFunctionArgumentTypes(*this, arguments, args); return std::make_shared(); } diff --git a/tests/queries/0_stateless/02907_fromDaysSinceYearZero.sql b/tests/queries/0_stateless/02907_fromDaysSinceYearZero.sql index d3c11e0e643..6d171aebc4f 100644 --- a/tests/queries/0_stateless/02907_fromDaysSinceYearZero.sql +++ b/tests/queries/0_stateless/02907_fromDaysSinceYearZero.sql @@ -15,8 +15,8 @@ SELECT 739136 AS x, fromDaysSinceYearZero32(x); SELECT 693961 AS x, fromDaysSinceYearZero32(x); SELECT 785063 AS x, fromDaysSinceYearZero32(x); SELECT 785064 AS x, fromDaysSinceYearZero32(x); -SELECT -10 AS x, fromDaysSinceYearZero(x), 'lower clip, 1970-01-01 min'; -- {serverError ARGUMENT_OUT_OF_BOUND} -SELECT -10 AS x, fromDaysSinceYearZero32(x), 'lower clip, 1970-01-01 min'; -- {serverError ARGUMENT_OUT_OF_BOUND} +SELECT -10 AS x, fromDaysSinceYearZero(x), 'lower clip, 1970-01-01 min'; -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} +SELECT -10 AS x, fromDaysSinceYearZero32(x), 'lower clip, 1970-01-01 min'; -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} SELECT fromDaysSinceYearZero(NULL); SELECT fromDaysSinceYearZero32(NULL); @@ -40,8 +40,8 @@ SELECT 739136 AS x, fromDaysSinceYearZero32(x); SELECT 693961 AS x, fromDaysSinceYearZero32(x); SELECT 785063 AS x, fromDaysSinceYearZero32(x); SELECT 785064 AS x, fromDaysSinceYearZero32(x); -SELECT -10 AS x, fromDaysSinceYearZero(x), 'lower clip, 1970-01-01 min'; -- {serverError ARGUMENT_OUT_OF_BOUND} -SELECT -10 AS x, fromDaysSinceYearZero32(x), 'lower clip, 1970-01-01 min'; -- {serverError ARGUMENT_OUT_OF_BOUND} +SELECT -10 AS x, fromDaysSinceYearZero(x), 'lower clip, 1970-01-01 min'; -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} +SELECT -10 AS x, fromDaysSinceYearZero32(x), 'lower clip, 1970-01-01 min'; -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} SELECT fromDaysSinceYearZero(NULL); SELECT fromDaysSinceYearZero32(NULL); @@ -63,8 +63,8 @@ SELECT 785064 AS x, fromDaysSinceYearZero32(x); SELECT fromDaysSinceYearZero(NULL); SELECT fromDaysSinceYearZero32(NULL); SELECT 0.5 AS x, fromDaysSinceYearZero(x); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} -SELECT -10 AS x, fromDaysSinceYearZero(x), 'lower clip, 1970-01-01 min'; -- {serverError ARGUMENT_OUT_OF_BOUND} -SELECT -10 AS x, fromDaysSinceYearZero32(x), 'lower clip, 1970-01-01 min'; -- {serverError ARGUMENT_OUT_OF_BOUND} +SELECT -10 AS x, fromDaysSinceYearZero(x), 'lower clip, 1970-01-01 min'; -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} +SELECT -10 AS x, fromDaysSinceYearZero32(x), 'lower clip, 1970-01-01 min'; -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} SELECT 0 AS x, fromDaysSinceYearZero(x), 'lower clip, 1970-01-01 min'; -- {serverError VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE} SELECT 719527 AS x, fromDaysSinceYearZero(x), 'lower clip, 1970-01-01 min'; -- {serverError VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE} SELECT 785064 AS x, fromDaysSinceYearZero(x), 'upper clip, 2149-06-06 max'; -- {serverError VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE}