Skip to content

Commit f851a4c

Browse files
committed
Add test case.
1 parent e296eb6 commit f851a4c

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql.catalyst.optimizer
19+
20+
import org.apache.spark.sql.catalyst.dsl.expressions._
21+
import org.apache.spark.sql.catalyst.dsl.plans._
22+
import org.apache.spark.sql.catalyst.expressions._
23+
import org.apache.spark.sql.catalyst.expressions.aggregate.First
24+
import org.apache.spark.sql.catalyst.plans.PlanTest
25+
import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, LogicalPlan}
26+
import org.apache.spark.sql.catalyst.rules.RuleExecutor
27+
28+
class OptimizeWindowFunctionsSuite extends PlanTest {
29+
object Optimize extends RuleExecutor[LogicalPlan] {
30+
val batches = Batch("OptimizeWindowFunctions", FixedPoint(10),
31+
OptimizeWindowFunctions) :: Nil
32+
}
33+
34+
test("check OptimizeWindowFunctions") {
35+
val testRelation = LocalRelation('a.double, 'b.double, 'c.string)
36+
val a = testRelation.output.head
37+
val inputPlan = testRelation.select(
38+
WindowExpression(
39+
First(a, false).toAggregateExpression(),
40+
WindowSpecDefinition(Nil, a.asc :: Nil,
41+
SpecifiedWindowFrame(RowFrame, UnboundedPreceding, CurrentRow))))
42+
val correctAnswer = testRelation.select(
43+
WindowExpression(
44+
NthValue(a, Literal(1), false),
45+
WindowSpecDefinition(Nil, a.asc :: Nil,
46+
SpecifiedWindowFrame(RowFrame, UnboundedPreceding, CurrentRow))))
47+
48+
val optimized = Optimize.execute(inputPlan)
49+
assert(optimized == correctAnswer)
50+
}
51+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,8 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession with SQLHelper
563563
// Filter out test files with invalid extensions such as temp files created
564564
// by vi (.swp), Mac (.DS_Store) etc.
565565
val filteredFiles = files.filter(_.getName.endsWith(validFileExtensions))
566-
filteredFiles ++ dirs.flatMap(listFilesRecursively)
566+
(filteredFiles ++ dirs.flatMap(listFilesRecursively))
567+
.filter(_.getName.equals("window.sql"))
567568
}
568569

569570
/** Load built-in test tables into the SparkSession. */

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,30 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSparkSession with
10331033
}
10341034
}
10351035

1036+
test("abc2") {
1037+
spark.sql("create table SPARK_33045(id string) using parquet")
1038+
val values = Range(1, 90000)
1039+
spark.sql(s"select concat_ws(${values.mkString(", ")})").show
1040+
}
1041+
1042+
test("abc1") {
1043+
spark.sql("create table SPARK_33045(id string) using parquet")
1044+
val values = Range(1, 9000)
1045+
spark.sql(s"select * from SPARK_33045 where id in (${values.mkString(", ")}, id)").show
1046+
}
1047+
1048+
test("abc") {
1049+
spark.sql("create table SPARK_33045(id string) using parquet")
1050+
val values = Range(1, 9000)
1051+
spark.sql(s"select * from SPARK_33045 where id like all (${values.mkString(", ")})").show
1052+
}
1053+
1054+
test("concat") {
1055+
spark.sql("create table SPARK_33045(id int) using parquet")
1056+
val values = Range(1, 900)
1057+
spark.sql(s"select concat(${values.mkString(", ")}, id) from SPARK_33045").show
1058+
}
1059+
10361060
test("Insert overwrite table command should output correct schema: basic") {
10371061
withTable("tbl", "tbl2") {
10381062
withView("view1") {

0 commit comments

Comments
 (0)