Skip to content

Commit

Permalink
style and readability updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sethah committed Oct 22, 2015
1 parent 345463e commit 3ef2faa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,8 @@ abstract class CentralMomentAgg(child: Expression) extends ImperativeAggregate w
* Initialize all moments to zero.
*/
override def initialize(buffer: MutableRow): Unit = {
var aggIndex = 0
while (aggIndex < numMoments) {
for (aggIndex <- 0 until numMoments) {
buffer.setDouble(mutableAggBufferOffset + aggIndex, 0.0)
aggIndex += 1
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class DataFrameAggregateSuite extends QueryTest with SharedSQLContext {
val expectedVariancePop = Row(4.0 / 6.0)
checkAggregatesWithTol(sparkVariancePop, expectedVariancePop, absTol)

val sparkSkewness= testData2.agg(skewness('a))
val sparkSkewness = testData2.agg(skewness('a))
val expectedSkewness = Row(0.0)
checkAggregatesWithTol(sparkSkewness, expectedSkewness, absTol)

Expand Down
7 changes: 5 additions & 2 deletions sql/core/src/test/scala/org/apache/spark/sql/QueryTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,17 @@ abstract class QueryTest extends PlanTest {
* @param expectedAnswer the expected result in a [[Seq]] of [[Row]]s.
* @param absTol the absolute tolerance between actual and expected answers.
*/
protected def checkAggregatesWithTol(dataFrame: DataFrame, expectedAnswer: Seq[Row], absTol: Double): Unit = {
protected def checkAggregatesWithTol(dataFrame: DataFrame,
expectedAnswer: Seq[Row],
absTol: Double): Unit = {
// TODO: catch exceptions in data frame execution
val actualAnswer = dataFrame.collect()
require(actualAnswer.length == expectedAnswer.length,
s"actual num rows ${actualAnswer.length} != expected num of rows ${expectedAnswer.length}")

actualAnswer.zip(expectedAnswer).foreach {
case (actualRow, expectedRow) => QueryTest.checkAggregatesWithTol(actualRow, expectedRow, absTol)
case (actualRow, expectedRow) =>
QueryTest.checkAggregatesWithTol(actualRow, expectedRow, absTol)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,13 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
test("stddev agg") {
checkAnswer(
sql("SELECT a, stddev(b), stddev_pop(b), stddev_samp(b) FROM testData2 GROUP BY a"),
(1 to 3).map(i => Row(i, math.sqrt(1 / 2.0), math.sqrt(1 / 4.0), math.sqrt(1 / 2.0))))
(1 to 3).map(i => Row(i, math.sqrt(1.0 / 2.0), math.sqrt(1.0 / 4.0), math.sqrt(1.0 / 2.0))))
}

test("variance agg") {
val absTol = 1e-8
val sparkAnswer = sql("SELECT a, variance(b), var_samp(b), var_pop(b) FROM testData2 GROUP BY a")
val sparkAnswer = sql("SELECT a, variance(b), var_samp(b), var_pop(b)" +
"FROM testData2 GROUP BY a")
val expectedAnswer = (1 to 3).map(i => Row(i, 1.0 / 2.0, 1.0 / 2.0, 1.0 / 4.0))
checkAggregatesWithTol(sparkAnswer, expectedAnswer, absTol)
}
Expand Down

0 comments on commit 3ef2faa

Please sign in to comment.