-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-29328][SQL] Fix calculation of mean seconds per month #25998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
65385a1
Add SECONDS_PER_MONTH and SECONDS_PER_YEAR
MaxGekk 9b58059
Use SECONDS_PER_MONTH in monthsBetween
MaxGekk b0f765a
Fix expected values in DateTimeUtilsSuite
MaxGekk 1019645
Fix expected values in DateExpressionsSuite
MaxGekk 285af30
Fix expected values in DateFunctionsSuite
MaxGekk f59e006
Use SECONDS_PER_MONTH in GroupStateImpl
MaxGekk e97f419
Add MILLIS_PER_MONTH
MaxGekk 71dc2c0
Use MILLIS_PER_MONTH in EventTimeWatermark
MaxGekk e7c9920
Use MILLIS_PER_MONTH in GroupStateImpl
MaxGekk 6125a6b
Remove SECONDS_PER_YEAR
MaxGekk 7e30ece
Fix examples of months_between
MaxGekk b4ecba4
Update expected values in pyspark.sql.functions
MaxGekk f444123
Update expected values in test_sparkSQL.R
MaxGekk 2e33203
Revert "Update expected values in test_sparkSQL.R"
MaxGekk 00a1988
Revert "Update expected values in pyspark.sql.functions"
MaxGekk 5256ff4
Revert "Fix examples of months_between"
MaxGekk c59443f
Revert "Fix expected values in DateFunctionsSuite"
MaxGekk 93a680b
Revert "Fix expected values in DateExpressionsSuite"
MaxGekk df2d97a
Revert "Fix expected values in DateTimeUtilsSuite"
MaxGekk 9d78910
Revert "Use SECONDS_PER_MONTH in monthsBetween"
MaxGekk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,9 @@ | |
| package org.apache.spark.sql.execution.streaming | ||
|
|
||
| import java.sql.Date | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
| import org.apache.spark.sql.catalyst.plans.logical.{EventTimeTimeout, ProcessingTimeTimeout} | ||
| import org.apache.spark.sql.catalyst.util.DateTimeUtils.MILLIS_PER_MONTH | ||
| import org.apache.spark.sql.execution.streaming.GroupStateImpl._ | ||
| import org.apache.spark.sql.streaming.{GroupState, GroupStateTimeout} | ||
| import org.apache.spark.unsafe.types.CalendarInterval | ||
|
|
@@ -164,8 +164,7 @@ private[sql] class GroupStateImpl[S] private( | |
| throw new IllegalArgumentException(s"Provided duration ($duration) is not positive") | ||
| } | ||
|
|
||
| val millisPerMonth = TimeUnit.MICROSECONDS.toMillis(CalendarInterval.MICROS_PER_DAY) * 31 | ||
| cal.milliseconds + cal.months * millisPerMonth | ||
| cal.milliseconds + cal.months * MILLIS_PER_MONTH | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's interesting since this change doesn't affect our tests. |
||
| } | ||
|
|
||
| private def checkTimeoutTimestampAllowed(): Unit = { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we need here is seconds per month, not seconds per year. I think we should still assume 31 days per month here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point out where we need seconds/days per year in the codebase?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe any place including this one when we need a duration (in seconds or its fractions). The difference between
months_between()and this place ismonths_betweenuses month length to calculate fraction of month, and 28 or 31 days per months don't really matter because it impacts on 2nd or 3rd digit in fractions but here we operate on bigger numbers when months form years. And it becomes matter how much days we use per year. Let's say we calculate the duration of 10 years which 120 months. If we use 31 days per months, this duration is 31 * 120 = 10 * 372 = 3720 days but if one year is 365.2425 than 10 years = 3652 days. The difference is 3720 - 3652 = 68 days or the calculation error is more than 2 months. That's matter I believe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
months_betweenis sort of a special case because "31 days per month" is (it seems) actually how it is supposed to work, correctly.It's rare that someone would specify "1 month" here, let alone "10 years" right? or am I missing something? these are things like watermark intervals. Not that it means the semantics don't matter, it's just quite a corner case.
I therefore just don't feel strongly either way about it. We don't need to match
months_betweensemantics. More precision is nice, but surely it almost never comes up anyway? I don't mind the change, as a result.