MaxGekk commented on a change in pull request #25981: [SPARK-28420][SQL] 
Support the `INTERVAL` type in `date_part()`
URL: https://github.com/apache/spark/pull/25981#discussion_r332218582
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
 ##########
 @@ -2067,6 +2082,10 @@ object DatePart {
        224
       > SELECT _FUNC_('SECONDS', timestamp'2019-10-01 00:00:01.000001');
        1.000001
+      > SELECT _FUNC_('days', interval 1 year 10 months 5 days);
 
 Review comment:
   > But it does seem like this proposal doesn't match PostgreSQL in the 
`SELECT date_part('hour', INTERVAL '4 hours 3 minutes')`;
   
   It does. In PostgreSQL:
   ```sql
   maxim=# SELECT date_part('hour', INTERVAL '4 hours 3 minutes');
    date_part 
   -----------
            4
   ```
   In SparkSQL:
   ```sql
   spark-sql> SELECT date_part('hour', interval 4 hours 3 minutes);
   4
   ```
   
   > SELECT date_part('hour', INTERVAL '1 month 1 day'); gives 24, right? 
because the days are separable from the months.
   
   No, it is 0 because the range of hours is `[0, 23]`:
   In PostgreSQL:
   ```sql
   maxim=# SELECT date_part('hour', INTERVAL '1 month 1 day');
    date_part 
   -----------
            0
   ```
   In SparkSQL:
   ```sql
   spark-sql> SELECT date_part('hour', INTERVAL 1 month 1 day);
   0
   ```
   
   > SELECT date_part('month', INTERVAL '1 year 1 month'); gives 13, not 1, 
right? because the month part isn't separable.
   
   No, it gives 1.
   In PostgreSQL:
   ```sql
   maxim=# SELECT date_part('month', INTERVAL '1 year 1 month');
    date_part 
   -----------
            1
   ```
   In SparkSQL:
   ```sql
   spark-sql> SELECT date_part('month', INTERVAL 1 year 1 month);
   1
   ```
   
   > This feels inconsistent.
   
   I cannot agree with you so far.

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


With regards,
Apache Git Services

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

Reply via email to