From 23ca36ab30777377d425d55ee6b4b87fefd6adb9 Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Sat, 12 Oct 2024 14:40:55 +0800 Subject: [PATCH 1/7] add function toUnixTimestampEx and toUnixTimestamp64Second --- .../functions/date-time-functions.md | 40 +++++++++++- .../functions/type-conversion-functions.md | 63 +++++++++++++++---- src/Functions/FunctionsConversion.cpp | 26 ++++++++ src/Functions/toUnixTimestamp64.cpp | 13 ++++ .../01277_toUnixTimestamp64.reference | 12 ++-- .../0_stateless/01277_toUnixTimestamp64.sql | 15 +++-- .../03246_to_timestampex.reference | 9 +++ .../0_stateless/03246_to_timestampex.sql | 9 +++ 8 files changed, 162 insertions(+), 25 deletions(-) create mode 100644 src/Functions/toUnixTimestamp64.cpp create mode 100644 tests/queries/0_stateless/03246_to_timestampex.reference create mode 100644 tests/queries/0_stateless/03246_to_timestampex.sql diff --git a/docs/en/sql-reference/functions/date-time-functions.md b/docs/en/sql-reference/functions/date-time-functions.md index 1d543f11cf3..57a92fa2358 100644 --- a/docs/en/sql-reference/functions/date-time-functions.md +++ b/docs/en/sql-reference/functions/date-time-functions.md @@ -195,7 +195,7 @@ makeDateTime64(year, month, day, hour, minute, second[, precision]) **Returned value** -- A date and time created from the supplied arguments. [DateTime64](../../sql-reference/data-types/datetime64.md). +- A date and time created from the supplied arguments. [DateTime64](../../sql-reference/data-types/datetime64.md). **Example** @@ -868,6 +868,44 @@ Behavior for * Functions `toStartOfDay`, `toStartOfHour`, `toStartOfFifteenMinutes`, `toStartOfTenMinutes`, `toStartOfFiveMinutes`, `toStartOfMinute`, `timeSlot` return `DateTime` if their argument is a `Date` or `DateTime`, and they return `DateTime64` if their argument is a `Date32` or `DateTime64`. ::: +## toUnixTimestampEx + +Like `toUnixTimestamp`, converts a string, a date or a date with time to the [Unix Timestamp](https://en.wikipedia.org/wiki/Unix_time) in `Int64` representation. + +If the function is called with a string, it accepts an optional timezone argument. + +**Syntax** + +``` sql +toUnixTimestampEx(date) +toUnixTimestampEx(str, [timezone]) +``` + +**Returned value** + +- Returns the unix timestamp. [UInt32](../data-types/int-uint.md). + +**Example** + +``` sql +SELECT + '1969-01-01 00:00:00' AS dt_str, + toUnixTimestamp(dt_str) AS from_str, + toUnixTimestampEx(dt_str) AS ex_str, + toUnixTimestamp(dt_str, 'Asia/Tokyo') AS from_str_tokyo, + toUnixTimestampEx(dt_str, 'Asia/Tokyo') AS ex_str_tokyo, + toUnixTimestamp(toDateTime(dt_str)) AS from_datetime, + toUnixTimestampEx(toDateTime64(dt_str, 0)) AS ex_datetime64 +``` + +Result: + +``` +┌─dt_str──────────────┬─from_str─┬────ex_str─┬─from_str_tokyo─┬─ex_str_tokyo─┬─from_datetime─┬─ex_datetime64─┐ +│ 1969-01-01 00:00:00 │ 0 │ -31564800 │ 0 │ -31568400 │ 0 │ -31564800 │ +└─────────────────────┴──────────┴───────────┴────────────────┴──────────────┴───────────────┴───────────────┘ +``` + ## toStartOfYear Rounds down a date or date with time to the first day of the year. Returns the date as a `Date` object. diff --git a/docs/en/sql-reference/functions/type-conversion-functions.md b/docs/en/sql-reference/functions/type-conversion-functions.md index b37bd057adc..e7b4f60afc7 100644 --- a/docs/en/sql-reference/functions/type-conversion-functions.md +++ b/docs/en/sql-reference/functions/type-conversion-functions.md @@ -122,7 +122,7 @@ Unsupported arguments: :::note If the input value cannot be represented within the bounds of [Int8](../data-types/int-uint.md), overflow or underflow of the result occurs. -This is not considered an error. +This is not considered an error. For example: `SELECT toInt8(128) == -128;`. ::: @@ -370,7 +370,7 @@ Unsupported arguments: :::note If the input value cannot be represented within the bounds of [Int16](../data-types/int-uint.md), overflow or underflow of the result occurs. -This is not considered an error. +This is not considered an error. For example: `SELECT toInt16(32768) == -32768;`. ::: @@ -618,7 +618,7 @@ Unsupported arguments: :::note If the input value cannot be represented within the bounds of [Int32](../data-types/int-uint.md), the result over or under flows. -This is not considered an error. +This is not considered an error. For example: `SELECT toInt32(2147483648) == -2147483648;` ::: @@ -865,7 +865,7 @@ Unsupported types: :::note If the input value cannot be represented within the bounds of [Int64](../data-types/int-uint.md), the result over or under flows. -This is not considered an error. +This is not considered an error. For example: `SELECT toInt64(9223372036854775808) == -9223372036854775808;` ::: @@ -1608,7 +1608,7 @@ Unsupported arguments: :::note If the input value cannot be represented within the bounds of [UInt8](../data-types/int-uint.md), overflow or underflow of the result occurs. -This is not considered an error. +This is not considered an error. For example: `SELECT toUInt8(256) == 0;`. ::: @@ -1856,7 +1856,7 @@ Unsupported arguments: :::note If the input value cannot be represented within the bounds of [UInt16](../data-types/int-uint.md), overflow or underflow of the result occurs. -This is not considered an error. +This is not considered an error. For example: `SELECT toUInt16(65536) == 0;`. ::: @@ -2104,7 +2104,7 @@ Unsupported arguments: :::note If the input value cannot be represented within the bounds of [UInt32](../data-types/int-uint.md), the result over or under flows. -This is not considered an error. +This is not considered an error. For example: `SELECT toUInt32(4294967296) == 0;` ::: @@ -2353,7 +2353,7 @@ Unsupported types: :::note If the input value cannot be represented within the bounds of [UInt64](../data-types/int-uint.md), the result over or under flows. -This is not considered an error. +This is not considered an error. For example: `SELECT toUInt64(18446744073709551616) == 0;` ::: @@ -3691,8 +3691,8 @@ toDateTime(expr[, time_zone ]) - `time_zone` — Time zone. [String](../data-types/string.md). :::note -If `expr` is a number, it is interpreted as the number of seconds since the beginning of the Unix Epoch (as Unix timestamp). -If `expr` is a [String](../data-types/string.md), it may be interpreted as a Unix timestamp or as a string representation of date / date with time. +If `expr` is a number, it is interpreted as the number of seconds since the beginning of the Unix Epoch (as Unix timestamp). +If `expr` is a [String](../data-types/string.md), it may be interpreted as a Unix timestamp or as a string representation of date / date with time. Thus, parsing of short numbers' string representations (up to 4 digits) is explicitly disabled due to ambiguity, e.g. a string `'1999'` may be both a year (an incomplete string representation of Date / DateTime) or a unix timestamp. Longer numeric strings are allowed. ::: @@ -5536,7 +5536,7 @@ Result: ## reinterpretAsUInt256 -Performs byte reinterpretation by treating the input value as a value of type UInt256. Unlike [`CAST`](#cast), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is meaningless. +Performs byte reinterpretation by treating the input value as a value of type UInt256. Unlike [`CAST`](#cast), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is meaningless. **Syntax** @@ -5612,7 +5612,7 @@ Result: ## reinterpretAsInt16 -Performs byte reinterpretation by treating the input value as a value of type Int16. Unlike [`CAST`](#cast), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is meaningless. +Performs byte reinterpretation by treating the input value as a value of type Int16. Unlike [`CAST`](#cast), the function does not attempt to preserve the original value - if the target type is not able to represent the input type, the output is meaningless. **Syntax** @@ -7170,6 +7170,45 @@ Result: └──────────────────────────────┘ ``` +## toUnixTimestamp64Second + +Converts a `DateTime64` to a `Int64` value with fixed second precision. The input value is scaled up or down appropriately depending on its precision. + +:::note +The output value is a timestamp in UTC, not in the timezone of `DateTime64`. +::: + +**Syntax** + +```sql +toUnixTimestamp64Second(value) +``` + +**Arguments** + +- `value` — DateTime64 value with any precision. [DateTime64](../data-types/datetime64.md). + +**Returned value** + +- `value` converted to the `Int64` data type. [Int64](../data-types/int-uint.md). + +**Example** + +Query: + +```sql +WITH toDateTime64('2009-02-13 23:31:31.011', 3, 'UTC') AS dt64 +SELECT toUnixTimestamp64Second(dt64); +``` + +Result: + +```response +┌─toUnixTimestamp64Second(dt64)─┐ +│ 1234567891 │ +└───────────────────────────────┘ +``` + ## toUnixTimestamp64Micro Converts a `DateTime64` to a `Int64` value with fixed microsecond precision. The input value is scaled up or down appropriately depending on its precision. diff --git a/src/Functions/FunctionsConversion.cpp b/src/Functions/FunctionsConversion.cpp index 615589a7d43..3f4e46eef0a 100644 --- a/src/Functions/FunctionsConversion.cpp +++ b/src/Functions/FunctionsConversion.cpp @@ -1150,6 +1150,9 @@ struct ConvertThroughParsing /// Function toUnixTimestamp has exactly the same implementation as toDateTime of String type. struct NameToUnixTimestamp { static constexpr auto name = "toUnixTimestamp"; }; +/// Function toUnixTimestampEx has exactly the same implementation as toDateTime of String type. +struct NameToUnixTimestampEx { static constexpr auto name = "toUnixTimestampEx"; }; + enum class BehaviourOnErrorFromString : uint8_t { ConvertDefaultBehaviorTag, @@ -1559,6 +1562,17 @@ struct ConvertImpl return ConvertImpl::template execute( arguments, result_type, input_rows_count, from_string_tag); } + else if constexpr (std::is_same_v + && std::is_same_v + && std::is_same_v) + { + /// Convert String to DateTime64 + ColumnPtr res = ConvertImpl::template execute( + arguments, result_type, input_rows_count, from_string_tag, 0); + /// Convert DateTime64 to Int64 + return ConvertImpl::template execute( + ColumnsWithTypeAndName{{res, result_type, arguments[0].name}}, result_type, input_rows_count, from_string_tag); + } else if constexpr ((std::is_same_v || std::is_same_v)) { switch (from_string_tag) @@ -1813,6 +1827,11 @@ struct ConvertImpl { vec_to[i] = static_cast(vec_from[i] * DATE_SECONDS_PER_DAY); } + else if constexpr (std::is_same_v + && (std::is_same_v || std::is_same_v)) + { + vec_to[i] = static_cast(vec_from[i] * DATE_SECONDS_PER_DAY); + } else { /// If From Data is Nan or Inf and we convert to integer type, throw exception @@ -2080,6 +2099,8 @@ public: if ((std::is_same_v && !arguments.empty() && (isDateTime64(arguments[0].type) || isDateTime(arguments[0].type))) // toUnixTimestamp(value[, timezone : String]) || std::is_same_v + // toUnixTimestampEx(value[, timezone : String]) + || std::is_same_v // toDate(value[, timezone : String]) || std::is_same_v // TODO: shall we allow timestamp argument for toDate? DateTime knows nothing about timezones and this argument is ignored below. // toDate32(value[, timezone : String]) @@ -2236,6 +2257,7 @@ private: if constexpr (IsDataTypeDecimal) { + if constexpr (std::is_same_v) { /// Account for optional timezone argument. @@ -2319,8 +2341,10 @@ private: } } else + { result_column = ConvertImpl::execute(arguments, result_type, input_rows_count, from_string_tag); + } return true; }; @@ -2880,6 +2904,7 @@ using FunctionToIPv4 = FunctionConvert>; using FunctionToString = FunctionConvert; using FunctionToUnixTimestamp = FunctionConvert>; +using FunctionToUnixTimestampEx = FunctionConvert>; using FunctionToDecimal32 = FunctionConvert, NameToDecimal32, UnknownMonotonicity>; using FunctionToDecimal64 = FunctionConvert, NameToDecimal64, UnknownMonotonicity>; using FunctionToDecimal128 = FunctionConvert, NameToDecimal128, UnknownMonotonicity>; @@ -5420,6 +5445,7 @@ REGISTER_FUNCTION(Conversion) factory.registerFunction(); factory.registerFunction(); + factory.registerFunction(); factory.registerFunction(); factory.registerFunction(); diff --git a/src/Functions/toUnixTimestamp64.cpp b/src/Functions/toUnixTimestamp64.cpp new file mode 100644 index 00000000000..61249ed5609 --- /dev/null +++ b/src/Functions/toUnixTimestamp64.cpp @@ -0,0 +1,13 @@ +#include +#include + +namespace DB +{ + +REGISTER_FUNCTION(ToUnixTimestamp64Second) +{ + factory.registerFunction("toUnixTimestamp64Second", + [](ContextPtr){ return std::make_shared(0, "toUnixTimestamp64Second"); }); +} + +} diff --git a/tests/queries/0_stateless/01277_toUnixTimestamp64.reference b/tests/queries/0_stateless/01277_toUnixTimestamp64.reference index 7b66586b4d2..6b329f185a3 100644 --- a/tests/queries/0_stateless/01277_toUnixTimestamp64.reference +++ b/tests/queries/0_stateless/01277_toUnixTimestamp64.reference @@ -1,8 +1,8 @@ const column -2019-09-16 19:20:12.345 1568650812345 1568650812345000 1568650812345000000 -2019-09-16 19:20:12.345678 1568650812345 1568650812345678 1568650812345678000 -2019-09-16 19:20:12.345678910 1568650812345 1568650812345678 1568650812345678910 +2019-09-16 19:20:12.345 1568650812345 1568650812345000 1568650812345000000 1568650812 +2019-09-16 19:20:12.345678 1568650812345 1568650812345678 1568650812345678000 1568650812 +2019-09-16 19:20:12.345678910 1568650812345 1568650812345678 1568650812345678910 1568650812 non-const column -2019-09-16 19:20:12.345 1568650812345 1568650812345000 1568650812345000000 -2019-09-16 19:20:12.345678 1568650812345 1568650812345678 1568650812345678000 -2019-09-16 19:20:12.345678910 1568650812345 1568650812345678 1568650812345678910 +2019-09-16 19:20:12.345 1568650812345 1568650812345000 1568650812345000000 1568650812 +2019-09-16 19:20:12.345678 1568650812345 1568650812345678 1568650812345678000 1568650812 +2019-09-16 19:20:12.345678910 1568650812345 1568650812345678 1568650812345678910 1568650812 diff --git a/tests/queries/0_stateless/01277_toUnixTimestamp64.sql b/tests/queries/0_stateless/01277_toUnixTimestamp64.sql index 14ee57da5df..6f3e90bc92d 100644 --- a/tests/queries/0_stateless/01277_toUnixTimestamp64.sql +++ b/tests/queries/0_stateless/01277_toUnixTimestamp64.sql @@ -2,32 +2,35 @@ SELECT toUnixTimestamp64Milli(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH} SELECT toUnixTimestamp64Micro(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH} SELECT toUnixTimestamp64Nano(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH} +SELECT toUnixTimestamp64Second(); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH} SELECT toUnixTimestamp64Milli('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} SELECT toUnixTimestamp64Micro('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} SELECT toUnixTimestamp64Nano('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} +SELECT toUnixTimestamp64Second('abc'); -- {serverError ILLEGAL_TYPE_OF_ARGUMENT} SELECT toUnixTimestamp64Milli('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH} SELECT toUnixTimestamp64Micro('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH} SELECT toUnixTimestamp64Nano('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH} +SELECT toUnixTimestamp64Second('abc', 123); -- {serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH} SELECT 'const column'; WITH toDateTime64('2019-09-16 19:20:12.345678910', 3, 'Asia/Istanbul') AS dt64 -SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64); +SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64); WITH toDateTime64('2019-09-16 19:20:12.345678910', 6, 'Asia/Istanbul') AS dt64 -SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64); +SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64); WITH toDateTime64('2019-09-16 19:20:12.345678910', 9, 'Asia/Istanbul') AS dt64 -SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64); +SELECT dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64); SELECT 'non-const column'; WITH toDateTime64('2019-09-16 19:20:12.345678910', 3, 'Asia/Istanbul') AS x -SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64); +SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64); WITH toDateTime64('2019-09-16 19:20:12.345678910', 6, 'Asia/Istanbul') AS x -SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64); +SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64); WITH toDateTime64('2019-09-16 19:20:12.345678910', 9, 'Asia/Istanbul') AS x -SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64); +SELECT materialize(x) as dt64, toUnixTimestamp64Milli(dt64), toUnixTimestamp64Micro(dt64), toUnixTimestamp64Nano(dt64), toUnixTimestamp64Second(dt64); diff --git a/tests/queries/0_stateless/03246_to_timestampex.reference b/tests/queries/0_stateless/03246_to_timestampex.reference new file mode 100644 index 00000000000..23b6c78b943 --- /dev/null +++ b/tests/queries/0_stateless/03246_to_timestampex.reference @@ -0,0 +1,9 @@ +1683676800 +1683676800 +1683676800 +1683676800 +-1293882467 +0 +0 +-28800 +-28800 diff --git a/tests/queries/0_stateless/03246_to_timestampex.sql b/tests/queries/0_stateless/03246_to_timestampex.sql new file mode 100644 index 00000000000..861a23c0bb1 --- /dev/null +++ b/tests/queries/0_stateless/03246_to_timestampex.sql @@ -0,0 +1,9 @@ +SELECT toUnixTimestampEx(makeDate(2023, 5, 10)); +SELECT toUnixTimestampEx(makeDate32(2023, 5, 10)); +SELECT toUnixTimestampEx(makeDate(2023, 5, 10), 'Pacific/Auckland'); +SELECT toUnixTimestampEx(makeDate32(2023, 5, 10), 'Pacific/Auckland'); +SELECT toUnixTimestampEx(toDateTime64('1928-12-31 12:12:12.123', 3, 'UTC')); +SELECT toUnixTimestampEx('1970-01-01 00:00:00', 'UTC'); +SELECT toUnixTimestampEx(materialize('1970-01-01 00:00:00'), 'UTC'); +SELECT toUnixTimestampEx('1970-01-01 00:00:00', 'Asia/Shanghai'); +SELECT toUnixTimestampEx(materialize('1970-01-01 00:00:00'), 'Asia/Shanghai'); From ae3ea224682e4da2086868adb9d26d05707c7d27 Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Sat, 12 Oct 2024 14:49:11 +0800 Subject: [PATCH 2/7] clean code --- src/Functions/FunctionsConversion.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Functions/FunctionsConversion.cpp b/src/Functions/FunctionsConversion.cpp index 3f4e46eef0a..9faa1c48d5a 100644 --- a/src/Functions/FunctionsConversion.cpp +++ b/src/Functions/FunctionsConversion.cpp @@ -2341,10 +2341,8 @@ private: } } else - { result_column = ConvertImpl::execute(arguments, result_type, input_rows_count, from_string_tag); - } return true; }; From bbe701d3415fb7cc190a959e11f074d5b57b2e0b Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Tue, 15 Oct 2024 12:39:21 +0800 Subject: [PATCH 3/7] fix Check docs spelling error --- utils/check-style/aspell-ignore/en/aspell-dict.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/check-style/aspell-ignore/en/aspell-dict.txt b/utils/check-style/aspell-ignore/en/aspell-dict.txt index 616ad4a800c..aa0c2746391 100644 --- a/utils/check-style/aspell-ignore/en/aspell-dict.txt +++ b/utils/check-style/aspell-ignore/en/aspell-dict.txt @@ -3143,3 +3143,4 @@ DistributedCachePoolBehaviourOnLimit SharedJoin ShareSet unacked +toUnixTimestampEx From 15f7061109ce5c070f183e4a4c86a0f47c80c46b Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Wed, 16 Oct 2024 09:00:29 +0800 Subject: [PATCH 4/7] fix new functions doc check --- .../02415_all_new_functions_must_be_documented.reference | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference b/tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference index 7c541f272c8..072df78ee79 100644 --- a/tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference +++ b/tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference @@ -850,6 +850,8 @@ toUnixTimestamp toUnixTimestamp64Micro toUnixTimestamp64Milli toUnixTimestamp64Nano +toUnixTimestamp64Second +toUnixTimestampEx toValidUTF8 toWeek toYYYYMM From 9dc861f0abd1bc2a1cc0394866ee10a7a957623c Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Wed, 16 Oct 2024 15:03:06 +0800 Subject: [PATCH 5/7] fix tidy check fail --- src/Functions/FunctionsConversion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Functions/FunctionsConversion.cpp b/src/Functions/FunctionsConversion.cpp index 9faa1c48d5a..6afce88e054 100644 --- a/src/Functions/FunctionsConversion.cpp +++ b/src/Functions/FunctionsConversion.cpp @@ -1830,7 +1830,7 @@ struct ConvertImpl else if constexpr (std::is_same_v && (std::is_same_v || std::is_same_v)) { - vec_to[i] = static_cast(vec_from[i] * DATE_SECONDS_PER_DAY); + vec_to[i] = vec_from[i] * DATE_SECONDS_PER_DAY; } else { From ffc33fb7c138b4e67f96b9ee2d21facc723e7090 Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Thu, 28 Nov 2024 11:39:43 +0800 Subject: [PATCH 6/7] delete toUnixTimestampEx --- .../functions/date-time-functions.md | 38 ------------------- ...new_functions_must_be_documented.reference | 1 - .../03246_to_timestampex.reference | 9 ----- .../0_stateless/03246_to_timestampex.sql | 9 ----- 4 files changed, 57 deletions(-) delete mode 100644 tests/queries/0_stateless/03246_to_timestampex.reference delete mode 100644 tests/queries/0_stateless/03246_to_timestampex.sql diff --git a/docs/en/sql-reference/functions/date-time-functions.md b/docs/en/sql-reference/functions/date-time-functions.md index ed03ed46d76..2c563495777 100644 --- a/docs/en/sql-reference/functions/date-time-functions.md +++ b/docs/en/sql-reference/functions/date-time-functions.md @@ -868,44 +868,6 @@ Behavior for * Functions `toStartOfDay`, `toStartOfHour`, `toStartOfFifteenMinutes`, `toStartOfTenMinutes`, `toStartOfFiveMinutes`, `toStartOfMinute`, `timeSlot` return `DateTime` if their argument is a `Date` or `DateTime`, and they return `DateTime64` if their argument is a `Date32` or `DateTime64`. ::: -## toUnixTimestampEx - -Like `toUnixTimestamp`, converts a string, a date or a date with time to the [Unix Timestamp](https://en.wikipedia.org/wiki/Unix_time) in `Int64` representation. - -If the function is called with a string, it accepts an optional timezone argument. - -**Syntax** - -``` sql -toUnixTimestampEx(date) -toUnixTimestampEx(str, [timezone]) -``` - -**Returned value** - -- Returns the unix timestamp. [UInt32](../data-types/int-uint.md). - -**Example** - -``` sql -SELECT - '1969-01-01 00:00:00' AS dt_str, - toUnixTimestamp(dt_str) AS from_str, - toUnixTimestampEx(dt_str) AS ex_str, - toUnixTimestamp(dt_str, 'Asia/Tokyo') AS from_str_tokyo, - toUnixTimestampEx(dt_str, 'Asia/Tokyo') AS ex_str_tokyo, - toUnixTimestamp(toDateTime(dt_str)) AS from_datetime, - toUnixTimestampEx(toDateTime64(dt_str, 0)) AS ex_datetime64 -``` - -Result: - -``` -┌─dt_str──────────────┬─from_str─┬────ex_str─┬─from_str_tokyo─┬─ex_str_tokyo─┬─from_datetime─┬─ex_datetime64─┐ -│ 1969-01-01 00:00:00 │ 0 │ -31564800 │ 0 │ -31568400 │ 0 │ -31564800 │ -└─────────────────────┴──────────┴───────────┴────────────────┴──────────────┴───────────────┴───────────────┘ -``` - ## toStartOfYear Rounds down a date or date with time to the first day of the year. Returns the date as a `Date` object. diff --git a/tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference b/tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference index 5d047f6333e..39fdf042930 100644 --- a/tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference +++ b/tests/queries/0_stateless/02415_all_new_functions_must_be_documented.reference @@ -858,7 +858,6 @@ toUnixTimestamp64Micro toUnixTimestamp64Milli toUnixTimestamp64Nano toUnixTimestamp64Second -toUnixTimestampEx toValidUTF8 toWeek toYYYYMM diff --git a/tests/queries/0_stateless/03246_to_timestampex.reference b/tests/queries/0_stateless/03246_to_timestampex.reference deleted file mode 100644 index 23b6c78b943..00000000000 --- a/tests/queries/0_stateless/03246_to_timestampex.reference +++ /dev/null @@ -1,9 +0,0 @@ -1683676800 -1683676800 -1683676800 -1683676800 --1293882467 -0 -0 --28800 --28800 diff --git a/tests/queries/0_stateless/03246_to_timestampex.sql b/tests/queries/0_stateless/03246_to_timestampex.sql deleted file mode 100644 index 861a23c0bb1..00000000000 --- a/tests/queries/0_stateless/03246_to_timestampex.sql +++ /dev/null @@ -1,9 +0,0 @@ -SELECT toUnixTimestampEx(makeDate(2023, 5, 10)); -SELECT toUnixTimestampEx(makeDate32(2023, 5, 10)); -SELECT toUnixTimestampEx(makeDate(2023, 5, 10), 'Pacific/Auckland'); -SELECT toUnixTimestampEx(makeDate32(2023, 5, 10), 'Pacific/Auckland'); -SELECT toUnixTimestampEx(toDateTime64('1928-12-31 12:12:12.123', 3, 'UTC')); -SELECT toUnixTimestampEx('1970-01-01 00:00:00', 'UTC'); -SELECT toUnixTimestampEx(materialize('1970-01-01 00:00:00'), 'UTC'); -SELECT toUnixTimestampEx('1970-01-01 00:00:00', 'Asia/Shanghai'); -SELECT toUnixTimestampEx(materialize('1970-01-01 00:00:00'), 'Asia/Shanghai'); From 128080c24914517e4d197302d606efe89c92eb76 Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Thu, 28 Nov 2024 11:42:59 +0800 Subject: [PATCH 7/7] delete toUnixTimestampEx --- utils/check-style/aspell-ignore/en/aspell-dict.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/check-style/aspell-ignore/en/aspell-dict.txt b/utils/check-style/aspell-ignore/en/aspell-dict.txt index 23f202d4997..0383642385d 100644 --- a/utils/check-style/aspell-ignore/en/aspell-dict.txt +++ b/utils/check-style/aspell-ignore/en/aspell-dict.txt @@ -3165,5 +3165,4 @@ znode znodes zookeeperSessionUptime zstd -toUnixTimestampEx BFloat