Skip to content

Commit 1abbde0

Browse files
egraldlomarmbrus
authored andcommitted
[SQL] Add average overflow test case from apache#978
By @egraldlo. Author: egraldlo <[email protected]> Author: Michael Armbrust <[email protected]> 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().
1 parent 55a0e87 commit 1abbde0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ class SQLQuerySuite extends QueryTest {
136136
2.0)
137137
}
138138

139+
test("average overflow") {
140+
checkAnswer(
141+
sql("SELECT AVG(a),b FROM largeAndSmallInts group by b"),
142+
Seq((2147483645.0,1),(2.0,2)))
143+
}
144+
139145
test("count") {
140146
checkAnswer(
141147
sql("SELECT COUNT(*) FROM testData2"),

sql/core/src/test/scala/org/apache/spark/sql/TestData.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ object TestData {
3030
(1 to 100).map(i => TestData(i, i.toString)))
3131
testData.registerAsTable("testData")
3232

33+
case class LargeAndSmallInts(a: Int, b: Int)
34+
val largeAndSmallInts: SchemaRDD =
35+
TestSQLContext.sparkContext.parallelize(
36+
LargeAndSmallInts(2147483644, 1) ::
37+
LargeAndSmallInts(1, 2) ::
38+
LargeAndSmallInts(2147483645, 1) ::
39+
LargeAndSmallInts(2, 2) ::
40+
LargeAndSmallInts(2147483646, 1) ::
41+
LargeAndSmallInts(3, 2) :: Nil)
42+
largeAndSmallInts.registerAsTable("largeAndSmallInts")
43+
3344
case class TestData2(a: Int, b: Int)
3445
val testData2: SchemaRDD =
3546
TestSQLContext.sparkContext.parallelize(

0 commit comments

Comments
 (0)