yaooqinn opened a new pull request #28396:
URL: https://github.com/apache/spark/pull/28396


   ### What changes were proposed in this pull request?
   Checked with both Presto and PostgresSQL, one is implemented intervals with 
ANSI style year-month/day-time, the other is mixed and Non-ANSI. They both add 
the exceeded days in interval time part to the total days of the operation 
which extracts day from interval values.
   
    
   
   ```sql
   
   presto> SELECT EXTRACT(DAY FROM (cast('2020-01-15 00:00:00' as timestamp) - 
cast('2020-01-01 00:00:00' as timestamp)));
   _col0
   -------
   14
   (1 row)
   
   Query 20200428_135239_00000_ahn7x, FINISHED, 1 node
   Splits: 17 total, 17 done (100.00%)
   0:01 [0 rows, 0B] [0 rows/s, 0B/s]
   
   presto> SELECT EXTRACT(DAY FROM (cast('2020-01-15 00:00:00' as timestamp) - 
cast('2020-01-01 00:00:01' as timestamp)));
   _col0
   -------
   13
   (1 row)
   
   Query 20200428_135246_00001_ahn7x, FINISHED, 1 node
   Splits: 17 total, 17 done (100.00%)
   0:00 [0 rows, 0B] [0 rows/s, 0B/s]
   
   presto>
   
   ```
   
   ```scala
   
   postgres=# SELECT EXTRACT(DAY FROM (cast('2020-01-15 00:00:00' as timestamp) 
- cast('2020-01-01 00:00:00' as timestamp)));
   date_part
   -----------
   14
   (1 row)
   
   postgres=# SELECT EXTRACT(DAY FROM (cast('2020-01-15 00:00:00' as timestamp) 
- cast('2020-01-01 00:00:01' as timestamp)));
   date_part
   -----------
   13
   
   ```
   
   In ANSI standard, the day is exact 24 hours, so we don't need to worry about 
the conceptual day for interval extraction. The meaning of the conceptual day 
only takes effect when we add it to a zoned timestamp value.
   
   ### Why are the changes needed?
   
   Both satisfy the ANSI standard and common use cases in modern SQL platforms
   
   
   ### Does this PR introduce any user-facing change?
   <!--
   If yes, please clarify the previous behavior and the change this PR proposes 
- provide the console output, description and/or an example to show the 
behavior difference if possible.
   If no, write 'No'.
   -->
   
   No, it new in 3.0
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some 
test cases that check the changes thoroughly including negative and positive 
cases if possible.
   If it was tested in a way different from regular unit tests, please clarify 
how you tested step by step, ideally copy and paste-able, so that other 
reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why 
it was difficult to add.
   -->
   add more uts


----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to