-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-14163][CORE] SumEvaluator and countApprox cannot reliably handle RDDs of size 1 #12016
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 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3b26826
Use confidence when count is 1.
mtustin-handy 3faecc4
Set infinite confidence if count is 1 or otherwise confidence would b…
mtustin-handy 93bcd99
Update tests, reformat additions.
mtustin-handy 5db9678
Fix style errors, use equality now exact values are known.
mtustin-handy 5e3c477
Fix scalastyle errors.
mtustin-handy 4040e0e
Put toString back to how it was (only print bounds).
mtustin-handy 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
107 changes: 107 additions & 0 deletions
107
core/src/test/scala/org/apache/spark/partial/SumEvaluatorSuite.scala
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 |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.partial | ||
|
|
||
| import org.apache.spark._ | ||
| import org.apache.spark.util.StatCounter | ||
|
|
||
| class SumEvaluatorSuite extends SparkFunSuite with SharedSparkContext { | ||
|
|
||
| test("correct handling of count 1") { | ||
|
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. While you're here throw in a basic test for count == 0 too, and ideally some normal-path case for completeness
Contributor
Author
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. Done. |
||
|
|
||
| // setup | ||
| val counter = new StatCounter(List(2.0)) | ||
| // count of 10 because it's larger than 1, | ||
| // and 0.95 because that's the default | ||
| val evaluator = new SumEvaluator(10, 0.95) | ||
| // arbitrarily assign id 1 | ||
| evaluator.merge(1, counter) | ||
|
|
||
| // execute | ||
| val res = evaluator.currentResult() | ||
| // 38.0 - 7.1E-15 because that's how the maths shakes out | ||
| val targetMean = 38.0 - 7.1E-15 | ||
|
|
||
| // Sanity check that equality works on BoundedDouble | ||
| assert(new BoundedDouble(2.0, 0.95, 1.1, 1.2) == new BoundedDouble(2.0, 0.95, 1.1, 1.2)) | ||
|
|
||
| // actual test | ||
| assert(res == | ||
| new BoundedDouble(targetMean, 0.950, Double.NegativeInfinity, Double.PositiveInfinity)) | ||
| } | ||
|
|
||
| test("correct handling of count 0") { | ||
|
|
||
| // setup | ||
| val counter = new StatCounter(List()) | ||
| // count of 10 because it's larger than 0, | ||
| // and 0.95 because that's the default | ||
| val evaluator = new SumEvaluator(10, 0.95) | ||
| // arbitrarily assign id 1 | ||
| evaluator.merge(1, counter) | ||
|
|
||
| // execute | ||
| val res = evaluator.currentResult() | ||
| // assert | ||
| assert(res == new BoundedDouble(0, 0.0, Double.NegativeInfinity, Double.PositiveInfinity)) | ||
| } | ||
|
|
||
| test("correct handling of NaN") { | ||
|
|
||
| // setup | ||
| val counter = new StatCounter(List(1, Double.NaN, 2)) | ||
| // count of 10 because it's larger than 0, | ||
| // and 0.95 because that's the default | ||
| val evaluator = new SumEvaluator(10, 0.95) | ||
| // arbitrarily assign id 1 | ||
| evaluator.merge(1, counter) | ||
|
|
||
| // execute | ||
| val res = evaluator.currentResult() | ||
| // assert - note semantics of == in face of NaN | ||
| assert(res.mean.isNaN) | ||
| assert(res.confidence == 0.95) | ||
| assert(res.low == Double.NegativeInfinity) | ||
| assert(res.high == Double.PositiveInfinity) | ||
| } | ||
|
|
||
| test("correct handling of > 1 values") { | ||
|
|
||
| // setup | ||
| val counter = new StatCounter(List(1, 3, 2)) | ||
| // count of 10 because it's larger than 0, | ||
| // and 0.95 because that's the default | ||
| val evaluator = new SumEvaluator(10, 0.95) | ||
| // arbitrarily assign id 1 | ||
| evaluator.merge(1, counter) | ||
|
|
||
| // execute | ||
| val res = evaluator.currentResult() | ||
|
|
||
| // These vals because that's how the maths shakes out | ||
| val targetMean = 78.0 | ||
| val targetLow = -117.617 + 2.732357258139473E-5 | ||
| val targetHigh = 273.617 - 2.7323572624027292E-5 | ||
| val target = new BoundedDouble(targetMean, 0.95, targetLow, targetHigh) | ||
|
|
||
|
|
||
| // check that values are within expected tolerance of expectation | ||
| assert(res == target) | ||
| } | ||
|
|
||
| } | ||
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.
OK, I think this is all good, except I think the
toStringshould be left alone. I forgot to mention this. Not that I really expect anyone to depend on the format, but let's leave it since it's a public class.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 definitely can put it back, but the previous toString was just weird - it
only printed the bounds. Anyway, I'll update this in a sec (to go back).
Let me know if you change your mind.
On Saturday, April 2, 2016, Sean Owen [email protected] wrote:
Want to work at Handy? Check out our culture deck and open roles
http://www.handy.com/careers
Latest news http://www.handy.com/press at Handy
Handy just raised $50m
http://venturebeat.com/2015/11/02/on-demand-home-service-handy-raises-50m-in-round-led-by-fidelity/ led
by Fidelity
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.
Done.