MaxGekk commented on a change in pull request #25336: [SPARK-28017][SQL] 
Support additional levels of truncations by DATE_TRUNC/TRUNC
URL: https://github.com/apache/spark/pull/25336#discussion_r310651438
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
 ##########
 @@ -617,57 +617,75 @@ object DateTimeUtils {
     (date - localDate.getDayOfMonth) + localDate.lengthOfMonth()
   }
 
-  // Visible for testing.
-  private[sql] val TRUNC_TO_YEAR = 1
-  private[sql] val TRUNC_TO_MONTH = 2
-  private[sql] val TRUNC_TO_QUARTER = 3
-  private[sql] val TRUNC_TO_WEEK = 4
-  private[sql] val TRUNC_TO_DAY = 5
-  private[sql] val TRUNC_TO_HOUR = 6
-  private[sql] val TRUNC_TO_MINUTE = 7
-  private[sql] val TRUNC_TO_SECOND = 8
+  // The constants are visible for testing purpose only.
   private[sql] val TRUNC_INVALID = -1
+  // The levels from TRUNC_TO_MONTH to TRUNC_TO_MILLENNIUM are used in 
truncations
+  // of DATE and TIMESTAMP values.
+  private[sql] val TRUNC_TO_MONTH = 0
+  private[sql] val TRUNC_TO_YEAR = 1
+  private[sql] val TRUNC_TO_DECADE = 2
+  private[sql] val TRUNC_TO_CENTURY = 3
+  private[sql] val TRUNC_TO_MILLENNIUM = 4
+  private[sql] val MAX_LEVEL_OF_DATE_TRUNC = TRUNC_TO_MILLENNIUM
+  // The levels from TRUNC_TO_MICROSECOND to TRUNC_TO_QUARTER are used in 
truncations
+  // of TIMESTAMP values only.
+  private[sql] val TRUNC_TO_MICROSECOND = 5
+  private[sql] val TRUNC_TO_MILLISECOND = 6
+  private[sql] val TRUNC_TO_SECOND = 7
+  private[sql] val TRUNC_TO_MINUTE = 8
+  private[sql] val TRUNC_TO_HOUR = 9
+  private[sql] val TRUNC_TO_DAY = 10
+  private[sql] val TRUNC_TO_WEEK = 11
 
 Review comment:
   > So, can you not truncate a date to week, quarter?
   
   For now, `trunc()` (the `TruncDate` expression) cannot do that but you can 
use `date_trunc()` (`TruncTimestamp` expression) which does implicit conversion 
from `DATE` to `TIMESTAMP`:
   ```sql
   spark-sql> select date_trunc('quarter', DATE'2019-08-05');
   2019-07-01 00:00:00
   ```
   We can support those levels for `trunc()` (`DATE` type) as well. 

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