Skip to content

Commit

Permalink
Add test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
beliefer committed Nov 11, 2020
1 parent e296eb6 commit f851a4c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.sql.catalyst.optimizer

import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.dsl.plans._
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.aggregate.First
import org.apache.spark.sql.catalyst.plans.PlanTest
import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, LogicalPlan}
import org.apache.spark.sql.catalyst.rules.RuleExecutor

class OptimizeWindowFunctionsSuite extends PlanTest {
object Optimize extends RuleExecutor[LogicalPlan] {
val batches = Batch("OptimizeWindowFunctions", FixedPoint(10),
OptimizeWindowFunctions) :: Nil
}

test("check OptimizeWindowFunctions") {
val testRelation = LocalRelation('a.double, 'b.double, 'c.string)
val a = testRelation.output.head
val inputPlan = testRelation.select(
WindowExpression(
First(a, false).toAggregateExpression(),
WindowSpecDefinition(Nil, a.asc :: Nil,
SpecifiedWindowFrame(RowFrame, UnboundedPreceding, CurrentRow))))
val correctAnswer = testRelation.select(
WindowExpression(
NthValue(a, Literal(1), false),
WindowSpecDefinition(Nil, a.asc :: Nil,
SpecifiedWindowFrame(RowFrame, UnboundedPreceding, CurrentRow))))

val optimized = Optimize.execute(inputPlan)
assert(optimized == correctAnswer)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession with SQLHelper
// Filter out test files with invalid extensions such as temp files created
// by vi (.swp), Mac (.DS_Store) etc.
val filteredFiles = files.filter(_.getName.endsWith(validFileExtensions))
filteredFiles ++ dirs.flatMap(listFilesRecursively)
(filteredFiles ++ dirs.flatMap(listFilesRecursively))
.filter(_.getName.equals("window.sql"))
}

/** Load built-in test tables into the SparkSession. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,30 @@ class DataFrameReaderWriterSuite extends QueryTest with SharedSparkSession with
}
}

test("abc2") {
spark.sql("create table SPARK_33045(id string) using parquet")
val values = Range(1, 90000)
spark.sql(s"select concat_ws(${values.mkString(", ")})").show
}

test("abc1") {
spark.sql("create table SPARK_33045(id string) using parquet")
val values = Range(1, 9000)
spark.sql(s"select * from SPARK_33045 where id in (${values.mkString(", ")}, id)").show
}

test("abc") {
spark.sql("create table SPARK_33045(id string) using parquet")
val values = Range(1, 9000)
spark.sql(s"select * from SPARK_33045 where id like all (${values.mkString(", ")})").show
}

test("concat") {
spark.sql("create table SPARK_33045(id int) using parquet")
val values = Range(1, 900)
spark.sql(s"select concat(${values.mkString(", ")}, id) from SPARK_33045").show
}

test("Insert overwrite table command should output correct schema: basic") {
withTable("tbl", "tbl2") {
withView("view1") {
Expand Down

0 comments on commit f851a4c

Please sign in to comment.