@@ -300,8 +300,8 @@ fn register_string_to_timestamp(registry: &mut FunctionRegistry) {
300
300
"to_timestamp" ,
301
301
|_, _, _| FunctionDomain :: MayThrow ,
302
302
vectorize_with_builder_2_arg :: < StringType , StringType , NullableType < TimestampType > > (
303
- |timestamp, format, output, ctx| match string_to_format_timestamp (
304
- timestamp, format, ctx,
303
+ |timestamp, format, output, ctx| match string_to_format_datetime (
304
+ timestamp, format, ctx, true ,
305
305
) {
306
306
Ok ( ( ts, need_null) ) => {
307
307
if need_null {
@@ -322,8 +322,8 @@ fn register_string_to_timestamp(registry: &mut FunctionRegistry) {
322
322
"try_to_timestamp" ,
323
323
|_, _, _| FunctionDomain :: MayThrow ,
324
324
vectorize_with_builder_2_arg :: < StringType , StringType , NullableType < TimestampType > > (
325
- |timestamp, format, output, ctx| match string_to_format_timestamp (
326
- timestamp, format, ctx,
325
+ |timestamp, format, output, ctx| match string_to_format_datetime (
326
+ timestamp, format, ctx, true ,
327
327
) {
328
328
Ok ( ( ts, need_null) ) => {
329
329
if need_null {
@@ -347,7 +347,7 @@ fn register_string_to_timestamp(registry: &mut FunctionRegistry) {
347
347
if format. is_empty ( ) {
348
348
output. push_null ( ) ;
349
349
} else {
350
- match string_to_format_timestamp ( date, format, ctx) {
350
+ match string_to_format_datetime ( date, format, ctx, false ) {
351
351
Ok ( ( res, false ) ) => {
352
352
output. push ( ( res / MICROS_PER_SEC / 24 / 3600 ) as _ ) ;
353
353
}
@@ -372,7 +372,7 @@ fn register_string_to_timestamp(registry: &mut FunctionRegistry) {
372
372
if format. is_empty ( ) {
373
373
output. push_null ( ) ;
374
374
} else {
375
- match string_to_format_timestamp ( date, format, ctx) {
375
+ match string_to_format_datetime ( date, format, ctx, false ) {
376
376
Ok ( ( res, false ) ) => {
377
377
output. push ( ( res / MICROS_PER_SEC / 24 / 3600 ) as _ ) ;
378
378
}
@@ -386,10 +386,11 @@ fn register_string_to_timestamp(registry: &mut FunctionRegistry) {
386
386
) ;
387
387
}
388
388
389
- fn string_to_format_timestamp (
389
+ fn string_to_format_datetime (
390
390
timestamp : & str ,
391
391
format : & str ,
392
392
ctx : & mut EvalContext ,
393
+ parse_timestamp : bool ,
393
394
) -> Result < ( i64 , bool ) , Box < ErrorCode > > {
394
395
if format. is_empty ( ) {
395
396
return Ok ( ( 0 , true ) ) ;
@@ -424,9 +425,15 @@ fn string_to_format_timestamp(
424
425
}
425
426
426
427
let z = if tm. offset ( ) . is_none ( ) {
427
- ctx. func_ctx . tz . to_zoned ( tm. to_datetime ( ) . map_err ( |err| {
428
- ErrorCode :: BadArguments ( format ! ( "{timestamp} to datetime error {err}" ) )
429
- } ) ?)
428
+ if parse_timestamp {
429
+ ctx. func_ctx . tz . to_zoned ( tm. to_datetime ( ) . map_err ( |err| {
430
+ ErrorCode :: BadArguments ( format ! ( "{timestamp} to datetime error {err}" ) )
431
+ } ) ?)
432
+ } else {
433
+ TimeZone :: UTC . to_zoned ( tm. to_datetime ( ) . map_err ( |err| {
434
+ ErrorCode :: BadArguments ( format ! ( "{timestamp} to datetime error {err}" ) )
435
+ } ) ?)
436
+ }
430
437
} else {
431
438
tm. to_zoned ( )
432
439
}
0 commit comments