Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
beliefer committed Apr 8, 2020
1 parent 8ab2a0c commit 45bba4c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 51 deletions.
16 changes: 8 additions & 8 deletions sql/core/src/test/resources/sql-tests/results/limit.sql.out
Expand Up @@ -7,8 +7,8 @@ SELECT * FROM testdata LIMIT 2
-- !query schema
struct<key:int,value:string>
-- !query output
1 1
2 2
51 51
52 52


-- !query
Expand All @@ -34,17 +34,17 @@ SELECT * FROM testdata LIMIT 2 + 1
-- !query schema
struct<key:int,value:string>
-- !query output
1 1
2 2
3 3
51 51
52 52
53 53


-- !query
SELECT * FROM testdata LIMIT CAST(1 AS int)
-- !query schema
struct<key:int,value:string>
-- !query output
1 1
51 51


-- !query
Expand All @@ -70,7 +70,7 @@ SELECT * FROM testdata LIMIT CAST(1 AS INT)
-- !query schema
struct<key:int,value:string>
-- !query output
1 1
51 51


-- !query
Expand All @@ -88,7 +88,7 @@ SELECT * FROM testdata LIMIT key > 3
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
The limit expression must evaluate to a constant value, but got (testdata.`key` > 3);
The limit expression must evaluate to a constant value, but got (spark_catalog.default.testdata.`key` > 3);


-- !query
Expand Down
12 changes: 0 additions & 12 deletions sql/core/src/test/resources/sql-tests/results/show-tables.sql.out
Expand Up @@ -63,31 +63,19 @@ SHOW TABLES
-- !query schema
struct<database:string,tableName:string,isTemporary:boolean>
-- !query output
aggtest
arraydata
mapdata
onek
show_t1
show_t2
show_t3
tenk1
testdata


-- !query
SHOW TABLES IN showdb
-- !query schema
struct<database:string,tableName:string,isTemporary:boolean>
-- !query output
aggtest
arraydata
mapdata
onek
show_t1
show_t2
show_t3
tenk1
testdata


-- !query
Expand Down
24 changes: 0 additions & 24 deletions sql/core/src/test/resources/sql-tests/results/show-views.sql.out
Expand Up @@ -63,12 +63,6 @@ SHOW VIEWS
-- !query schema
struct<namespace:string,viewName:string,isTemporary:boolean>
-- !query output
aggtest
arraydata
mapdata
onek
tenk1
testdata
view_1
view_2
view_4
Expand All @@ -79,12 +73,6 @@ SHOW VIEWS FROM showdb
-- !query schema
struct<namespace:string,viewName:string,isTemporary:boolean>
-- !query output
aggtest
arraydata
mapdata
onek
tenk1
testdata
view_1
view_2
view_4
Expand All @@ -95,12 +83,6 @@ SHOW VIEWS IN showdb
-- !query schema
struct<namespace:string,viewName:string,isTemporary:boolean>
-- !query output
aggtest
arraydata
mapdata
onek
tenk1
testdata
view_1
view_2
view_4
Expand All @@ -111,12 +93,6 @@ SHOW VIEWS IN global_temp
-- !query schema
struct<namespace:string,viewName:string,isTemporary:boolean>
-- !query output
aggtest
arraydata
mapdata
onek
tenk1
testdata
view_3
view_4

Expand Down
Expand Up @@ -363,7 +363,6 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession {
// Create a local SparkSession to have stronger isolation between different test cases.
// This does not isolate catalog changes.
val localSparkSession = spark.newSession()
loadTestData(localSparkSession)

testCase match {
case udfTestCase: UDFTest =>
Expand Down Expand Up @@ -575,27 +574,36 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession {
private def loadTestData(session: SparkSession): Unit = {
import session.implicits._

(1 to 100).map(i => (i, i.toString)).toDF("key", "value").createOrReplaceTempView("testdata")
(1 to 100).map(i => (i, i.toString)).toDF("key", "value")
.write
.format("parquet")
.saveAsTable("testdata")

((Seq(1, 2, 3), Seq(Seq(1, 2, 3))) :: (Seq(2, 3, 4), Seq(Seq(2, 3, 4))) :: Nil)
.toDF("arraycol", "nestedarraycol")
.createOrReplaceTempView("arraydata")
.write
.format("parquet")
.saveAsTable("arraydata")

(Tuple1(Map(1 -> "a1", 2 -> "b1", 3 -> "c1", 4 -> "d1", 5 -> "e1")) ::
Tuple1(Map(1 -> "a2", 2 -> "b2", 3 -> "c2", 4 -> "d2")) ::
Tuple1(Map(1 -> "a3", 2 -> "b3", 3 -> "c3")) ::
Tuple1(Map(1 -> "a4", 2 -> "b4")) ::
Tuple1(Map(1 -> "a5")) :: Nil)
.toDF("mapcol")
.createOrReplaceTempView("mapdata")
.write
.format("parquet")
.saveAsTable("mapdata")

session
.read
.format("csv")
.options(Map("delimiter" -> "\t", "header" -> "false"))
.schema("a int, b float")
.load(testFile("test-data/postgresql/agg.data"))
.createOrReplaceTempView("aggtest")
.write
.format("parquet")
.saveAsTable("aggtest")

session
.read
Expand All @@ -621,7 +629,9 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession {
|string4 string
""".stripMargin)
.load(testFile("test-data/postgresql/onek.data"))
.createOrReplaceTempView("onek")
.write
.format("parquet")
.saveAsTable("onek")

session
.read
Expand All @@ -647,14 +657,26 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession {
|string4 string
""".stripMargin)
.load(testFile("test-data/postgresql/tenk.data"))
.createOrReplaceTempView("tenk1")
.write
.format("parquet")
.saveAsTable("tenk1")
}

private def unloadTestData(session: SparkSession): Unit = {
session.sql("DROP TABLE IF EXISTS testdata")
session.sql("DROP TABLE IF EXISTS arraydata")
session.sql("DROP TABLE IF EXISTS mapdata")
session.sql("DROP TABLE IF EXISTS aggtest")
session.sql("DROP TABLE IF EXISTS onek")
session.sql("DROP TABLE IF EXISTS tenk1")
}

private val originalTimeZone = TimeZone.getDefault
private val originalLocale = Locale.getDefault

override def beforeAll(): Unit = {
super.beforeAll()
loadTestData(spark)
// Timezone is fixed to America/Los_Angeles for those timezone sensitive tests (timestamp_*)
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"))
// Add Locale setting
Expand All @@ -668,6 +690,7 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession {
try {
TimeZone.setDefault(originalTimeZone)
Locale.setDefault(originalLocale)
unloadTestData(spark)

// For debugging dump some statistics about how much time was spent in various optimizer rules
logWarning(RuleExecutor.dumpTimeSpent())
Expand Down

0 comments on commit 45bba4c

Please sign in to comment.