diff --git a/dbms/src/Functions/timeSlot.cpp b/dbms/src/Functions/timeSlot.cpp index f9763997b92..c734bed8203 100644 --- a/dbms/src/Functions/timeSlot.cpp +++ b/dbms/src/Functions/timeSlot.cpp @@ -8,7 +8,7 @@ namespace DB { -using FunctionTimeSlot = FunctionDateOrDateTimeToSomething; +using FunctionTimeSlot = FunctionDateOrDateTimeToSomething; void registerFunctionTimeSlot(FunctionFactory & factory) { diff --git a/dbms/src/Functions/timeSlots.cpp b/dbms/src/Functions/timeSlots.cpp index 16ade60cb50..07afc2894e1 100644 --- a/dbms/src/Functions/timeSlots.cpp +++ b/dbms/src/Functions/timeSlots.cpp @@ -121,17 +121,19 @@ public: size_t getNumberOfArguments() const override { return 2; } - DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override + DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override { - if (!WhichDataType(arguments[0]).isDateTime()) - throw Exception("Illegal type " + arguments[0]->getName() + " of first argument of function " + getName() + ". Must be DateTime.", + if (!WhichDataType(arguments[0].type).isDateTime()) + throw Exception("Illegal type " + arguments[0].type->getName() + " of first argument of function " + getName() + ". Must be DateTime.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - if (!WhichDataType(arguments[1]).isUInt32()) - throw Exception("Illegal type " + arguments[1]->getName() + " of second argument of function " + getName() + ". Must be UInt32.", + if (!WhichDataType(arguments[1].type).isUInt32()) + throw Exception("Illegal type " + arguments[1].type->getName() + " of second argument of function " + getName() + ". Must be UInt32.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - return std::make_shared(std::make_shared()); + /// If time zone is specified for source data type, attach it to the resulting type. + /// Note that there is no explicit time zone argument for this function (we specify 2 as an argument number with explicit time zone). + return std::make_shared(std::make_shared(extractTimeZoneNameFromFunctionArguments(arguments, 2, 0))); } void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override diff --git a/dbms/tests/queries/0_stateless/00734_timeslot.reference b/dbms/tests/queries/0_stateless/00734_timeslot.reference new file mode 100644 index 00000000000..5acfa2b537c --- /dev/null +++ b/dbms/tests/queries/0_stateless/00734_timeslot.reference @@ -0,0 +1,2 @@ +2000-01-02 03:00:00 +['2000-01-02 03:00:00','2000-01-02 03:30:00','2000-01-02 04:00:00','2000-01-02 04:30:00','2000-01-02 05:00:00','2000-01-02 05:30:00'] diff --git a/dbms/tests/queries/0_stateless/00734_timeslot.sql b/dbms/tests/queries/0_stateless/00734_timeslot.sql new file mode 100644 index 00000000000..7362074ccaf --- /dev/null +++ b/dbms/tests/queries/0_stateless/00734_timeslot.sql @@ -0,0 +1,2 @@ +SELECT timeSlot(toDateTime('2000-01-02 03:04:05', 'UTC')); +SELECT timeSlots(toDateTime('2000-01-02 03:04:05', 'UTC'), toUInt32(10000));