diff --git a/src/Functions/now.cpp b/src/Functions/now.cpp index b244d054cfe..653a39b38d0 100644 --- a/src/Functions/now.cpp +++ b/src/Functions/now.cpp @@ -43,13 +43,13 @@ private: class FunctionBaseNow : public IFunctionBase { public: - explicit FunctionBaseNow(time_t time_, DataTypePtr return_type_) : time_value(time_), return_type(return_type_) {} + explicit FunctionBaseNow(time_t time_, DataTypes argument_types_, DataTypePtr return_type_) + : time_value(time_), argument_types(std::move(argument_types_)), return_type(std::move(return_type_)) {} String getName() const override { return "now"; } const DataTypes & getArgumentTypes() const override { - static const DataTypes argument_types; return argument_types; } @@ -69,6 +69,7 @@ public: private: time_t time_value; + DataTypes argument_types; DataTypePtr return_type; }; @@ -117,8 +118,10 @@ public: } if (arguments.size() == 1) return std::make_unique( - time(nullptr), std::make_shared(extractTimeZoneNameFromFunctionArguments(arguments, 0, 0))); - return std::make_unique(time(nullptr), std::make_shared()); + time(nullptr), DataTypes{arguments.front().type}, + std::make_shared(extractTimeZoneNameFromFunctionArguments(arguments, 0, 0))); + + return std::make_unique(time(nullptr), DataTypes(), std::make_shared()); } }; diff --git a/src/Functions/now64.cpp b/src/Functions/now64.cpp index 4a3f4dbfb22..bd1038b1fc6 100644 --- a/src/Functions/now64.cpp +++ b/src/Functions/now64.cpp @@ -67,13 +67,13 @@ private: class FunctionBaseNow64 : public IFunctionBase { public: - explicit FunctionBaseNow64(Field time_, DataTypePtr return_type_) : time_value(time_), return_type(return_type_) {} + explicit FunctionBaseNow64(Field time_, DataTypes argument_types_, DataTypePtr return_type_) + : time_value(time_), argument_types(std::move(argument_types_)), return_type(std::move(return_type_)) {} String getName() const override { return "now64"; } const DataTypes & getArgumentTypes() const override { - static const DataTypes argument_types; return argument_types; } @@ -93,6 +93,7 @@ public: private: Field time_value; + DataTypes argument_types; DataTypePtr return_type; }; @@ -139,14 +140,19 @@ public: return std::make_shared(scale, timezone_name); } - FunctionBasePtr buildImpl(const ColumnsWithTypeAndName &, const DataTypePtr & result_type) const override + FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type) const override { UInt32 scale = DataTypeDateTime64::default_scale; auto res_type = removeNullable(result_type); if (const auto * type = typeid_cast(res_type.get())) scale = type->getScale(); - return std::make_unique(nowSubsecond(scale), result_type); + DataTypes arg_types; + arg_types.reserve(arguments.size()); + for (const auto & arg : arguments) + arg_types.push_back(arg.type); + + return std::make_unique(nowSubsecond(scale), std::move(arg_types), std::move(result_type)); } }; diff --git a/tests/queries/0_stateless/02100_now64_types_bug.reference b/tests/queries/0_stateless/02100_now64_types_bug.reference new file mode 100644 index 00000000000..ae136939b64 --- /dev/null +++ b/tests/queries/0_stateless/02100_now64_types_bug.reference @@ -0,0 +1,3 @@ +2 +1 +0 diff --git a/tests/queries/0_stateless/02100_now64_types_bug.sql b/tests/queries/0_stateless/02100_now64_types_bug.sql new file mode 100644 index 00000000000..c91defcbf3a --- /dev/null +++ b/tests/queries/0_stateless/02100_now64_types_bug.sql @@ -0,0 +1,8 @@ +SELECT x +FROM +( + SELECT if((number % NULL) = -2147483648, NULL, if(toInt64(toInt64(now64(if((number % NULL) = -2147483648, NULL, if(toInt64(now64(toInt64(9223372036854775807, now64(h3kRing(NULL, NULL))), h3kRing(NULL, NULL))) = (number % NULL), nan, toFloat64(number))), toInt64(9223372036854775807, toInt64(9223372036854775807, now64(h3kRing(NULL, NULL))), now64(h3kRing(NULL, NULL))), h3kRing(NULL, NULL))), now64(toInt64(9223372036854775807, toInt64(0, now64(h3kRing(NULL, NULL))), now64(h3kRing(NULL, NULL))), h3kRing(NULL, NULL))) = (number % NULL), nan, toFloat64(number))) AS x + FROM system.numbers + LIMIT 3 +) +ORDER BY x DESC NULLS LAST