MaxGekk commented on a change in pull request #31765:
URL: https://github.com/apache/spark/pull/31765#discussion_r589241739



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -791,4 +791,35 @@ object IntervalUtils {
    * @return A [[Duration]], not null
    */
   def microsToDuration(micros: Long): Duration = Duration.of(micros, 
ChronoUnit.MICROS)
+
+  /**
+   * Gets the total number of months in this period.
+   * <p>
+   * This returns the total number of months in the period by multiplying the
+   * number of years by 12 and adding the number of months.
+   * <p>
+   *
+   * @return The total number of months in the period, may be negative
+   * @throws ArithmeticException If numeric overflow occurs
+   */
+  def periodToMonths(period: Period): Int = {

Review comment:
       We don't fail when we convert:
   
   1. `java.sql.Date` has time component with millisecond precision but we 
ignore it when we convert to days at 
https://github.com/apache/spark/blob/56e664c7179eadeb5134b4418f3aaa6a9d742ef6/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala#L93
   2. `java.sql.Timestamp` which has nanoseconds precision: 
https://github.com/apache/spark/blob/56e664c7179eadeb5134b4418f3aaa6a9d742ef6/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala#L166
   3. `java.time.Instant` which contains nanoseconds, and we don't fail when we 
convert it to microseconds: 
https://github.com/apache/spark/blob/56e664c7179eadeb5134b4418f3aaa6a9d742ef6/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala#L383
   
   To be consistent with current implementation for other types, I do believe 
we should not fail.
   
   > Or at least give a warning?
   
   This will just fill in the logs by useless records, and this is again 
inconsistent with current implementation.




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