-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-46644] Change add and merge in SQLMetric to use isZero #44649
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
Conversation
sql/core/src/main/scala/org/apache/spark/sql/execution/metric/SQLMetrics.scala
Show resolved
Hide resolved
| // and instead return defaultValidValue. | ||
| override def value: Long = if (!isValid) defaultValidValue else _value | ||
| // and instead return 0. | ||
| override def value: Long = if (!isValid) 0 else _value |
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 we do if (isZero) 0 else _value? or we are worried about negative values due to bugs?
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.
Hm, it seems like tests fail because of a test with a positive initValue.
assert(SQLMetrics.createNanoTimingMetric(sparkContext, name = "m", initValue = 5).value === 5)
I don't think we ever use a positive initValue so we could either remove this or stick with the original check if(_value < 0).
|
thanks, merging to master! |
What changes were proposed in this pull request?
A previous refactor mistakenly used
isValidfor add. SincedefaultValidValuewas always0, this didn't cause any correctness issues.What we really want to do for add (and merge) is
if (isZero) _value = 0.Also removing
isValidsince its redundant, ifdefaultValidValueis always0.Why are the changes needed?
There are no correctness errors, but this is confusing and error-prone.
A negative
defaultValidValuewas intended to allow creating optional metrics. With the previous behavior this would incorrectly add the sentinel value.defaultValidValueis supposed to determine what value is exposed to the user.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Running the tests.
Was this patch authored or co-authored using generative AI tooling?
No.