@@ -567,25 +567,30 @@ async fn timestamp_sub_interval_days() -> Result<()> {
567567#[ tokio:: test]
568568async fn timestamp_add_interval_months ( ) -> Result < ( ) > {
569569 let ctx = SessionContext :: new ( ) ;
570+ let table_a =
571+ make_timestamp_tz_table :: < TimestampNanosecondType > ( Some ( "+00:00" . into ( ) ) ) ?;
572+ ctx. register_table ( "table_a" , table_a) ?;
570573
571- let sql = "SELECT NOW(), NOW() + INTERVAL '17' MONTH;" ;
574+ let sql = "SELECT ts, ts + INTERVAL '17' MONTH FROM table_a ;" ;
572575 let results = execute_to_batches ( & ctx, sql) . await ;
573- let actual = result_vec ( & results) ;
576+ let actual_vec = result_vec ( & results) ;
574577
575- let res1 = actual[ 0 ] [ 0 ] . as_str ( ) ;
576- let res2 = actual[ 0 ] [ 1 ] . as_str ( ) ;
578+ for actual in actual_vec {
579+ let res1 = actual[ 0 ] . as_str ( ) ;
580+ let res2 = actual[ 1 ] . as_str ( ) ;
577581
578- let format = "%Y-%m-%dT%H:%M:%S%.6fZ" ;
579- let t1_naive = NaiveDateTime :: parse_from_str ( res1, format) . unwrap ( ) ;
580- let t2_naive = NaiveDateTime :: parse_from_str ( res2, format) . unwrap ( ) ;
582+ let format = "%Y-%m-%dT%H:%M:%S%.6fZ" ;
583+ let t1_naive = NaiveDateTime :: parse_from_str ( res1, format) . unwrap ( ) ;
584+ let t2_naive = NaiveDateTime :: parse_from_str ( res2, format) . unwrap ( ) ;
581585
582- let year = t1_naive. year ( ) + ( t1_naive. month0 ( ) as i32 + 17 ) / 12 ;
583- let month = ( t1_naive. month0 ( ) + 17 ) % 12 + 1 ;
586+ let year = t1_naive. year ( ) + ( t1_naive. month0 ( ) as i32 + 17 ) / 12 ;
587+ let month = ( t1_naive. month0 ( ) + 17 ) % 12 + 1 ;
584588
585- assert_eq ! (
586- t1_naive. with_year( year) . unwrap( ) . with_month( month) . unwrap( ) ,
587- t2_naive
588- ) ;
589+ assert_eq ! (
590+ t1_naive. with_year( year) . unwrap( ) . with_month( month) . unwrap( ) ,
591+ t2_naive
592+ ) ;
593+ }
589594 Ok ( ( ) )
590595}
591596
0 commit comments