[GitHub] [spark] yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add the justify_days(), justify_hours() and justif_interval() functions

2019-11-12 Thread GitBox
yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add 
the justify_days(), justify_hours() and justif_interval() functions
URL: https://github.com/apache/spark/pull/26465#discussion_r345536928
 
 

 ##
 File path: sql/core/src/test/resources/sql-tests/inputs/postgreSQL/interval.sql
 ##
 @@ -342,3 +333,10 @@ SELECT interval '1 2:03:04' minute to second;
 -- select make_interval(secs := 'inf');
 -- select make_interval(secs := 'NaN');
 -- select make_interval(secs := 7e12);
+
+-- test justify_hours() and justify_days()
+SELECT justify_hours(interval '6 months 3 days 52 hours 3 minutes 2 seconds') 
as `6 mons 5 days 4 hours 3 mins 2 seconds`;
+SELECT justify_days(interval '6 months 36 days 5 hours 4 minutes 3 seconds') 
as `7 mons 6 days 5 hours 4 mins 3 seconds`;
+
+-- test justify_interval()
+SELECT justify_interval(interval '1 month -1 hour') as `1 month -1 hour`;
 
 Review comment:
   OK, I just wanted to make the diff smalle. I'd move them back


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


With regards,
Apache Git Services

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



[GitHub] [spark] yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add the justify_days(), justify_hours() and justif_interval() functions

2019-11-12 Thread GitBox
yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add 
the justify_days(), justify_hours() and justif_interval() functions
URL: https://github.com/apache/spark/pull/26465#discussion_r345536254
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
 ##
 @@ -637,4 +637,40 @@ object IntervalUtils {
 
 new CalendarInterval(totalMonths, totalDays, micros)
   }
+
+  /**
+   * Adjust interval so 30-day time periods are represented as months
+   */
+  def justifyDays(interval: CalendarInterval): CalendarInterval = {
+val monthToDays = interval.months * DAYS_PER_MONTH
+val totalDays = Math.addExact(monthToDays, interval.days)
+val months = Math.toIntExact(totalDays / DAYS_PER_MONTH)
+val days = Math.toIntExact(totalDays % DAYS_PER_MONTH)
+new CalendarInterval(months, days, interval.microseconds)
+  }
+
+  /**
+   * Adjust interval so 24-hour time periods are represented as days
+   */
+  def justifyHours(interval: CalendarInterval): CalendarInterval = {
+val dayToUs = MICROS_PER_DAY * interval.days
+val totalUs = Math.addExact(interval.microseconds, dayToUs)
+val days = Math.toIntExact(totalUs / MICROS_PER_DAY)
+val microseconds = totalUs % MICROS_PER_DAY
+new CalendarInterval(interval.months, days, microseconds)
+  }
+
+  /**
+   * Adjust interval using justifyHours and justifyDays, with additional sign 
adjustments
+   */
+  def justifyInterval(interval: CalendarInterval): CalendarInterval = {
+val monthToDays = DAYS_PER_MONTH * interval.months
+val dayToUs = Math.multiplyExact(monthToDays + interval.days, 
MICROS_PER_DAY)
+val totalUs = Math.addExact(interval.microseconds, dayToUs)
+val microseconds = totalUs % MICROS_PER_DAY
+val totalDays = totalUs / MICROS_PER_DAY
+val days = totalDays % DAYS_PER_MONTH
+val months = Math.toIntExact(totalDays / DAYS_PER_MONTH)
 
 Review comment:
   ok, i'd remove these useless overflow check


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


With regards,
Apache Git Services

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



[GitHub] [spark] yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add the justify_days(), justify_hours() and justif_interval() functions

2019-11-12 Thread GitBox
yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add 
the justify_days(), justify_hours() and justif_interval() functions
URL: https://github.com/apache/spark/pull/26465#discussion_r345300782
 
 

 ##
 File path: sql/core/src/test/resources/sql-tests/inputs/postgreSQL/interval.sql
 ##
 @@ -156,15 +156,6 @@
 -- [SPARK-29389] Support synonyms for interval units
 -- select '1y 10mon -10d -10h -10min -10.01s 
ago'::interval;
 
--- test justify_hours() and justify_days()
--- [SPARK-29390] Add the justify_days(), justify_hours() and 
justify_interval() functions
 
 Review comment:
   my fault


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


With regards,
Apache Git Services

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



[GitHub] [spark] yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add the justify_days(), justify_hours() and justif_interval() functions

2019-11-12 Thread GitBox
yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add 
the justify_days(), justify_hours() and justif_interval() functions
URL: https://github.com/apache/spark/pull/26465#discussion_r345269256
 
 

 ##
 File path: sql/core/src/test/resources/sql-tests/inputs/postgreSQL/interval.sql
 ##
 @@ -342,3 +333,11 @@ SELECT interval '1 2:03:04' minute to second;
 -- select make_interval(secs := 'inf');
 -- select make_interval(secs := 'NaN');
 -- select make_interval(secs := 7e12);
+
+-- test justify_hours() and justify_days()
+-- [SPARK-29390] Add the justify_days(), justify_hours() and 
justify_interval() functions
 
 Review comment:
   I'd rather remove these too. I will push a new commit to delete these.


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


With regards,
Apache Git Services

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



[GitHub] [spark] yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add the justify_days(), justify_hours() and justif_interval() functions

2019-11-12 Thread GitBox
yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add 
the justify_days(), justify_hours() and justif_interval() functions
URL: https://github.com/apache/spark/pull/26465#discussion_r345087602
 
 

 ##
 File path: sql/core/src/test/resources/sql-tests/inputs/postgreSQL/interval.sql
 ##
 @@ -342,3 +333,11 @@ SELECT interval '1 2:03:04' minute to second;
 -- select make_interval(secs := 'inf');
 -- select make_interval(secs := 'NaN');
 -- select make_interval(secs := 7e12);
+
+-- test justify_hours() and justify_days()
+-- [SPARK-29390] Add the justify_days(), justify_hours() and 
justify_interval() functions
 
 Review comment:
   I have some similar PRs which also modify PostgreSQL ported tests, mostly 
will be requested to leave or enable these tests. I guess they just want to 
track the progress of PostgreSQL feature parity in Spark. 


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


With regards,
Apache Git Services

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



[GitHub] [spark] yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add the justify_days(), justify_hours() and justif_interval() functions

2019-11-11 Thread GitBox
yaooqinn commented on a change in pull request #26465: [SPARK-29390][SQL] Add 
the justify_days(), justify_hours() and justif_interval() functions
URL: https://github.com/apache/spark/pull/26465#discussion_r345057918
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
 ##
 @@ -637,4 +637,39 @@ object IntervalUtils {
 
 new CalendarInterval(totalMonths, totalDays, micros)
   }
+
+  /**
+   * Adjust interval so 30-day time periods are represented as months
+   */
+  def justifyDays(interval: CalendarInterval): CalendarInterval = {
+val months = Math.addExact(interval.months, interval.days / 
DAYS_PER_MONTH.toInt)
 
 Review comment:
   good catch, we shall calculate all days first just like other 2 funcs


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


With regards,
Apache Git Services

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