@@ -22,6 +22,7 @@ import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
2222import org .apache .spark .sql .test .SharedSQLContext
2323
2424case class WindowData (month : Int , area : String , product : Int )
25+ case class EmpSalary (empno : Int , depname : String , salary : Double )
2526
2627
2728/**
@@ -31,6 +32,19 @@ class SQLWindowFunctionSuite extends QueryTest with SharedSQLContext {
3132
3233 import testImplicits ._
3334
35+ val empSalaryData = Seq (
36+ EmpSalary (11 , " develop" , 5200D ),
37+ EmpSalary (7 , " develop" , 4200D ),
38+ EmpSalary (9 , " develop" , 4500D ),
39+ EmpSalary (8 , " develop" , 6000D ),
40+ EmpSalary (10 , " develop" , 5200D ),
41+ EmpSalary (5 , " personnel" , 3500D ),
42+ EmpSalary (2 , " personnel" , 3900D ),
43+ EmpSalary (3 , " sales" , 4800D ),
44+ EmpSalary (1 , " sales" , 5000D ),
45+ EmpSalary (4 , " sales" , 4800D )
46+ )
47+
3448 test(" window function: udaf with aggregate expression" ) {
3549 val data = Seq (
3650 WindowData (1 , " a" , 5 ),
@@ -173,6 +187,30 @@ class SQLWindowFunctionSuite extends QueryTest with SharedSQLContext {
173187 ).map(i => Row (i._1, i._2, i._3, i._4)))
174188 }
175189
190+ test(" window function: allow parentheses around window reference" ) {
191+ sparkContext.parallelize(empSalaryData).toDF().createOrReplaceTempView(" empsalary" )
192+
193+ checkAnswer(
194+ sql(
195+ """
196+ |SELECT sum(salary) OVER (w), avg(salary) OVER w
197+ |FROM empsalary
198+ |WINDOW w AS (PARTITION BY depname ORDER BY salary DESC)
199+ """ .stripMargin),
200+ Seq (
201+ (6000 , 6000 ),
202+ (16400 , 5466.6666666666666667D ),
203+ (16400 , 5466.6666666666666667 ),
204+ (20900 , 5225 ),
205+ (25100 , 5020 ),
206+ (3900 , 3900 ),
207+ (7400 , 3700 ),
208+ (5000 , 5000 ),
209+ (14600 , 4866.6666666666666667 ),
210+ (14600 , 4866.6666666666666667 )
211+ ).map(i => Row (i._1, i._2)))
212+ }
213+
176214 test(" window function: distinct should not be silently ignored" ) {
177215 val data = Seq (
178216 WindowData (1 , " a" , 5 ),
0 commit comments