Skip to content

Commit 5578de4

Browse files
authored
fix(query): to_yyyymmddhhmmss only support timestamp type (#17422)
* fix(query): to_yyyymmddhhmmss only support timestamp type * to_yyyymmddhh only support timestamp type as arg
1 parent b9294c1 commit 5578de4

File tree

4 files changed

+16
-36
lines changed

4 files changed

+16
-36
lines changed

src/query/functions/src/scalars/timestamp/src/datetime.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,32 +1332,6 @@ fn register_to_number_functions(registry: &mut FunctionRegistry) {
13321332
}
13331333
}),
13341334
);
1335-
registry.register_passthrough_nullable_1_arg::<DateType, UInt64Type, _, _>(
1336-
"to_yyyymmddhh",
1337-
|_, _| FunctionDomain::Full,
1338-
vectorize_with_builder_1_arg::<DateType, UInt64Type>(|val, output, ctx| {
1339-
match ToNumberImpl::eval_date::<ToYYYYMMDDHH, _>(val, ctx.func_ctx.tz.clone()) {
1340-
Ok(t) => output.push(t),
1341-
Err(e) => {
1342-
ctx.set_error(output.len(), format!("cannot parse to type `Date`. {}", e));
1343-
output.push(0);
1344-
}
1345-
}
1346-
}),
1347-
);
1348-
registry.register_passthrough_nullable_1_arg::<DateType, UInt64Type, _, _>(
1349-
"to_yyyymmddhhmmss",
1350-
|_, _| FunctionDomain::Full,
1351-
vectorize_with_builder_1_arg::<DateType, UInt64Type>(|val, output, ctx| {
1352-
match ToNumberImpl::eval_date::<ToYYYYMMDDHHMMSS, _>(val, ctx.func_ctx.tz.clone()) {
1353-
Ok(t) => output.push(t),
1354-
Err(e) => {
1355-
ctx.set_error(output.len(), format!("cannot parse to type `Date`. {}", e));
1356-
output.push(0);
1357-
}
1358-
}
1359-
}),
1360-
);
13611335
registry.register_passthrough_nullable_1_arg::<DateType, UInt16Type, _, _>(
13621336
"to_year",
13631337
|_, _| FunctionDomain::Full,

src/query/functions/tests/it/scalars/testdata/datetime.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,7 @@ output : 20210905
24892489

24902490
ast : to_yyyymmddhhmmss(to_date(18875))
24912491
raw expr : to_yyyymmddhhmmss(to_date(18875))
2492-
checked expr : to_yyyymmddhhmmss<Date>(to_date<Int64>(to_int64<UInt16>(18875_u16)))
2492+
checked expr : to_yyyymmddhhmmss<Timestamp>(to_timestamp<Date>(to_date<Int64>(to_int64<UInt16>(18875_u16))))
24932493
optimized expr : 20210905000000_u64
24942494
output type : UInt64
24952495
output domain : {20210905000000..=20210905000000}
@@ -2605,7 +2605,7 @@ evaluation (internal):
26052605

26062606
ast : to_yyyymmddhhmmss(a)
26072607
raw expr : to_yyyymmddhhmmss(a::Date)
2608-
checked expr : to_yyyymmddhhmmss<Date>(a)
2608+
checked expr : to_yyyymmddhhmmss<Timestamp>(to_timestamp<Date>(a))
26092609
evaluation:
26102610
+--------+--------------+----------------------------+
26112611
| | a | Output |

src/query/functions/tests/it/scalars/testdata/function_list.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,14 +4092,10 @@ Functions overloads:
40924092
1 to_yyyymmdd(Date NULL) :: UInt32 NULL
40934093
2 to_yyyymmdd(Timestamp) :: UInt32
40944094
3 to_yyyymmdd(Timestamp NULL) :: UInt32 NULL
4095-
0 to_yyyymmddhh(Date) :: UInt64
4096-
1 to_yyyymmddhh(Date NULL) :: UInt64 NULL
4097-
2 to_yyyymmddhh(Timestamp) :: UInt64
4098-
3 to_yyyymmddhh(Timestamp NULL) :: UInt64 NULL
4099-
0 to_yyyymmddhhmmss(Date) :: UInt64
4100-
1 to_yyyymmddhhmmss(Date NULL) :: UInt64 NULL
4101-
2 to_yyyymmddhhmmss(Timestamp) :: UInt64
4102-
3 to_yyyymmddhhmmss(Timestamp NULL) :: UInt64 NULL
4095+
0 to_yyyymmddhh(Timestamp) :: UInt64
4096+
1 to_yyyymmddhh(Timestamp NULL) :: UInt64 NULL
4097+
0 to_yyyymmddhhmmss(Timestamp) :: UInt64
4098+
1 to_yyyymmddhhmmss(Timestamp NULL) :: UInt64 NULL
41034099
0 today() :: Date
41044100
0 tomorrow() :: Date
41054101
0 translate(String, String, String) :: String

tests/sqllogictests/suites/query/functions/02_0012_function_datetimes.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ select to_yyyymmddhhmmss(to_date(18875))
417417
----
418418
20210905000000
419419

420+
query I
421+
SELECT to_yyyymmddhhmmss('2023-11-12 09:38:18.165575')
422+
----
423+
20231112093818
424+
420425
query B
421426
select to_yyyymmddhhmmss(to_datetime(1630833797000000)) = 20210905092317
422427
----
@@ -447,6 +452,11 @@ select to_yyyymmddhh(to_date(18875)) = 2021090500
447452
----
448453
1
449454

455+
query I
456+
SELECT to_yyyymmddhh('2023-11-12 09:38:18.165575')
457+
----
458+
2023111209
459+
450460
query I
451461
select to_yyyymmdd(to_datetime(1630833797000000))
452462
----

0 commit comments

Comments
 (0)