mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Merge pull request #14509 from bharatnc/ncb/disallow-empty-tz-toStartOfIntervalFunc
disallow empty time_zone argument in toStartOf* type of functions
This commit is contained in:
commit
69630972d4
@ -67,8 +67,16 @@ public:
|
||||
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
/// For DateTime, if time zone is specified, attach it to type.
|
||||
/// If the time zone is specified but empty, throw an exception.
|
||||
if constexpr (std::is_same_v<ToDataType, DataTypeDateTime>)
|
||||
return std::make_shared<ToDataType>(extractTimeZoneNameFromFunctionArguments(arguments, 1, 0));
|
||||
{
|
||||
std::string time_zone = extractTimeZoneNameFromFunctionArguments(arguments, 1, 0);
|
||||
if (time_zone.empty())
|
||||
throw Exception(
|
||||
"Function " + getName() + " supports a 2nd argument (optional) that must be non-empty and be a valid time zone",
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
return std::make_shared<ToDataType>(time_zone);
|
||||
}
|
||||
if constexpr (std::is_same_v<ToDataType, DataTypeDateTime64>)
|
||||
{
|
||||
Int64 scale = DataTypeDateTime64::default_scale;
|
||||
|
@ -13,6 +13,7 @@ namespace DB
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int ILLEGAL_COLUMN;
|
||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +55,12 @@ std::string extractTimeZoneNameFromFunctionArguments(const ColumnsWithTypeAndNam
|
||||
const DateLUTImpl & extractTimeZoneFromFunctionArguments(Block & block, const ColumnNumbers & arguments, size_t time_zone_arg_num, size_t datetime_arg_num)
|
||||
{
|
||||
if (arguments.size() == time_zone_arg_num + 1)
|
||||
return DateLUT::instance(extractTimeZoneNameFromColumn(*block.getByPosition(arguments[time_zone_arg_num]).column));
|
||||
{
|
||||
std::string time_zone = extractTimeZoneNameFromColumn(*block.getByPosition(arguments[time_zone_arg_num]).column);
|
||||
if (time_zone.empty())
|
||||
throw Exception("Provided time zone must be non-empty and be a valid time zone", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
return DateLUT::instance(time_zone);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (arguments.empty())
|
||||
|
@ -88,37 +88,38 @@ SELECT toStartOfWeek(N)
|
||||
"Date","2019-09-15"
|
||||
------------------------------------------
|
||||
SELECT toStartOfDay(N)
|
||||
"DateTime","2019-09-16 00:00:00"
|
||||
|
||||
Code: 43: Function toStartOfDay supports a 2nd argument (optional) that must be non-empty and be a valid time zone.
|
||||
"DateTime('Europe/Minsk')","2019-09-16 00:00:00"
|
||||
"DateTime('Europe/Minsk')","2019-09-16 00:00:00"
|
||||
------------------------------------------
|
||||
SELECT toStartOfHour(N)
|
||||
|
||||
Code: 43: Illegal type Date of argument for function toStartOfHour.
|
||||
Code: 43: Function toStartOfHour supports a 2nd argument (optional) that must be non-empty and be a valid time zone.
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:00:00"
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:00:00"
|
||||
------------------------------------------
|
||||
SELECT toStartOfMinute(N)
|
||||
|
||||
Code: 43: Illegal type Date of argument for function toStartOfMinute.
|
||||
Code: 43: Function toStartOfMinute supports a 2nd argument (optional) that must be non-empty and be a valid time zone.
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:20:00"
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:20:00"
|
||||
------------------------------------------
|
||||
SELECT toStartOfFiveMinute(N)
|
||||
|
||||
Code: 43: Illegal type Date of argument for function toStartOfFiveMinute.
|
||||
Code: 43: Function toStartOfFiveMinute supports a 2nd argument (optional) that must be non-empty and be a valid time zone.
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:20:00"
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:20:00"
|
||||
------------------------------------------
|
||||
SELECT toStartOfTenMinutes(N)
|
||||
|
||||
Code: 43: Illegal type Date of argument for function toStartOfTenMinutes.
|
||||
Code: 43: Function toStartOfTenMinutes supports a 2nd argument (optional) that must be non-empty and be a valid time zone.
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:20:00"
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:20:00"
|
||||
------------------------------------------
|
||||
SELECT toStartOfFifteenMinutes(N)
|
||||
|
||||
Code: 43: Illegal type Date of argument for function toStartOfFifteenMinutes.
|
||||
Code: 43: Function toStartOfFifteenMinutes supports a 2nd argument (optional) that must be non-empty and be a valid time zone.
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:15:00"
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:15:00"
|
||||
------------------------------------------
|
||||
@ -166,7 +167,7 @@ Code: 43: Illegal type Date of argument for function date_trunc.
|
||||
------------------------------------------
|
||||
SELECT toTime(N)
|
||||
|
||||
Code: 43: Illegal type Date of argument for function toTime.
|
||||
Code: 43: Function toTime supports a 2nd argument (optional) that must be non-empty and be a valid time zone.
|
||||
"DateTime('Europe/Minsk')","1970-01-02 19:20:11"
|
||||
"DateTime('Europe/Minsk')","1970-01-02 19:20:11"
|
||||
------------------------------------------
|
||||
@ -232,7 +233,7 @@ SELECT toYearWeek(N)
|
||||
------------------------------------------
|
||||
SELECT timeSlot(N)
|
||||
|
||||
Code: 43: Illegal type Date of argument for function timeSlot.
|
||||
Code: 43: Function timeSlot supports a 2nd argument (optional) that must be non-empty and be a valid time zone.
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:00:00"
|
||||
"DateTime('Europe/Minsk')","2019-09-16 19:00:00"
|
||||
------------------------------------------
|
||||
|
@ -0,0 +1,8 @@
|
||||
2017-12-31 00:00:00
|
||||
2017-12-01
|
||||
2017-10-01
|
||||
2017-01-01
|
||||
2017-12-31 05:10:00
|
||||
2017-12-31 01:15:00
|
||||
2017-12-31 01:00:00
|
||||
2017-12-31 00:01:00
|
@ -0,0 +1,23 @@
|
||||
SELECT toStartOfDay(toDateTime('2017-12-31 00:00:00', 'UTC'), ''); -- {serverError 43}
|
||||
SELECT toStartOfDay(toDateTime('2017-12-31 03:45:00', 'UTC'), 'UTC'); -- success
|
||||
|
||||
SELECT toStartOfMonth(toDateTime('2017-12-31 00:00:00', 'UTC'), ''); -- {serverError 43}
|
||||
SELECT toStartOfMonth(toDateTime('2017-12-31 00:00:00', 'UTC'), 'UTC'); -- success
|
||||
|
||||
SELECT toStartOfQuarter(toDateTime('2017-12-31 00:00:00', 'UTC'), ''); -- {serverError 43}
|
||||
SELECT toStartOfQuarter(toDateTime('2017-12-31 00:00:00', 'UTC'), 'UTC'); -- success
|
||||
|
||||
SELECT toStartOfYear(toDateTime('2017-12-31 00:00:00', 'UTC'), ''); -- {serverError 43}
|
||||
SELECT toStartOfYear(toDateTime('2017-12-31 00:00:00', 'UTC'), 'UTC'); -- success
|
||||
|
||||
SELECT toStartOfTenMinutes(toDateTime('2017-12-31 00:00:00', 'UTC'), ''); -- {serverError 43}
|
||||
SELECT toStartOfTenMinutes(toDateTime('2017-12-31 05:12:30', 'UTC'), 'UTC'); -- success
|
||||
|
||||
SELECT toStartOfFifteenMinutes(toDateTime('2017-12-31 00:00:00', 'UTC'), ''); -- {serverError 43}
|
||||
SELECT toStartOfFifteenMinutes(toDateTime('2017-12-31 01:17:00', 'UTC'), 'UTC'); -- success
|
||||
|
||||
SELECT toStartOfHour(toDateTime('2017-12-31 00:00:00', 'UTC'), ''); -- {serverError 43}
|
||||
SELECT toStartOfHour(toDateTime('2017-12-31 01:59:00', 'UTC'), 'UTC'); -- success
|
||||
|
||||
SELECT toStartOfMinute(toDateTime('2017-12-31 00:00:00', 'UTC'), ''); -- {serverError 43}
|
||||
SELECT toStartOfMinute(toDateTime('2017-12-31 00:01:30', 'UTC'), 'UTC'); -- success
|
Loading…
Reference in New Issue
Block a user