Use FunctionArgumentDescriptors in getReturnTypeImpl()

This commit is contained in:
Robert Schulze 2023-11-02 20:43:51 +00:00
parent 3a85f79fcb
commit dee8775c6a
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
3 changed files with 13 additions and 11 deletions

View File

@ -458,6 +458,8 @@ inline bool isUInt32(const T & data_type) { return WhichDataType(data_type).isUI
template <typename T>
inline bool isUInt64(const T & data_type) { return WhichDataType(data_type).isUInt64(); }
template <typename T>
inline bool isNativeUnsignedInteger(const T & data_type) { return WhichDataType(data_type).isNativeUInt(); }
template <typename T>
inline bool isUnsignedInteger(const T & data_type) { return WhichDataType(data_type).isUInt(); }
template <typename T>

View File

@ -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<IDataType>, 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<typename Traits::ReturnDataType>();
}

View File

@ -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}