@@ -260,37 +260,238 @@ async fn set_u64_variable_bad_value() {
260
260
261
261
#[ tokio:: test]
262
262
async fn set_time_zone ( ) {
263
- // we don't support changing time zone for now until all time zone issues fixed and related function completed
263
+ let ctx =
264
+ SessionContext :: with_config ( SessionConfig :: new ( ) . with_information_schema ( true ) ) ;
264
265
265
- let ctx = SessionContext :: new ( ) ;
266
+ plan_and_collect ( & ctx, "SET datafusion.execution.time_zone = '+08:00'" )
267
+ . await
268
+ . unwrap ( ) ;
266
269
267
- // for full variable name
268
- let err = plan_and_collect ( & ctx, "set datafusion.execution.time_zone = '8'" )
270
+ let result = plan_and_collect ( & ctx, "SHOW datafusion.execution.time_zone" )
269
271
. await
270
- . unwrap_err ( ) ;
272
+ . unwrap ( ) ;
273
+ let expected = vec ! [
274
+ "+--------------------------------+---------+" ,
275
+ "| name | setting |" ,
276
+ "+--------------------------------+---------+" ,
277
+ "| datafusion.execution.time_zone | +08:00 |" ,
278
+ "+--------------------------------+---------+" ,
279
+ ] ;
280
+ assert_batches_eq ! ( expected, & result) ;
281
+ }
271
282
272
- assert_eq ! (
273
- err . to_string ( ) ,
274
- "Error during planning: Changing Time Zone isn't supported yet"
275
- ) ;
283
+ # [ tokio :: test ]
284
+ async fn set_time_zone_with_alias_variable_name ( ) {
285
+ let ctx =
286
+ SessionContext :: with_config ( SessionConfig :: new ( ) . with_information_schema ( true ) ) ;
276
287
277
- // for alias time zone
278
- let err = plan_and_collect ( & ctx, "set time zone = '8 '" )
288
+ // TIME ZONE with space
289
+ plan_and_collect ( & ctx, "SET TIME ZONE = '+08:00 '" )
279
290
. await
280
- . unwrap_err ( ) ;
291
+ . unwrap ( ) ;
281
292
282
- assert_eq ! (
283
- err. to_string( ) ,
284
- "Error during planning: Changing Time Zone isn't supported yet"
285
- ) ;
293
+ let result = plan_and_collect ( & ctx, "SHOW TIME ZONE" ) . await . unwrap ( ) ;
294
+ let expected = vec ! [
295
+ "+--------------------------------+---------+" ,
296
+ "| name | setting |" ,
297
+ "+--------------------------------+---------+" ,
298
+ "| datafusion.execution.time_zone | +08:00 |" ,
299
+ "+--------------------------------+---------+" ,
300
+ ] ;
301
+ assert_batches_eq ! ( expected, & result) ;
286
302
287
- // for alias timezone
288
- let err = plan_and_collect ( & ctx, "set timezone = '8 '" )
303
+ // TIMEZONE without space
304
+ plan_and_collect ( & ctx, "SET TIMEZONE = '+07:00 '" )
289
305
. await
290
- . unwrap_err ( ) ;
306
+ . unwrap ( ) ;
291
307
292
- assert_eq ! (
293
- err. to_string( ) ,
294
- "Error during planning: Changing Time Zone isn't supported yet"
295
- ) ;
308
+ let result = plan_and_collect ( & ctx, "SHOW TIMEZONE" ) . await . unwrap ( ) ;
309
+ let expected = vec ! [
310
+ "+--------------------------------+---------+" ,
311
+ "| name | setting |" ,
312
+ "+--------------------------------+---------+" ,
313
+ "| datafusion.execution.time_zone | +07:00 |" ,
314
+ "+--------------------------------+---------+" ,
315
+ ] ;
316
+ assert_batches_eq ! ( expected, & result) ;
317
+ }
318
+
319
+ #[ tokio:: test]
320
+ async fn set_time_zone_good_time_zone_format ( ) {
321
+ let ctx =
322
+ SessionContext :: with_config ( SessionConfig :: new ( ) . with_information_schema ( true ) ) ;
323
+
324
+ plan_and_collect ( & ctx, "SET TIME ZONE = '+08:00'" )
325
+ . await
326
+ . unwrap ( ) ;
327
+
328
+ // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the middle layer for now
329
+ let result =
330
+ plan_and_collect ( & ctx, "SELECT '2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ" )
331
+ . await
332
+ . unwrap ( ) ;
333
+ let expected = vec ! [
334
+ "+-----------------------------+" ,
335
+ "| Utf8(\" 2000-01-01T00:00:00\" ) |" ,
336
+ "+-----------------------------+" ,
337
+ "| 2000-01-01T08:00:00+08:00 |" ,
338
+ "+-----------------------------+" ,
339
+ ] ;
340
+ // this might break once https://github.com/apache/arrow-rs/issues/1936 fixed
341
+ assert_batches_eq ! ( expected, & result) ;
342
+
343
+ plan_and_collect ( & ctx, "SET TIME ZONE = '-08:00'" )
344
+ . await
345
+ . unwrap ( ) ;
346
+
347
+ // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the middle layer for now
348
+ let result =
349
+ plan_and_collect ( & ctx, "SELECT '2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ" )
350
+ . await
351
+ . unwrap ( ) ;
352
+ let expected = vec ! [
353
+ "+-----------------------------+" ,
354
+ "| Utf8(\" 2000-01-01T00:00:00\" ) |" ,
355
+ "+-----------------------------+" ,
356
+ "| 1999-12-31T16:00:00-08:00 |" ,
357
+ "+-----------------------------+" ,
358
+ ] ;
359
+ // this might break once https://github.com/apache/arrow-rs/issues/1936 fixed
360
+ assert_batches_eq ! ( expected, & result) ;
361
+
362
+ plan_and_collect ( & ctx, "SET TIME ZONE = '+0800'" )
363
+ . await
364
+ . unwrap ( ) ;
365
+
366
+ // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the middle layer for now
367
+ let result =
368
+ plan_and_collect ( & ctx, "SELECT '2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ" )
369
+ . await
370
+ . unwrap ( ) ;
371
+ let expected = vec ! [
372
+ "+-----------------------------+" ,
373
+ "| Utf8(\" 2000-01-01T00:00:00\" ) |" ,
374
+ "+-----------------------------+" ,
375
+ "| 2000-01-01T08:00:00+08:00 |" ,
376
+ "+-----------------------------+" ,
377
+ ] ;
378
+ // this might break once https://github.com/apache/arrow-rs/issues/1936 fixed
379
+ assert_batches_eq ! ( expected, & result) ;
380
+
381
+ plan_and_collect ( & ctx, "SET TIME ZONE = '+08'" )
382
+ . await
383
+ . unwrap ( ) ;
384
+
385
+ // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the middle layer for now
386
+ let result =
387
+ plan_and_collect ( & ctx, "SELECT '2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ" )
388
+ . await
389
+ . unwrap ( ) ;
390
+ let expected = vec ! [
391
+ "+-----------------------------+" ,
392
+ "| Utf8(\" 2000-01-01T00:00:00\" ) |" ,
393
+ "+-----------------------------+" ,
394
+ "| 2000-01-01T08:00:00+08:00 |" ,
395
+ "+-----------------------------+" ,
396
+ ] ;
397
+ // this might break once https://github.com/apache/arrow-rs/issues/1936 fixed
398
+ assert_batches_eq ! ( expected, & result) ;
399
+ }
400
+
401
+ #[ tokio:: test]
402
+ async fn set_time_zone_bad_time_zone_format ( ) {
403
+ let ctx =
404
+ SessionContext :: with_config ( SessionConfig :: new ( ) . with_information_schema ( true ) ) ;
405
+
406
+ plan_and_collect ( & ctx, "SET TIME ZONE = '+08:00:00'" )
407
+ . await
408
+ . unwrap ( ) ;
409
+
410
+ // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the middle layer for now
411
+ let result =
412
+ plan_and_collect ( & ctx, "SELECT '2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ" )
413
+ . await
414
+ . unwrap ( ) ;
415
+ let expected = vec ! [
416
+ "+-----------------------------------------------------+" ,
417
+ "| Utf8(\" 2000-01-01T00:00:00\" ) |" ,
418
+ "+-----------------------------------------------------+" ,
419
+ "| 2000-01-01T00:00:00 (Unknown Time Zone '+08:00:00') |" ,
420
+ "+-----------------------------------------------------+" ,
421
+ ] ;
422
+ assert_batches_eq ! ( expected, & result) ;
423
+
424
+ plan_and_collect ( & ctx, "SET TIME ZONE = '08:00'" )
425
+ . await
426
+ . unwrap ( ) ;
427
+
428
+ // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the middle layer for now
429
+ let result =
430
+ plan_and_collect ( & ctx, "SELECT '2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ" )
431
+ . await
432
+ . unwrap ( ) ;
433
+ let expected = vec ! [
434
+ "+-------------------------------------------------+" ,
435
+ "| Utf8(\" 2000-01-01T00:00:00\" ) |" ,
436
+ "+-------------------------------------------------+" ,
437
+ "| 2000-01-01T00:00:00 (Unknown Time Zone '08:00') |" ,
438
+ "+-------------------------------------------------+" ,
439
+ ] ;
440
+ assert_batches_eq ! ( expected, & result) ;
441
+
442
+ plan_and_collect ( & ctx, "SET TIME ZONE = '08'" )
443
+ . await
444
+ . unwrap ( ) ;
445
+
446
+ // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the middle layer for now
447
+ let result =
448
+ plan_and_collect ( & ctx, "SELECT '2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ" )
449
+ . await
450
+ . unwrap ( ) ;
451
+ let expected = vec ! [
452
+ "+----------------------------------------------+" ,
453
+ "| Utf8(\" 2000-01-01T00:00:00\" ) |" ,
454
+ "+----------------------------------------------+" ,
455
+ "| 2000-01-01T00:00:00 (Unknown Time Zone '08') |" ,
456
+ "+----------------------------------------------+" ,
457
+ ] ;
458
+ assert_batches_eq ! ( expected, & result) ;
459
+
460
+ // we dont support named time zone yet
461
+ plan_and_collect ( & ctx, "SET TIME ZONE = 'Asia/Taipei'" )
462
+ . await
463
+ . unwrap ( ) ;
464
+
465
+ // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the middle layer for now
466
+ let result =
467
+ plan_and_collect ( & ctx, "SELECT '2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ" )
468
+ . await
469
+ . unwrap ( ) ;
470
+ let expected = vec ! [
471
+ "+-------------------------------------------------------+" ,
472
+ "| Utf8(\" 2000-01-01T00:00:00\" ) |" ,
473
+ "+-------------------------------------------------------+" ,
474
+ "| 2000-01-01T00:00:00 (Unknown Time Zone 'Asia/Taipei') |" ,
475
+ "+-------------------------------------------------------+" ,
476
+ ] ;
477
+ assert_batches_eq ! ( expected, & result) ;
478
+
479
+ // this is invalid even after we support named time zone
480
+ plan_and_collect ( & ctx, "SET TIME ZONE = 'Asia/Taipei2'" )
481
+ . await
482
+ . unwrap ( ) ;
483
+
484
+ // casting UTF-8 to TimestampTZ isn't supported yet, add Timestamp as the middle layer for now
485
+ let result =
486
+ plan_and_collect ( & ctx, "SELECT '2000-01-01T00:00:00'::TIMESTAMP::TIMESTAMPTZ" )
487
+ . await
488
+ . unwrap ( ) ;
489
+ let expected = vec ! [
490
+ "+--------------------------------------------------------+" ,
491
+ "| Utf8(\" 2000-01-01T00:00:00\" ) |" ,
492
+ "+--------------------------------------------------------+" ,
493
+ "| 2000-01-01T00:00:00 (Unknown Time Zone 'Asia/Taipei2') |" ,
494
+ "+--------------------------------------------------------+" ,
495
+ ] ;
496
+ assert_batches_eq ! ( expected, & result) ;
296
497
}
0 commit comments