Fix argument types for now and now64

This commit is contained in:
Nikolai Kochetov 2021-10-25 12:06:53 +03:00
parent 1e2ceeb2e7
commit a0a5c1a21d
4 changed files with 28 additions and 8 deletions

View File

@ -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<FunctionBaseNow>(
time(nullptr), std::make_shared<DataTypeDateTime>(extractTimeZoneNameFromFunctionArguments(arguments, 0, 0)));
return std::make_unique<FunctionBaseNow>(time(nullptr), std::make_shared<DataTypeDateTime>());
time(nullptr), DataTypes{arguments.front().type},
std::make_shared<DataTypeDateTime>(extractTimeZoneNameFromFunctionArguments(arguments, 0, 0)));
return std::make_unique<FunctionBaseNow>(time(nullptr), DataTypes(), std::make_shared<DataTypeDateTime>());
}
};

View File

@ -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<DataTypeDateTime64>(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<const DataTypeDateTime64 *>(res_type.get()))
scale = type->getScale();
return std::make_unique<FunctionBaseNow64>(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<FunctionBaseNow64>(nowSubsecond(scale), std::move(arg_types), std::move(result_type));
}
};

View File

@ -0,0 +1,3 @@
2
1
0

View File

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