I am trying to execute a simple SQL query on some dataframe in spark-shell the query adds interval of 1 week to some date as follows:
The original query:
scala> spark.sql("select Cast(table1.date2 as Date) + interval 1 week from table1").show()
Now when I did some tests:
scala> spark.sql("select Cast('1999-09-19' as Date) + interval 1 week from table1").show()
I got the results correctly
+----------------------------------------------------------------------------+
|CAST(CAST(CAST(1999-09-19 AS DATE) AS TIMESTAMP) + interval 1 weeks AS DATE)|
+----------------------------------------------------------------------------+
| 1999-09-26|
+----------------------------------------------------------------------------+
(Just adding 7 days to 19 = 26)
But when I just changed the year to 1997 instead of 1999 the results changed!
scala> spark.sql("select Cast('1997-09-19' as Date) + interval 1 week from table1").show()
+----------------------------------------------------------------------------+
|CAST(CAST(CAST(1997-09-19 AS DATE) AS TIMESTAMP) + interval 1 weeks AS DATE)|
+----------------------------------------------------------------------------+
| 1997-09-25|
+----------------------------------------------------------------------------+
Why the reuslts changed? Shouldn't it be 26 not 25?
So, is this a bug in sparkSQL related to some kind of itermediate calculations loss or I am missing something?