diff --git a/src/query/functions/src/scalars/datetime.rs b/src/query/functions/src/scalars/datetime.rs index 87c29543af2f..23c7af7b8d48 100644 --- a/src/query/functions/src/scalars/datetime.rs +++ b/src/query/functions/src/scalars/datetime.rs @@ -541,6 +541,30 @@ fn register_number_to_timestamp(registry: &mut FunctionRegistry) { error_to_null(eval_number_to_timestamp), ); + registry.register_passthrough_nullable_2_arg::( + "to_timestamp", + |_, _, _| FunctionDomain::Full, + vectorize_with_builder_2_arg::( + |val, scale, output, _| { + let mut n = val * 10i64.pow(6 - scale.clamp(0, 6) as u32); + clamp_timestamp(&mut n); + output.push(n) + }, + ), + ); + + registry.register_passthrough_nullable_2_arg::( + "try_to_timestamp", + |_, _, _| FunctionDomain::Full, + vectorize_with_builder_2_arg::( + |val, scale, output, _| { + let mut n = val * 10i64.pow(6 - scale.clamp(0, 6) as u32); + clamp_timestamp(&mut n); + output.push(n); + }, + ), + ); + fn eval_number_to_timestamp( val: ValueRef, ctx: &mut EvalContext, diff --git a/src/query/functions/tests/it/scalars/testdata/function_list.txt b/src/query/functions/tests/it/scalars/testdata/function_list.txt index bb706257a921..afc725e13450 100644 --- a/src/query/functions/tests/it/scalars/testdata/function_list.txt +++ b/src/query/functions/tests/it/scalars/testdata/function_list.txt @@ -4164,6 +4164,8 @@ Functions overloads: 7 to_timestamp(Date NULL) :: Timestamp NULL 8 to_timestamp(Int64) :: Timestamp 9 to_timestamp(Int64 NULL) :: Timestamp NULL +10 to_timestamp(Int64, UInt64) :: Timestamp +11 to_timestamp(Int64 NULL, UInt64 NULL) :: Timestamp NULL 0 to_uint16(Variant) :: UInt16 1 to_uint16(Variant NULL) :: UInt16 NULL 2 to_uint16(String) :: UInt16 @@ -4614,6 +4616,8 @@ Functions overloads: 7 try_to_timestamp(Date NULL) :: Timestamp NULL 8 try_to_timestamp(Int64) :: Timestamp NULL 9 try_to_timestamp(Int64 NULL) :: Timestamp NULL +10 try_to_timestamp(Int64, UInt64) :: Timestamp +11 try_to_timestamp(Int64 NULL, UInt64 NULL) :: Timestamp NULL 0 try_to_uint16(Variant) :: UInt16 NULL 1 try_to_uint16(Variant NULL) :: UInt16 NULL 2 try_to_uint16(String) :: UInt16 NULL diff --git a/tests/sqllogictests/suites/query/functions/02_0012_function_datetimes.test b/tests/sqllogictests/suites/query/functions/02_0012_function_datetimes.test index a5220e9fa180..c38571b09a41 100644 --- a/tests/sqllogictests/suites/query/functions/02_0012_function_datetimes.test +++ b/tests/sqllogictests/suites/query/functions/02_0012_function_datetimes.test @@ -1451,3 +1451,18 @@ query T select to_timestamp('2022-03-27 07:54:31.12'); ---- 2022-03-27 07:54:31.120000 + +query T +select TO_TIMESTAMP(-7233803000000+1, 6), TO_TIMESTAMP(-7233803000, 3), TO_TIMESTAMP(-7233803000000-1, 6); +---- +1969-10-09 06:36:37.000001 1969-10-09 06:36:37.000000 1969-10-09 06:36:36.999999 + +query T +select TO_TIMESTAMP(1, 0), TO_TIMESTAMP(1, 1), TO_TIMESTAMP(1, 2), TO_TIMESTAMP(1, 3), TO_TIMESTAMP(1, 4), TO_TIMESTAMP(1, 5), TO_TIMESTAMP(1, 6); +---- +1970-01-01 00:00:01.000000 1970-01-01 00:00:00.100000 1970-01-01 00:00:00.010000 1970-01-01 00:00:00.001000 1970-01-01 00:00:00.000100 1970-01-01 00:00:00.000010 1970-01-01 00:00:00.000001 + +query T +select TRY_TO_TIMESTAMP(1, 0), TRY_TO_TIMESTAMP(1, null); +---- +1970-01-01 00:00:01.000000 NULL