Skip to content

Commit

Permalink
[SQL] Add average overflow test case from apache#978
Browse files Browse the repository at this point in the history
By @egraldlo.

Author: egraldlo <egraldlo@gmail.com>
Author: Michael Armbrust <michael@databricks.com>

Closes apache#1033 from marmbrus/pr/978 and squashes the following commits:

e228c5e [Michael Armbrust] Remove "test".
762aeaf [Michael Armbrust] Remove unneeded rule. More descriptive name for test table.
d414cd7 [egraldlo] fommatting issues
1153f75 [egraldlo] do best to avoid overflowing in function avg().
  • Loading branch information
egraldlo authored and marmbrus committed Jun 10, 2014
1 parent 55a0e87 commit 1abbde0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ class SQLQuerySuite extends QueryTest {
2.0)
}

test("average overflow") {
checkAnswer(
sql("SELECT AVG(a),b FROM largeAndSmallInts group by b"),
Seq((2147483645.0,1),(2.0,2)))
}

test("count") {
checkAnswer(
sql("SELECT COUNT(*) FROM testData2"),
Expand Down
11 changes: 11 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ object TestData {
(1 to 100).map(i => TestData(i, i.toString)))
testData.registerAsTable("testData")

case class LargeAndSmallInts(a: Int, b: Int)
val largeAndSmallInts: SchemaRDD =
TestSQLContext.sparkContext.parallelize(
LargeAndSmallInts(2147483644, 1) ::
LargeAndSmallInts(1, 2) ::
LargeAndSmallInts(2147483645, 1) ::
LargeAndSmallInts(2, 2) ::
LargeAndSmallInts(2147483646, 1) ::
LargeAndSmallInts(3, 2) :: Nil)
largeAndSmallInts.registerAsTable("largeAndSmallInts")

case class TestData2(a: Int, b: Int)
val testData2: SchemaRDD =
TestSQLContext.sparkContext.parallelize(
Expand Down

0 comments on commit 1abbde0

Please sign in to comment.