Skip to content

Conversation

@davintjong-db
Copy link
Contributor

@davintjong-db davintjong-db commented Jan 10, 2024

What changes were proposed in this pull request?

A previous refactor mistakenly used isValid for add. Since defaultValidValue was always 0, this didn't cause any correctness issues.

What we really want to do for add (and merge) is if (isZero) _value = 0.

Also removing isValid since its redundant, if defaultValidValue is always 0.

Why are the changes needed?

There are no correctness errors, but this is confusing and error-prone.

A negative defaultValidValue was intended to allow creating optional metrics. With the previous behavior this would incorrectly add the sentinel value. defaultValidValue is 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.

@github-actions github-actions bot added the SQL label Jan 10, 2024
@davintjong-db davintjong-db changed the title [SPARK-46644] Fix add and merge in SQLMetric [SPARK-46644] Change add and merge in SQLMetric to use isZero Jan 10, 2024
@davintjong-db davintjong-db marked this pull request as ready for review January 10, 2024 05:47
// 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
Copy link
Contributor

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?

Copy link
Contributor Author

@davintjong-db davintjong-db Jan 12, 2024

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

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 89727bf Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants