You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "WweiL (via GitHub)" <gi...@apache.org> on 2023/02/01 08:19:17 UTC
[GitHub] [spark] WweiL opened a new pull request, #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
WweiL opened a new pull request, #39843:
URL: https://github.com/apache/spark/pull/39843
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
I tried to understand what was introduced in https://github.com/apache/spark/pull/36737 and made the code more readable and added some test. Sharing the credit with @nyingping.
The change in https://github.com/apache/spark/pull/35362 brought a bug when the `timestamp` is less than 0, i.e. before `1970-01-01 00:00:00 UTC`. Then for some windows, spark returns a wrong `windowStart` time. The root cause of this bug is how the module operator(%) works with negative number.
For example,
```
scala> 1 % 3
res0: Int = 1
scala> -1 % 3
res1: Int = -1 // Mathematically it should be 2 here
```
This lead to a wrong calculation result of `windowStart`. For a concrete example refer to the added comments in [ResolveTimeWindows.scala](https://github.com/WweiL/oss-spark/blob/fee352e46813cca1f1b6187ea9cfa27124b6049c/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTimeWindows.scala#L58-L67)
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
This is a bug fix.
Example from the original PR https://github.com/apache/spark/pull/36737:
Here df3 and df4 has time before 1970, so timestamp < 0.
```
val df3 = Seq(
("1969-12-31 00:00:02", 1),
("1969-12-31 00:00:12", 2)).toDF("time", "value")
val df4 = Seq(
(LocalDateTime.parse("1969-12-31T00:00:02"), 1),
(LocalDateTime.parse("1969-12-31T00:00:12"), 2)).toDF("time", "value") Seq(df3, df4).foreach { df =>
checkAnswer(
df.select(window($"time", "10 seconds", "10 seconds", "5 seconds"), $"value")
.orderBy($"window.start".asc)
.select($"window.start".cast(StringType), $"window.end".cast(StringType), $"value"),
Seq(
Row("1969-12-30 23:59:55", "1969-12-31 00:00:05", 1),
Row("1969-12-31 00:00:05", "1969-12-31 00:00:15", 2))
)
}
```
Without the change this would error with:
```
== Results ==
!== Correct Answer - 2 == == Spark Answer - 2 ==
!struct<> struct<CAST(window.start AS STRING):string,CAST(window.end AS STRING):string,value:int>
![1969-12-30 23:59:55,1969-12-31 00:00:05,1] [1969-12-31 00:00:05,1969-12-31 00:00:15,1]
![1969-12-31 00:00:05,1969-12-31 00:00:15,2] [1969-12-31 00:00:15,1969-12-31 00:00:25,2]
```
Notice how this is shifted with one `slideDuration`. It should start with `[1969-12-30 23:59:55,1969-12-31 00:00:05,1]` but spark returns `[1969-12-31 00:00:05,1969-12-31 00:00:15,1]`, right-shifted of one `slideDuration` (10 seconds).
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
Unit test.
### Benchmark results:
1. Burak's original Implementation
```
[info] Apple M1 Max
[info] tumbling windows: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative
[info] ------------------------------------------------------------------------------------------------------------------------
[info] burak version 10 17 14 962.7 1.0 1.0X
[info] Running benchmark: sliding windows
[info] Running case: burak version
[info] Stopped after 16 iterations, 10604 ms
[info] OpenJDK 64-Bit Server VM 11.0.12+7-LTS on Mac OS X 12.5.1
[info] Apple M1 Max
[info] sliding windows: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative
[info] ------------------------------------------------------------------------------------------------------------------------
[info] burak version 646 663 19 15.5 64.6 1.0X
```
2. Current implementation (buggy)
```
[info] Running benchmark: tumbling windows
[info] Running case: current - buggy
[info] Stopped after 637 iterations, 10008 ms
[info] OpenJDK 64-Bit Server VM 11.0.12+7-LTS on Mac OS X 12.5.1
[info] Apple M1 Max
[info] tumbling windows: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative
[info] ------------------------------------------------------------------------------------------------------------------------
[info] current - buggy 10 16 12 1042.7 1.0 1.0X
[info] Running benchmark: sliding windows
[info] Running case: current - buggy
[info] Stopped after 16 iterations, 10143 ms
[info] OpenJDK 64-Bit Server VM 11.0.12+7-LTS on Mac OS X 12.5.1
[info] Apple M1 Max
[info] sliding windows: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative
[info] ------------------------------------------------------------------------------------------------------------------------
[info] current - buggy 617 634 10 16.2 61.7 1.0X
```
3. Purposed change in this PR:
```
[info] Apple M1 Max
[info] tumbling windows: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative
[info] ------------------------------------------------------------------------------------------------------------------------
[info] purposed change 10 16 11 981.2 1.0 1.0X
[info] Running benchmark: sliding windows
[info] Running case: purposed change
[info] Stopped after 18 iterations, 10122 ms
[info] OpenJDK 64-Bit Server VM 11.0.12+7-LTS on Mac OS X 12.5.1
[info] Apple M1 Max
[info] sliding windows: Best Time(ms) Avg Time(ms) Stdev(ms) Rate(M/s) Per Row(ns) Relative
[info] ------------------------------------------------------------------------------------------------------------------------
[info] purposed change 548 562 19 18.3 54.8 1.0X
```
Note that I run them separately, because I found that if you run these tests sequentially, the later one will always get a performance gain. I think the computer is doing some optimizations.
--
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
[GitHub] [spark] WweiL commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "WweiL (via GitHub)" <gi...@apache.org>.
WweiL commented on code in PR #39843:
URL: https://github.com/apache/spark/pull/39843#discussion_r1095386680
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameTimeWindowingSuite.scala:
##########
@@ -314,6 +314,42 @@ class DataFrameTimeWindowingSuite extends QueryTest with SharedSparkSession {
Row("1970-01-01 00:00:05", "1970-01-01 00:00:15", 2))
)
}
+
+ val df3 = Seq(
+ ("1969-12-31 00:00:02", 1),
+ ("1969-12-31 00:00:12", 2)).toDF("time", "value")
+ val df4 = Seq(
+ (LocalDateTime.parse("1969-12-31T00:00:02"), 1),
+ (LocalDateTime.parse("1969-12-31T00:00:12"), 2)).toDF("time", "value")
+
+ Seq(df3, df4).foreach { df =>
+ checkAnswer(
+ df.select(window($"time", "10 seconds", "10 seconds", "5 seconds"), $"value")
+ .orderBy($"window.start".asc)
+ .select($"window.start".cast(StringType), $"window.end".cast(StringType), $"value"),
+ Seq(
+ Row("1969-12-30 23:59:55", "1969-12-31 00:00:05", 1),
+ Row("1969-12-31 00:00:05", "1969-12-31 00:00:15", 2))
+ )
+ }
+
+ val df5 = Seq(
Review Comment:
Right this is actually testing some other cases, below I put year `1968` not `1969`. The `1969` test case tests when window start is less than 0 but window end is greater than 0. I added this case to test when both start and end are less than 0.
--
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
[GitHub] [spark] WweiL commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "WweiL (via GitHub)" <gi...@apache.org>.
WweiL commented on code in PR #39843:
URL: https://github.com/apache/spark/pull/39843#discussion_r1095385441
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTimeWindows.scala:
##########
@@ -49,11 +49,23 @@ object TimeWindowing extends Rule[LogicalPlan] {
* The windows are calculated as below:
* maxNumOverlapping <- ceil(windowDuration / slideDuration)
* for (i <- 0 until maxNumOverlapping)
- * lastStart <- timestamp - (timestamp - startTime + slideDuration) % slideDuration
- * windowStart <- lastStart - i * slideDuration
+ * lastStart <- timestamp - (timestamp - startTime) % slideDuration
+ * lastStartAdjusted <- (timestamp < startTime) ? lastStart - slideDuration : lastStart
+ * windowStart <- lastStartAdjusted - i * slideDuration
* windowEnd <- windowStart + windowDuration
* return windowStart, windowEnd
*
+ * Rationale of lastStartAdjusted:
Review Comment:
May I know what's the suggestion here? Should I move this explanation to somewhere else?
--
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
[GitHub] [spark] HeartSaVioR commented on pull request #39843: [SPARK-39347][SS] Bug fix for time window calculation when event time < 0
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #39843:
URL: https://github.com/apache/spark/pull/39843#issuecomment-1418420365
Thanks! Merging to master/3.4/3.3.
--
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
[GitHub] [spark] HeartSaVioR closed pull request #39843: [SPARK-39347][SS] Bug fix for time window calculation when event time < 0
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR closed pull request #39843: [SPARK-39347][SS] Bug fix for time window calculation when event time < 0
URL: https://github.com/apache/spark/pull/39843
--
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
[GitHub] [spark] WweiL commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "WweiL (via GitHub)" <gi...@apache.org>.
WweiL commented on code in PR #39843:
URL: https://github.com/apache/spark/pull/39843#discussion_r1095384980
##########
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:
> and need not involve CaseWhen.
This is actually incorrect. Although `window.startTime` and `window.slideDuration` are `Long`, `timestamp` is `Expression`, and `remainder < 0` returns a `Predicate` not `boolean` so the complier complains.
> You just always want to subtract a nonnegative amount here.
Sure I could do that. I'll update a version with `CaseWhen` with your logic.
--
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
[GitHub] [spark] HeartSaVioR commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on code in PR #39843:
URL: https://github.com/apache/spark/pull/39843#discussion_r1093955585
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameTimeWindowingSuite.scala:
##########
@@ -314,6 +314,42 @@ class DataFrameTimeWindowingSuite extends QueryTest with SharedSparkSession {
Row("1970-01-01 00:00:05", "1970-01-01 00:00:15", 2))
)
}
+
+ val df3 = Seq(
+ ("1969-12-31 00:00:02", 1),
+ ("1969-12-31 00:00:12", 2)).toDF("time", "value")
+ val df4 = Seq(
+ (LocalDateTime.parse("1969-12-31T00:00:02"), 1),
+ (LocalDateTime.parse("1969-12-31T00:00:12"), 2)).toDF("time", "value")
+
+ Seq(df3, df4).foreach { df =>
+ checkAnswer(
+ df.select(window($"time", "10 seconds", "10 seconds", "5 seconds"), $"value")
+ .orderBy($"window.start".asc)
+ .select($"window.start".cast(StringType), $"window.end".cast(StringType), $"value"),
+ Seq(
+ Row("1969-12-30 23:59:55", "1969-12-31 00:00:05", 1),
+ Row("1969-12-31 00:00:05", "1969-12-31 00:00:15", 2))
+ )
+ }
+
+ val df5 = Seq(
Review Comment:
nit: is this test case testing other edge case than above one? Otherwise let's remove this.
--
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
[GitHub] [spark] HeartSaVioR commented on pull request #39843: [SPARK-39347][SS] Bug fix for time window calculation when event time < 0
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #39843:
URL: https://github.com/apache/spark/pull/39843#issuecomment-1418436041
There is merge conflict in branch-3.3. @WweiL Would you mind creating a backport PR for this? Thanks!
--
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
[GitHub] [spark] srowen commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on code in PR #39843:
URL: https://github.com/apache/spark/pull/39843#discussion_r1094624053
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTimeWindows.scala:
##########
@@ -49,11 +49,23 @@ object TimeWindowing extends Rule[LogicalPlan] {
* The windows are calculated as below:
* maxNumOverlapping <- ceil(windowDuration / slideDuration)
* for (i <- 0 until maxNumOverlapping)
- * lastStart <- timestamp - (timestamp - startTime + slideDuration) % slideDuration
- * windowStart <- lastStart - i * slideDuration
+ * lastStart <- timestamp - (timestamp - startTime) % slideDuration
+ * lastStartAdjusted <- (timestamp < startTime) ? lastStart - slideDuration : lastStart
+ * windowStart <- lastStartAdjusted - i * slideDuration
* windowEnd <- windowStart + windowDuration
* return windowStart, windowEnd
*
+ * Rationale of lastStartAdjusted:
Review Comment:
This doesn't belong in user-facing javadoc IMHO
--
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
[GitHub] [spark] WweiL commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "WweiL (via GitHub)" <gi...@apache.org>.
WweiL commented on code in PR #39843:
URL: https://github.com/apache/spark/pull/39843#discussion_r1096389516
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTimeWindows.scala:
##########
@@ -49,11 +49,23 @@ object TimeWindowing extends Rule[LogicalPlan] {
* The windows are calculated as below:
* maxNumOverlapping <- ceil(windowDuration / slideDuration)
* for (i <- 0 until maxNumOverlapping)
- * lastStart <- timestamp - (timestamp - startTime + slideDuration) % slideDuration
- * windowStart <- lastStart - i * slideDuration
+ * lastStart <- timestamp - (timestamp - startTime) % slideDuration
+ * lastStartAdjusted <- (timestamp < startTime) ? lastStart - slideDuration : lastStart
+ * windowStart <- lastStartAdjusted - i * slideDuration
* windowEnd <- windowStart + windowDuration
* return windowStart, windowEnd
*
+ * Rationale of lastStartAdjusted:
Review Comment:
I put it in the description of this PR
--
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
[GitHub] [spark] srowen commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "srowen (via GitHub)" <gi...@apache.org>.
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
[GitHub] [spark] HyukjinKwon commented on pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #39843:
URL: https://github.com/apache/spark/pull/39843#issuecomment-1413031117
cc @HeartSaVioR
--
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
[GitHub] [spark] WweiL commented on pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "WweiL (via GitHub)" <gi...@apache.org>.
WweiL commented on PR #39843:
URL: https://github.com/apache/spark/pull/39843#issuecomment-1418201621
> Looks good. I think we back-port this to 3.2? I can try that.
Thanks! That’d be very helpful! I can’t access my laptop right now.
--
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
[GitHub] [spark] srowen commented on pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on PR #39843:
URL: https://github.com/apache/spark/pull/39843#issuecomment-1418021777
Looks good. I think we back-port this to 3.2? I can try that.
--
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
[GitHub] [spark] srowen commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "srowen (via GitHub)" <gi...@apache.org>.
srowen commented on code in PR #39843:
URL: https://github.com/apache/spark/pull/39843#discussion_r1095835269
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTimeWindows.scala:
##########
@@ -49,11 +49,23 @@ object TimeWindowing extends Rule[LogicalPlan] {
* The windows are calculated as below:
* maxNumOverlapping <- ceil(windowDuration / slideDuration)
* for (i <- 0 until maxNumOverlapping)
- * lastStart <- timestamp - (timestamp - startTime + slideDuration) % slideDuration
- * windowStart <- lastStart - i * slideDuration
+ * lastStart <- timestamp - (timestamp - startTime) % slideDuration
+ * lastStartAdjusted <- (timestamp < startTime) ? lastStart - slideDuration : lastStart
+ * windowStart <- lastStartAdjusted - i * slideDuration
* windowEnd <- windowStart + windowDuration
* return windowStart, windowEnd
*
+ * Rationale of lastStartAdjusted:
Review Comment:
You could put it inside the function as comments, or omit it
--
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
[GitHub] [spark] WweiL commented on a diff in pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "WweiL (via GitHub)" <gi...@apache.org>.
WweiL commented on code in PR #39843:
URL: https://github.com/apache/spark/pull/39843#discussion_r1095384980
##########
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:
> and need not involve CaseWhen.
This is actually incorrect. Although `window.startTime` and `window.slideDuration` are `Long`, `timestamp` is `Expression`, and `remainder < 0` returns a `Predicate` not `boolean` so the complier complains.
> You just always want to subtract a nonnegative amount here.
Sure I could do that. I'll update a version with `CaseWhen` with your logic.
--
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
[GitHub] [spark] HeartSaVioR commented on pull request #39843: [SPARK-39347] [SS] Bug fix for time window calculation when event time < 0
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #39843:
URL: https://github.com/apache/spark/pull/39843#issuecomment-1413065699
@WweiL
Could you please add an empty commit having author as @nyingping ? (`nieyingping <ni...@alphadata.com.cn>`) That way we can give proper credit.
--
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
[GitHub] [spark] HeartSaVioR commented on pull request #39843: [SPARK-39347][SS] Bug fix for time window calculation when event time < 0
Posted by "HeartSaVioR (via GitHub)" <gi...@apache.org>.
HeartSaVioR commented on PR #39843:
URL: https://github.com/apache/spark/pull/39843#issuecomment-1418417815
SPARK-38069 was merged in Spark 3.3. Porting back to master/3.4/3.3 would be enough.
--
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
Re: [PR] [SPARK-39347][SS] Bug fix for time window calculation when event time < 0 [spark]
Posted by "corgy-w (via GitHub)" <gi...@apache.org>.
corgy-w commented on PR #39843:
URL: https://github.com/apache/spark/pull/39843#issuecomment-2335139809
> +1 I don't feel like co-auther credit is mandatory as the origin fix was also something he borrowed from Flink. Mentioning the credit in PR description seems sufficient.
I accidentally browsed the original author's blog and saw this PR. I think your sentence is incorrect. Even if it is a reference, it is a kind of discovery. Co-auther is a kind of affirmation. The submitter is maintaining a harmonious environment. You there is no need to deny it. Of course I'm just expressing thoughts, have a good life
--
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