From fe726ee71d0bfeb850515ba3b081fb63670b81fe Mon Sep 17 00:00:00 2001 From: remzi <13716567376yh@gmail.com> Date: Fri, 2 Sep 2022 21:06:17 +0800 Subject: [PATCH 1/2] update both year and month Signed-off-by: remzi <13716567376yh@gmail.com> --- datafusion/core/tests/sql/timestamp.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/datafusion/core/tests/sql/timestamp.rs b/datafusion/core/tests/sql/timestamp.rs index 351f8a5e3c6a4..a536b1ce2a1d0 100644 --- a/datafusion/core/tests/sql/timestamp.rs +++ b/datafusion/core/tests/sql/timestamp.rs @@ -1397,11 +1397,10 @@ async fn timestamp_sub_interval_days() -> Result<()> { } #[tokio::test] -#[ignore] // https://github.com/apache/arrow-datafusion/issues/3327 async fn timestamp_add_interval_months() -> Result<()> { let ctx = SessionContext::new(); - let sql = "SELECT NOW(), NOW() + INTERVAL '4' MONTH;"; + let sql = "SELECT NOW(), NOW() + INTERVAL '17' MONTH;"; let results = execute_to_batches(&ctx, sql).await; let actual = result_vec(&results); @@ -1412,7 +1411,10 @@ async fn timestamp_add_interval_months() -> Result<()> { let t1_naive = chrono::NaiveDateTime::parse_from_str(res1, format).unwrap(); let t2_naive = chrono::NaiveDateTime::parse_from_str(res2, format).unwrap(); - assert_eq!(t1_naive.with_month(t1_naive.month() + 4).unwrap(), t2_naive); + let year = t1_naive.year() + (t1_naive.month() as i32 + 17) / 12; + let month = (t1_naive.month() + 17) % 12; + + assert_eq!(t1_naive.with_year(year).unwrap().with_month(month).unwrap(), t2_naive); Ok(()) } From 92e3c571e3b967bc99ef2786aa9329db70274b01 Mon Sep 17 00:00:00 2001 From: remzi <13716567376yh@gmail.com> Date: Fri, 2 Sep 2022 21:09:11 +0800 Subject: [PATCH 2/2] fmt Signed-off-by: remzi <13716567376yh@gmail.com> --- datafusion/core/tests/sql/timestamp.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/datafusion/core/tests/sql/timestamp.rs b/datafusion/core/tests/sql/timestamp.rs index a536b1ce2a1d0..fab0dbf1dbced 100644 --- a/datafusion/core/tests/sql/timestamp.rs +++ b/datafusion/core/tests/sql/timestamp.rs @@ -1414,7 +1414,10 @@ async fn timestamp_add_interval_months() -> Result<()> { let year = t1_naive.year() + (t1_naive.month() as i32 + 17) / 12; let month = (t1_naive.month() + 17) % 12; - assert_eq!(t1_naive.with_year(year).unwrap().with_month(month).unwrap(), t2_naive); + assert_eq!( + t1_naive.with_year(year).unwrap().with_month(month).unwrap(), + t2_naive + ); Ok(()) }