berkaysynnada commented on PR #5764:
URL: 
https://github.com/apache/arrow-datafusion/pull/5764#issuecomment-1488317572

   > If I add 1 month to `2023-03-01T00:00:00 +02` is the output 
`2023-04-01T00:00:00 +02` or `2023-03-29T00:00:00 +02`.
   > 
   > I _believe_ this PR implements the latter as it performs arithmetic with 
respect to the UTC epoch? Is that the desired behaviour?
   > 
   > 
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=11112707c7217ecca3ef64ceb984beb6
 contains an example showing the difference
   
   ```
   #[tokio::test]
   async fn interval_ts_add() -> Result<()> {
       let ctx = SessionContext::new();
       let table_a = {
           let schema = Arc::new(Schema::new(vec![
               Field::new("ts1", DataType::Timestamp(TimeUnit::Second, None), 
false),
               Field::new(
                   "interval1",
                   DataType::Interval(IntervalUnit::YearMonth),
                   false,
               ),
           ]));
           let array1 = 
PrimitiveArray::<TimestampSecondType>::from_iter_values(vec![
               1_677_628_800i64, // 2023-03-01T00:00:00
           ]);
           let array2 =
               
PrimitiveArray::<IntervalYearMonthType>::from_iter_values(vec![1i32]);
           let data = RecordBatch::try_new(
               schema.clone(),
               vec![Arc::new(array1), Arc::new(array2)],
           )?;
           let table = MemTable::try_new(schema, vec![vec![data]])?;
           Arc::new(table)
       };
   
       ctx.register_table("table_a", table_a)?;
       let sql = "SELECT ts1, ts1 + interval1 from table_a";
       let actual = execute_to_batches(&ctx, sql).await;
       let expected = vec![
           "+---------------------+---------------------------------+",
           "| ts1                 | table_a.ts1 + table_a.interval1 |",
           "+---------------------+---------------------------------+",
           "| 2023-03-01T00:00:00 | 2023-04-01T00:00:00             |",
           "+---------------------+---------------------------------+",
       ];
       assert_batches_eq!(expected, &actual);
       Ok(())
   }
   ```
   The former result is produced, you can reproduce it with this test. Existing 
`do_date_time_math` functionality is adopted. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to