From 0afe3cb5655cbd45e2e7cfd78eb41cfc73a64d58 Mon Sep 17 00:00:00 2001 From: Xin Wu Date: Thu, 9 Feb 2017 16:24:31 -0800 Subject: [PATCH 1/6] don't allow create temporary table to replace existing temp view --- .../spark/sql/execution/SparkSqlParser.scala | 4 ++- .../sql/execution/command/DDLSuite.scala | 10 +++++++ .../org/apache/spark/sql/jdbc/JDBCSuite.scala | 26 +++++++++---------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala index 41768d451261..78449b4e6c21 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala @@ -425,7 +425,9 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder { logWarning(s"CREATE TEMPORARY TABLE ... USING ... is deprecated, please use " + "CREATE TEMPORARY VIEW ... USING ... instead") - CreateTempViewUsing(table, schema, replace = true, global = false, provider, options) + // Since we don't support IF NOT EXISTS for temp table, we should not allow + // replacing existing temp table, that may accidentally remove a temp view in use. + CreateTempViewUsing(table, schema, replace = false, global = false, provider, options) } else { CreateTable(tableDesc, mode, None) } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index bcb707c8fdfc..bfda47322c74 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -1690,6 +1690,16 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { } } + test("block creating duplicate temp table") { + withView("t_temp") { + sql("CREATE TEMPORARY TABLE t_temp (c1, c2) as select 1, 2") + val e = intercept[TempTableAlreadyExistsException] { + sql("CREATE TEMPORARY TABLE t_temp (c1, c2) as select 2, 3") + }.getMessage + assert(e.contains("already exists")) + } + } + test("truncate table - external table, temporary table, view (not allowed)") { import testImplicits._ withTempPath { tempDir => diff --git a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala index 14fbe9f44313..0b341380f935 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala @@ -75,14 +75,14 @@ class JDBCSuite extends SparkFunSuite sql( s""" - |CREATE TEMPORARY TABLE foobar + |CREATE OR REPLACE TEMPORARY VIEW foobar |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.PEOPLE', user 'testUser', password 'testPass') """.stripMargin.replaceAll("\n", " ")) sql( s""" - |CREATE TEMPORARY TABLE fetchtwo + |CREATE OR REPLACE TEMPORARY VIEW fetchtwo |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.PEOPLE', user 'testUser', password 'testPass', | ${JDBCOptions.JDBC_BATCH_FETCH_SIZE} '2') @@ -90,7 +90,7 @@ class JDBCSuite extends SparkFunSuite sql( s""" - |CREATE TEMPORARY TABLE parts + |CREATE OR REPLACE TEMPORARY VIEW parts |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.PEOPLE', user 'testUser', password 'testPass', | partitionColumn 'THEID', lowerBound '1', upperBound '4', numPartitions '3') @@ -105,7 +105,7 @@ class JDBCSuite extends SparkFunSuite conn.commit() sql( s""" - |CREATE TEMPORARY TABLE inttypes + |CREATE OR REPLACE TEMPORARY VIEW inttypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.INTTYPES', user 'testUser', password 'testPass') """.stripMargin.replaceAll("\n", " ")) @@ -122,7 +122,7 @@ class JDBCSuite extends SparkFunSuite stmt.executeUpdate() sql( s""" - |CREATE TEMPORARY TABLE strtypes + |CREATE OR REPLACE TEMPORARY VIEW strtypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.STRTYPES', user 'testUser', password 'testPass') """.stripMargin.replaceAll("\n", " ")) @@ -136,7 +136,7 @@ class JDBCSuite extends SparkFunSuite conn.commit() sql( s""" - |CREATE TEMPORARY TABLE timetypes + |CREATE OR REPLACE TEMPORARY VIEW timetypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.TIMETYPES', user 'testUser', password 'testPass') """.stripMargin.replaceAll("\n", " ")) @@ -151,7 +151,7 @@ class JDBCSuite extends SparkFunSuite conn.commit() sql( s""" - |CREATE TEMPORARY TABLE flttypes + |CREATE OR REPLACE TEMPORARY VIEW flttypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.FLTTYPES', user 'testUser', password 'testPass') """.stripMargin.replaceAll("\n", " ")) @@ -168,7 +168,7 @@ class JDBCSuite extends SparkFunSuite conn.commit() sql( s""" - |CREATE TEMPORARY TABLE nulltypes + |CREATE OR REPLACE TEMPORARY VIEW nulltypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.NULLTYPES', user 'testUser', password 'testPass') """.stripMargin.replaceAll("\n", " ")) @@ -198,7 +198,7 @@ class JDBCSuite extends SparkFunSuite sql( s""" - |CREATE TEMPORARY TABLE nullparts + |CREATE OR REPLACE TEMPORARY VIEW nullparts |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.EMP', user 'testUser', password 'testPass', |partitionColumn '"Dept"', lowerBound '1', upperBound '4', numPartitions '3') @@ -214,7 +214,7 @@ class JDBCSuite extends SparkFunSuite sql( s""" - |CREATE TEMPORARY TABLE mixedCaseCols + |CREATE OR REPLACE TEMPORARY VIEW mixedCaseCols |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST."mixedCaseCols"', user 'testUser', password 'testPass') """.stripMargin.replaceAll("\n", " ")) @@ -371,7 +371,7 @@ class JDBCSuite extends SparkFunSuite // Regression test for bug SPARK-7345 sql( s""" - |CREATE TEMPORARY TABLE renamed + |CREATE OR REPLACE TEMPORARY VIEW renamed |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable '(select NAME as NAME1, NAME as NAME2 from TEST.PEOPLE)', |user 'testUser', password 'testPass') @@ -589,7 +589,7 @@ class JDBCSuite extends SparkFunSuite test("SQL query as table name") { sql( s""" - |CREATE TEMPORARY TABLE hack + |CREATE OR REPLACE TEMPORARY VIEW hack |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable '(SELECT B, B*B FROM TEST.FLTTYPES)', | user 'testUser', password 'testPass') @@ -606,7 +606,7 @@ class JDBCSuite extends SparkFunSuite intercept[JdbcSQLException] { sql( s""" - |CREATE TEMPORARY TABLE abc + |CREATE OR REPLACE TEMPORARY VIEW abc |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable '(SELECT _ROWID_ FROM test.people)', | user 'testUser', password 'testPass') From 290fa15b4983071a4c6235213ee17d336e303c83 Mon Sep 17 00:00:00 2001 From: Xin Wu Date: Thu, 9 Feb 2017 16:54:11 -0800 Subject: [PATCH 2/6] update testcases --- .../execution/datasources/csv/CSVSuite.scala | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala index 491ff72337a8..2a4ac1fbe432 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala @@ -187,15 +187,18 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { test("test different encoding") { // scalastyle:off - spark.sql( - s""" + withView("carsTable") { + spark.sql( + s""" |CREATE TEMPORARY TABLE carsTable USING csv |OPTIONS (path "${testFile(carsFile8859)}", header "true", |charset "iso-8859-1", delimiter "þ") - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin. + replaceAll("\n", " ")) // scalastyle:on - verifyCars(spark.table("carsTable"), withHeader = true) + verifyCars(spark.table("carsTable"), withHeader = true) + } } test("test aliases sep and encoding for delimiter and charset") { @@ -213,18 +216,23 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { } test("DDL test with tab separated file") { - spark.sql( - s""" + withView("carsTable") { + spark.sql( + s""" |CREATE TEMPORARY TABLE carsTable USING csv |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " " - verifyCars(spark.table("carsTable"), numFields = 6, withHeader = true, checkHeader = false) + )) + + verifyCars(spark.table("carsTable"), numFields = 6, withHeader = true, checkHeader = false) + } } test("DDL test parsing decimal type") { - spark.sql( - s""" + withView("carsTable") { + spark.sql( + s""" |CREATE TEMPORARY TABLE carsTable |(yearMade double, makeName string, modelName string, priceTag decimal, | comments string, grp string) @@ -232,8 +240,9 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") """.stripMargin.replaceAll("\n", " ")) - assert( - spark.sql("SELECT makeName FROM carsTable where priceTag > 60000").collect().size === 1) + assert( + spark.sql("SELECT makeName FROM carsTable where priceTag > 60000").collect().size === 1) + } } test("test for DROPMALFORMED parsing mode") { @@ -300,28 +309,34 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { } test("DDL test with empty file") { - spark.sql(s""" + withView("carsTable") { + spark.sql( + s""" |CREATE TEMPORARY TABLE carsTable |(yearMade double, makeName string, modelName string, comments string, grp string) |USING csv |OPTIONS (path "${testFile(emptyFile)}", header "false") """.stripMargin.replaceAll("\n", " ")) - assert(spark.sql("SELECT count(*) FROM carsTable").collect().head(0) === 0) + assert(spark.sql("SELECT count(*) FROM carsTable").collect().head(0) === 0) + } } test("DDL test with schema") { - spark.sql(s""" + withView("carsTable") { + spark.sql( + s""" |CREATE TEMPORARY TABLE carsTable |(yearMade double, makeName string, modelName string, comments string, blank string) |USING csv |OPTIONS (path "${testFile(carsFile)}", header "true") """.stripMargin.replaceAll("\n", " ")) - val cars = spark.table("carsTable") - verifyCars(cars, withHeader = true, checkHeader = false, checkValues = false) - assert( - cars.schema.fieldNames === Array("yearMade", "makeName", "modelName", "comments", "blank")) + val cars = spark.table("carsTable") + verifyCars(cars, withHeader = true, checkHeader = false, checkValues = false) + assert( + cars.schema.fieldNames === Array("yearMade", "makeName", "modelName", "comments", "blank")) + } } test("save csv") { From 4a3a06abeec8e2e78cbb4c46515d77d64e5507de Mon Sep 17 00:00:00 2001 From: Xin Wu Date: Thu, 9 Feb 2017 17:19:03 -0800 Subject: [PATCH 3/6] update testcases --- .../org/apache/spark/sql/execution/command/DDLSuite.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index bfda47322c74..09e714fdfecc 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -1692,9 +1692,9 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { test("block creating duplicate temp table") { withView("t_temp") { - sql("CREATE TEMPORARY TABLE t_temp (c1, c2) as select 1, 2") + sql("CREATE TEMPORARY VIEW t_temp AS SELECT 1, 2") val e = intercept[TempTableAlreadyExistsException] { - sql("CREATE TEMPORARY TABLE t_temp (c1, c2) as select 2, 3") + sql("CREATE TEMPORARY TABLE t_temp (c3 int, c4 string) USING JSON") }.getMessage assert(e.contains("already exists")) } From f7253c578d0a7c712bd1e42d46362ab377d93923 Mon Sep 17 00:00:00 2001 From: Xin Wu Date: Sun, 12 Feb 2017 21:13:40 -0800 Subject: [PATCH 4/6] update testcases --- .../spark/sql/execution/SparkSqlParser.scala | 4 ++-- .../org/apache/spark/sql/SQLQuerySuite.scala | 6 +++--- .../spark/sql/execution/command/DDLSuite.scala | 12 ++++++------ .../RowDataSourceStrategySuite.scala | 2 +- .../execution/datasources/csv/CSVSuite.scala | 17 +++++++---------- .../apache/spark/sql/sources/DDLTestSuite.scala | 2 +- .../apache/spark/sql/sources/InsertSuite.scala | 4 ++-- .../sql/hive/execution/HiveCommandSuite.scala | 4 ++-- .../sql/hive/execution/SQLQuerySuite.scala | 6 +++--- 9 files changed, 27 insertions(+), 30 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala index 78449b4e6c21..199105e1f3e5 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala @@ -425,8 +425,8 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder { logWarning(s"CREATE TEMPORARY TABLE ... USING ... is deprecated, please use " + "CREATE TEMPORARY VIEW ... USING ... instead") - // Since we don't support IF NOT EXISTS for temp table, we should not allow - // replacing existing temp table, that may accidentally remove a temp view in use. + // Unlike CREATE TEMPORARY VIEW USING, CREATE TEMPORARY TABLE USING does not support + // IF NOT EXISTS. Users are not allowed to replace the existing temp table. CreateTempViewUsing(table, schema, replace = false, global = false, provider, options) } else { CreateTable(tableDesc, mode, None) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala index 9c95b1279519..b41f9d18a47c 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala @@ -1571,7 +1571,7 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { } } - test("specifying database name for a temporary table is not allowed") { + test("specifying database name for a temporary view is not allowed") { withTempPath { dir => val path = dir.toURI.toString val df = @@ -1585,7 +1585,7 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { intercept[AnalysisException] { spark.sql( s""" - |CREATE TEMPORARY TABLE db.t + |CREATE TEMPORARY VIEW db.t |USING parquet |OPTIONS ( | path '$path' @@ -1596,7 +1596,7 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { // If you use backticks to quote the name then it's OK. spark.sql( s""" - |CREATE TEMPORARY TABLE `db.t` + |CREATE TEMPORARY VIEW `db.t` |USING parquet |OPTIONS ( | path '$path' diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index 09e714fdfecc..8c64052a4556 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -903,7 +903,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { withTempView("show1a", "show2b") { sql( """ - |CREATE TEMPORARY TABLE show1a + |CREATE TEMPORARY VIEW show1a |USING org.apache.spark.sql.sources.DDLScanSource |OPTIONS ( | From '1', @@ -914,7 +914,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { """.stripMargin) sql( """ - |CREATE TEMPORARY TABLE show2b + |CREATE TEMPORARY VIEW show2b |USING org.apache.spark.sql.sources.DDLScanSource |OPTIONS ( | From '1', @@ -958,11 +958,11 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { Nil) } - test("drop table - temporary table") { + test("drop view - temporary view") { val catalog = spark.sessionState.catalog sql( """ - |CREATE TEMPORARY TABLE tab1 + |CREATE TEMPORARY VIEW tab1 |USING org.apache.spark.sql.sources.DDLScanSource |OPTIONS ( | From '1', @@ -971,7 +971,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { |) """.stripMargin) assert(catalog.listTables("default") == Seq(TableIdentifier("tab1"))) - sql("DROP TABLE tab1") + sql("DROP view tab1") assert(catalog.listTables("default") == Nil) } @@ -1696,7 +1696,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { val e = intercept[TempTableAlreadyExistsException] { sql("CREATE TEMPORARY TABLE t_temp (c3 int, c4 string) USING JSON") }.getMessage - assert(e.contains("already exists")) + assert(e.contains("Temporary table 't_temp' already exists")) } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/RowDataSourceStrategySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/RowDataSourceStrategySuite.scala index d9afa4635318..edcfc5aed341 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/RowDataSourceStrategySuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/RowDataSourceStrategySuite.scala @@ -52,7 +52,7 @@ class RowDataSourceStrategySuite extends SparkFunSuite with BeforeAndAfter with conn.commit() sql( s""" - |CREATE TEMPORARY TABLE inttypes + |CREATE OR REPLACE TEMPORARY VIEW inttypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.INTTYPES', user 'testUser', password 'testPass') """.stripMargin.replaceAll("\n", " ")) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala index 2a4ac1fbe432..c107f082a9b0 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala @@ -190,11 +190,10 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY TABLE carsTable USING csv + |CREATE TEMPORARY VIEW carsTable USING csv |OPTIONS (path "${testFile(carsFile8859)}", header "true", |charset "iso-8859-1", delimiter "þ") - """.stripMargin. - replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) // scalastyle:on verifyCars(spark.table("carsTable"), withHeader = true) @@ -219,11 +218,9 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY TABLE carsTable USING csv + |CREATE TEMPORARY VIEW carsTable USING csv |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") - """.stripMargin.replaceAll("\n", " " - - )) + """.stripMargin.replaceAll("\n", " ")) verifyCars(spark.table("carsTable"), numFields = 6, withHeader = true, checkHeader = false) } @@ -233,7 +230,7 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY TABLE carsTable + |CREATE TEMPORARY VIEW carsTable |(yearMade double, makeName string, modelName string, priceTag decimal, | comments string, grp string) |USING csv @@ -312,7 +309,7 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY TABLE carsTable + |CREATE TEMPORARY VIEW carsTable |(yearMade double, makeName string, modelName string, comments string, grp string) |USING csv |OPTIONS (path "${testFile(emptyFile)}", header "false") @@ -326,7 +323,7 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY TABLE carsTable + |CREATE TEMPORARY VIEW carsTable |(yearMade double, makeName string, modelName string, comments string, blank string) |USING csv |OPTIONS (path "${testFile(carsFile)}", header "true") diff --git a/sql/core/src/test/scala/org/apache/spark/sql/sources/DDLTestSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/sources/DDLTestSuite.scala index e535d4dc880a..dacf4747e108 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/sources/DDLTestSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/sources/DDLTestSuite.scala @@ -83,7 +83,7 @@ class DDLTestSuite extends DataSourceTest with SharedSQLContext { super.beforeAll() sql( """ - |CREATE TEMPORARY TABLE ddlPeople + |CREATE OR REPLACE TEMPORARY VIEW ddlPeople |USING org.apache.spark.sql.sources.DDLScanSource |OPTIONS ( | From '1', diff --git a/sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala index 5b215ca07f0d..4fc2f81f540b 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala @@ -34,7 +34,7 @@ class InsertSuite extends DataSourceTest with SharedSQLContext { spark.read.json(rdd).createOrReplaceTempView("jt") sql( s""" - |CREATE TEMPORARY TABLE jsonTable (a int, b string) + |CREATE TEMPORARY VIEW jsonTable (a int, b string) |USING org.apache.spark.sql.json.DefaultSource |OPTIONS ( | path '${path.toURI.toString}' @@ -293,7 +293,7 @@ class InsertSuite extends DataSourceTest with SharedSQLContext { test("it's not allowed to insert into a relation that is not an InsertableRelation") { sql( """ - |CREATE TEMPORARY TABLE oneToTen + |CREATE TEMPORARY VIEW oneToTen |USING org.apache.spark.sql.sources.SimpleScanSource |OPTIONS ( | From '1', diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala index 8fda1c5875cc..374896fd1596 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala @@ -148,7 +148,7 @@ class HiveCommandSuite extends QueryTest with SQLTestUtils with TestHiveSingleto withTempView("parquet_temp") { sql( """ - |CREATE TEMPORARY TABLE parquet_temp (c1 INT, c2 STRING) + |CREATE TEMPORARY VIEW parquet_temp (c1 INT, c2 STRING) |USING org.apache.spark.sql.parquet.DefaultSource """.stripMargin) @@ -401,7 +401,7 @@ class HiveCommandSuite extends QueryTest with SQLTestUtils with TestHiveSingleto withTempView("parquet_temp") { sql( """ - |CREATE TEMPORARY TABLE parquet_temp (c1 INT, c2 STRING) + |CREATE TEMPORARY VIEW parquet_temp (c1 INT, c2 STRING) |USING org.apache.spark.sql.parquet.DefaultSource """.stripMargin) // An empty sequence of row is returned for session temporary table. diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala index 20f30e48aba4..ab097d5c7f9e 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala @@ -1290,7 +1290,7 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { "interval 4 minutes 59 seconds 889 milliseconds 987 microseconds"))) } - test("specifying database name for a temporary table is not allowed") { + test("specifying database name for a temporary view is not allowed") { withTempPath { dir => val path = dir.toURI.toString val df = sparkContext.parallelize(1 to 10).map(i => (i, i.toString)).toDF("num", "str") @@ -1303,7 +1303,7 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { intercept[AnalysisException] { spark.sql( s""" - |CREATE TEMPORARY TABLE db.t + |CREATE TEMPORARY VIEW db.t |USING parquet |OPTIONS ( | path '$path' @@ -1314,7 +1314,7 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { // If you use backticks to quote the name then it's OK. spark.sql( s""" - |CREATE TEMPORARY TABLE `db.t` + |CREATE TEMPORARY VIEW `db.t` |USING parquet |OPTIONS ( | path '$path' From 6683d8c903f6a6d56af21049151688cf581b75ab Mon Sep 17 00:00:00 2001 From: Xin Wu Date: Mon, 13 Feb 2017 14:09:06 -0800 Subject: [PATCH 5/6] update upon review --- .../sql/execution/command/DDLSuite.scala | 2 +- .../execution/datasources/csv/CSVSuite.scala | 43 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index 8c64052a4556..833db471255e 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -971,7 +971,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { |) """.stripMargin) assert(catalog.listTables("default") == Seq(TableIdentifier("tab1"))) - sql("DROP view tab1") + sql("DROP VIEW tab1") assert(catalog.listTables("default") == Nil) } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala index c107f082a9b0..504afab3bcc2 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala @@ -186,16 +186,15 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { } test("test different encoding") { - // scalastyle:off withView("carsTable") { + // scalastyle:off spark.sql( s""" - |CREATE TEMPORARY VIEW carsTable USING csv - |OPTIONS (path "${testFile(carsFile8859)}", header "true", - |charset "iso-8859-1", delimiter "þ") - """.stripMargin.replaceAll("\n", " ")) - // scalastyle:on - + |CREATE TEMPORARY VIEW carsTable USING csv + |OPTIONS (path "${testFile(carsFile8859)}", header "true", + |charset "iso-8859-1", delimiter "þ") + """.stripMargin.replaceAll("\n", " ")) + // scalastyle:on verifyCars(spark.table("carsTable"), withHeader = true) } } @@ -218,9 +217,9 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY VIEW carsTable USING csv - |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") - """.stripMargin.replaceAll("\n", " ")) + |CREATE TEMPORARY VIEW carsTable USING csv + |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") + """.stripMargin.replaceAll("\n", " ")) verifyCars(spark.table("carsTable"), numFields = 6, withHeader = true, checkHeader = false) } @@ -230,12 +229,12 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY VIEW carsTable - |(yearMade double, makeName string, modelName string, priceTag decimal, - | comments string, grp string) - |USING csv - |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") - """.stripMargin.replaceAll("\n", " ")) + |CREATE TEMPORARY VIEW carsTable + |(yearMade double, makeName string, modelName string, priceTag decimal, + | comments string, grp string) + |USING csv + |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") + """.stripMargin.replaceAll("\n", " ")) assert( spark.sql("SELECT makeName FROM carsTable where priceTag > 60000").collect().size === 1) @@ -309,11 +308,11 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY VIEW carsTable - |(yearMade double, makeName string, modelName string, comments string, grp string) - |USING csv - |OPTIONS (path "${testFile(emptyFile)}", header "false") - """.stripMargin.replaceAll("\n", " ")) + |CREATE TEMPORARY VIEW carsTable + |(yearMade double, makeName string, modelName string, comments string, grp string) + |USING csv + |OPTIONS (path "${testFile(emptyFile)}", header "false") + """.stripMargin.replaceAll("\n", " ")) assert(spark.sql("SELECT count(*) FROM carsTable").collect().head(0) === 0) } @@ -327,7 +326,7 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { |(yearMade double, makeName string, modelName string, comments string, blank string) |USING csv |OPTIONS (path "${testFile(carsFile)}", header "true") - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) val cars = spark.table("carsTable") verifyCars(cars, withHeader = true, checkHeader = false, checkValues = false) From 3a989cf8f5b116656589fe3d972aba116e3cfcc5 Mon Sep 17 00:00:00 2001 From: Xin Wu Date: Mon, 13 Feb 2017 14:48:55 -0800 Subject: [PATCH 6/6] fix indention --- .../org/apache/spark/sql/SQLQuerySuite.scala | 14 +++--- .../sql/execution/command/DDLSuite.scala | 44 +++++++++---------- .../RowDataSourceStrategySuite.scala | 2 +- .../execution/datasources/csv/CSVSuite.scala | 44 +++++++++---------- .../org/apache/spark/sql/jdbc/JDBCSuite.scala | 42 +++++++++--------- .../spark/sql/sources/DDLTestSuite.scala | 14 +++--- .../sql/hive/execution/HiveCommandSuite.scala | 8 ++-- .../sql/hive/execution/SQLQuerySuite.scala | 14 +++--- 8 files changed, 91 insertions(+), 91 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala index b41f9d18a47c..40d0ce099217 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala @@ -1585,12 +1585,12 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { intercept[AnalysisException] { spark.sql( s""" - |CREATE TEMPORARY VIEW db.t - |USING parquet - |OPTIONS ( - | path '$path' - |) - """.stripMargin) + |CREATE TEMPORARY VIEW db.t + |USING parquet + |OPTIONS ( + | path '$path' + |) + """.stripMargin) }.getMessage // If you use backticks to quote the name then it's OK. @@ -1601,7 +1601,7 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { |OPTIONS ( | path '$path' |) - """.stripMargin) + """.stripMargin) checkAnswer(spark.table("`db.t`"), df) } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index 833db471255e..278d24725087 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -903,24 +903,24 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { withTempView("show1a", "show2b") { sql( """ - |CREATE TEMPORARY VIEW show1a - |USING org.apache.spark.sql.sources.DDLScanSource - |OPTIONS ( - | From '1', - | To '10', - | Table 'test1' - | - |) + |CREATE TEMPORARY VIEW show1a + |USING org.apache.spark.sql.sources.DDLScanSource + |OPTIONS ( + | From '1', + | To '10', + | Table 'test1' + | + |) """.stripMargin) sql( """ - |CREATE TEMPORARY VIEW show2b - |USING org.apache.spark.sql.sources.DDLScanSource - |OPTIONS ( - | From '1', - | To '10', - | Table 'test1' - |) + |CREATE TEMPORARY VIEW show2b + |USING org.apache.spark.sql.sources.DDLScanSource + |OPTIONS ( + | From '1', + | To '10', + | Table 'test1' + |) """.stripMargin) assert( sql("SHOW TABLE EXTENDED LIKE 'show*'").count() >= 2) @@ -962,13 +962,13 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { val catalog = spark.sessionState.catalog sql( """ - |CREATE TEMPORARY VIEW tab1 - |USING org.apache.spark.sql.sources.DDLScanSource - |OPTIONS ( - | From '1', - | To '10', - | Table 'test1' - |) + |CREATE TEMPORARY VIEW tab1 + |USING org.apache.spark.sql.sources.DDLScanSource + |OPTIONS ( + | From '1', + | To '10', + | Table 'test1' + |) """.stripMargin) assert(catalog.listTables("default") == Seq(TableIdentifier("tab1"))) sql("DROP VIEW tab1") diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/RowDataSourceStrategySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/RowDataSourceStrategySuite.scala index edcfc5aed341..e8bf21a2a9db 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/RowDataSourceStrategySuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/RowDataSourceStrategySuite.scala @@ -55,7 +55,7 @@ class RowDataSourceStrategySuite extends SparkFunSuite with BeforeAndAfter with |CREATE OR REPLACE TEMPORARY VIEW inttypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.INTTYPES', user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) } after { diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala index 504afab3bcc2..df9cebbe58d5 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala @@ -190,10 +190,10 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { // scalastyle:off spark.sql( s""" - |CREATE TEMPORARY VIEW carsTable USING csv - |OPTIONS (path "${testFile(carsFile8859)}", header "true", - |charset "iso-8859-1", delimiter "þ") - """.stripMargin.replaceAll("\n", " ")) + |CREATE TEMPORARY VIEW carsTable USING csv + |OPTIONS (path "${testFile(carsFile8859)}", header "true", + |charset "iso-8859-1", delimiter "þ") + """.stripMargin.replaceAll("\n", " ")) // scalastyle:on verifyCars(spark.table("carsTable"), withHeader = true) } @@ -217,9 +217,9 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY VIEW carsTable USING csv - |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") - """.stripMargin.replaceAll("\n", " ")) + |CREATE TEMPORARY VIEW carsTable USING csv + |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") + """.stripMargin.replaceAll("\n", " ")) verifyCars(spark.table("carsTable"), numFields = 6, withHeader = true, checkHeader = false) } @@ -229,12 +229,12 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY VIEW carsTable - |(yearMade double, makeName string, modelName string, priceTag decimal, - | comments string, grp string) - |USING csv - |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") - """.stripMargin.replaceAll("\n", " ")) + |CREATE TEMPORARY VIEW carsTable + |(yearMade double, makeName string, modelName string, priceTag decimal, + | comments string, grp string) + |USING csv + |OPTIONS (path "${testFile(carsTsvFile)}", header "true", delimiter "\t") + """.stripMargin.replaceAll("\n", " ")) assert( spark.sql("SELECT makeName FROM carsTable where priceTag > 60000").collect().size === 1) @@ -308,10 +308,10 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY VIEW carsTable - |(yearMade double, makeName string, modelName string, comments string, grp string) - |USING csv - |OPTIONS (path "${testFile(emptyFile)}", header "false") + |CREATE TEMPORARY VIEW carsTable + |(yearMade double, makeName string, modelName string, comments string, grp string) + |USING csv + |OPTIONS (path "${testFile(emptyFile)}", header "false") """.stripMargin.replaceAll("\n", " ")) assert(spark.sql("SELECT count(*) FROM carsTable").collect().head(0) === 0) @@ -322,11 +322,11 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils { withView("carsTable") { spark.sql( s""" - |CREATE TEMPORARY VIEW carsTable - |(yearMade double, makeName string, modelName string, comments string, blank string) - |USING csv - |OPTIONS (path "${testFile(carsFile)}", header "true") - """.stripMargin.replaceAll("\n", " ")) + |CREATE TEMPORARY VIEW carsTable + |(yearMade double, makeName string, modelName string, comments string, blank string) + |USING csv + |OPTIONS (path "${testFile(carsFile)}", header "true") + """.stripMargin.replaceAll("\n", " ")) val cars = spark.table("carsTable") verifyCars(cars, withHeader = true, checkHeader = false, checkValues = false) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala index 0b341380f935..1cca15542d11 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala @@ -78,7 +78,7 @@ class JDBCSuite extends SparkFunSuite |CREATE OR REPLACE TEMPORARY VIEW foobar |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.PEOPLE', user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) sql( s""" @@ -86,7 +86,7 @@ class JDBCSuite extends SparkFunSuite |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.PEOPLE', user 'testUser', password 'testPass', | ${JDBCOptions.JDBC_BATCH_FETCH_SIZE} '2') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) sql( s""" @@ -94,7 +94,7 @@ class JDBCSuite extends SparkFunSuite |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.PEOPLE', user 'testUser', password 'testPass', | partitionColumn 'THEID', lowerBound '1', upperBound '4', numPartitions '3') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) conn.prepareStatement("create table test.inttypes (a INT, b BOOLEAN, c TINYINT, " + "d SMALLINT, e BIGINT)").executeUpdate() @@ -108,7 +108,7 @@ class JDBCSuite extends SparkFunSuite |CREATE OR REPLACE TEMPORARY VIEW inttypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.INTTYPES', user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) conn.prepareStatement("create table test.strtypes (a BINARY(20), b VARCHAR(20), " + "c VARCHAR_IGNORECASE(20), d CHAR(20), e BLOB, f CLOB)").executeUpdate() @@ -125,7 +125,7 @@ class JDBCSuite extends SparkFunSuite |CREATE OR REPLACE TEMPORARY VIEW strtypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.STRTYPES', user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) conn.prepareStatement("create table test.timetypes (a TIME, b DATE, c TIMESTAMP)" ).executeUpdate() @@ -139,7 +139,7 @@ class JDBCSuite extends SparkFunSuite |CREATE OR REPLACE TEMPORARY VIEW timetypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.TIMETYPES', user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) conn.prepareStatement("create table test.flttypes (a DOUBLE, b REAL, c DECIMAL(38, 18))" @@ -154,14 +154,14 @@ class JDBCSuite extends SparkFunSuite |CREATE OR REPLACE TEMPORARY VIEW flttypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.FLTTYPES', user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) conn.prepareStatement( s""" |create table test.nulltypes (a INT, b BOOLEAN, c TINYINT, d BINARY(20), e VARCHAR(20), |f VARCHAR_IGNORECASE(20), g CHAR(20), h BLOB, i CLOB, j TIME, k DATE, l TIMESTAMP, |m DOUBLE, n REAL, o DECIMAL(38, 18)) - """.stripMargin.replaceAll("\n", " ")).executeUpdate() + """.stripMargin.replaceAll("\n", " ")).executeUpdate() conn.prepareStatement("insert into test.nulltypes values (" + "null, null, null, null, null, null, null, null, null, " + "null, null, null, null, null, null)").executeUpdate() @@ -171,7 +171,7 @@ class JDBCSuite extends SparkFunSuite |CREATE OR REPLACE TEMPORARY VIEW nulltypes |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable 'TEST.NULLTYPES', user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) conn.prepareStatement( "create table test.emp(name TEXT(32) NOT NULL," + @@ -198,11 +198,11 @@ class JDBCSuite extends SparkFunSuite sql( s""" - |CREATE OR REPLACE TEMPORARY VIEW nullparts - |USING org.apache.spark.sql.jdbc - |OPTIONS (url '$url', dbtable 'TEST.EMP', user 'testUser', password 'testPass', - |partitionColumn '"Dept"', lowerBound '1', upperBound '4', numPartitions '3') - """.stripMargin.replaceAll("\n", " ")) + |CREATE OR REPLACE TEMPORARY VIEW nullparts + |USING org.apache.spark.sql.jdbc + |OPTIONS (url '$url', dbtable 'TEST.EMP', user 'testUser', password 'testPass', + |partitionColumn '"Dept"', lowerBound '1', upperBound '4', numPartitions '3') + """.stripMargin.replaceAll("\n", " ")) conn.prepareStatement( """create table test."mixedCaseCols" ("Name" TEXT(32), "Id" INTEGER NOT NULL)""") @@ -214,10 +214,10 @@ class JDBCSuite extends SparkFunSuite sql( s""" - |CREATE OR REPLACE TEMPORARY VIEW mixedCaseCols - |USING org.apache.spark.sql.jdbc - |OPTIONS (url '$url', dbtable 'TEST."mixedCaseCols"', user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + |CREATE OR REPLACE TEMPORARY VIEW mixedCaseCols + |USING org.apache.spark.sql.jdbc + |OPTIONS (url '$url', dbtable 'TEST."mixedCaseCols"', user 'testUser', password 'testPass') + """.stripMargin.replaceAll("\n", " ")) // Untested: IDENTITY, OTHER, UUID, ARRAY, and GEOMETRY types. } @@ -375,7 +375,7 @@ class JDBCSuite extends SparkFunSuite |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable '(select NAME as NAME1, NAME as NAME2 from TEST.PEOPLE)', |user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) val df = sql("SELECT * FROM renamed") assert(df.schema.fields.size == 2) @@ -593,7 +593,7 @@ class JDBCSuite extends SparkFunSuite |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable '(SELECT B, B*B FROM TEST.FLTTYPES)', | user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) val rows = sql("SELECT * FROM hack").collect() assert(rows(0).getDouble(0) === 1.00000011920928955) // Yes, I meant ==. // For some reason, H2 computes this square incorrectly... @@ -610,7 +610,7 @@ class JDBCSuite extends SparkFunSuite |USING org.apache.spark.sql.jdbc |OPTIONS (url '$url', dbtable '(SELECT _ROWID_ FROM test.people)', | user 'testUser', password 'testPass') - """.stripMargin.replaceAll("\n", " ")) + """.stripMargin.replaceAll("\n", " ")) } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/sources/DDLTestSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/sources/DDLTestSuite.scala index dacf4747e108..674463feca4d 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/sources/DDLTestSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/sources/DDLTestSuite.scala @@ -83,13 +83,13 @@ class DDLTestSuite extends DataSourceTest with SharedSQLContext { super.beforeAll() sql( """ - |CREATE OR REPLACE TEMPORARY VIEW ddlPeople - |USING org.apache.spark.sql.sources.DDLScanSource - |OPTIONS ( - | From '1', - | To '10', - | Table 'test1' - |) + |CREATE OR REPLACE TEMPORARY VIEW ddlPeople + |USING org.apache.spark.sql.sources.DDLScanSource + |OPTIONS ( + | From '1', + | To '10', + | Table 'test1' + |) """.stripMargin) } diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala index 374896fd1596..6937e97a47dc 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveCommandSuite.scala @@ -148,8 +148,8 @@ class HiveCommandSuite extends QueryTest with SQLTestUtils with TestHiveSingleto withTempView("parquet_temp") { sql( """ - |CREATE TEMPORARY VIEW parquet_temp (c1 INT, c2 STRING) - |USING org.apache.spark.sql.parquet.DefaultSource + |CREATE TEMPORARY VIEW parquet_temp (c1 INT, c2 STRING) + |USING org.apache.spark.sql.parquet.DefaultSource """.stripMargin) // An empty sequence of row is returned for session temporary table. @@ -401,8 +401,8 @@ class HiveCommandSuite extends QueryTest with SQLTestUtils with TestHiveSingleto withTempView("parquet_temp") { sql( """ - |CREATE TEMPORARY VIEW parquet_temp (c1 INT, c2 STRING) - |USING org.apache.spark.sql.parquet.DefaultSource + |CREATE TEMPORARY VIEW parquet_temp (c1 INT, c2 STRING) + |USING org.apache.spark.sql.parquet.DefaultSource """.stripMargin) // An empty sequence of row is returned for session temporary table. intercept[NoSuchTableException] { diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala index ab097d5c7f9e..faed8b504649 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala @@ -1303,12 +1303,12 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { intercept[AnalysisException] { spark.sql( s""" - |CREATE TEMPORARY VIEW db.t - |USING parquet - |OPTIONS ( - | path '$path' - |) - """.stripMargin) + |CREATE TEMPORARY VIEW db.t + |USING parquet + |OPTIONS ( + | path '$path' + |) + """.stripMargin) } // If you use backticks to quote the name then it's OK. @@ -1319,7 +1319,7 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { |OPTIONS ( | path '$path' |) - """.stripMargin) + """.stripMargin) checkAnswer(spark.table("`db.t`"), df) } }