You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "srowen (via GitHub)" <gi...@apache.org> on 2023/02/02 14:43:25 UTC

[GitHub] [spark] srowen commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0

srowen commented on code in PR #39843:
URL: https://github.com/apache/spark/pull/39843#discussion_r1094623314


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTimeWindows.scala:
##########
@@ -103,9 +115,10 @@ object TimeWindowing extends Rule[LogicalPlan] {
 
         def getWindow(i: Int, dataType: DataType): Expression = {
           val timestamp = PreciseTimestampConversion(window.timeColumn, dataType, LongType)
-          val lastStart = timestamp - (timestamp - window.startTime
-            + window.slideDuration) % window.slideDuration
-          val windowStart = lastStart - i * window.slideDuration
+          val lastStart = timestamp - (timestamp - window.startTime) % window.slideDuration

Review Comment:
   This seems a little complicated, and need not involve CaseWhen. You just always want to subtract a nonnegative amount here.
   
   ```
   val remainder = (timestamp - window.startTime) % window.slideDuration
   val lastStart = timestamp - (if (remainder < 0) remainder + window.slideDuration else remainder)
   ```



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

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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