You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/10/20 15:47:10 UTC

[GitHub] [spark] srowen commented on a change in pull request #26177: [SPARK-29520][SS] Fix checks of negative intervals

srowen commented on a change in pull request #26177: [SPARK-29520][SS] Fix checks of negative intervals
URL: https://github.com/apache/spark/pull/26177#discussion_r336784300
 
 

 ##########
 File path: common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java
 ##########
 @@ -409,4 +410,25 @@ private void appendUnit(StringBuilder sb, long value, String unit) {
       sb.append(' ').append(value).append(' ').append(unit).append('s');
     }
   }
+
+  /**
+   * Gets interval duration
+   * @param daysPerMonth the number of days per one month
+   * @param targetUnit time units of the result
+   * @return duration in the specified time units
+   */
+  public long getDuration(int daysPerMonth, TimeUnit targetUnit) {
+    long monthsDuration = Math.multiplyExact(daysPerMonth * MICROS_PER_DAY, months);
+    long result = Math.addExact(microseconds, monthsDuration);
+    return targetUnit.convert(result, TimeUnit.MICROSECONDS);
+  }
+
+  /**
+   * Checks the interval is negative
+   * @param daysPerMonth the number of days per one month
+   * @return true if duration of the given interval is less than 0 otherwise false
+   */
+  public boolean isNegative(int daysPerMonth) {
 
 Review comment:
   Hm, on a second look:
   - Can this be static? 
   - Can the methods be package private?
   - Why does the caller define how many days are in a month? would that assumption not be fixed?
   - More generally, do we really need to allow for negative intervals at all? semantically it's nonnegative. Is it allowed in SQL?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org