From 95edce48231efec2e199f8363b02402ea3f039ac Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 11:43:32 +0300 Subject: [PATCH 01/22] Show tables in not existing namespace --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index b308934ba03c..73761a8b0962 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -63,6 +63,8 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { test("show tables") { checkAnswer(sql("SHOW TABLES IN h2.test"), Seq(Row("test", "people"))) + // Check not existing namespace + checkAnswer(sql("SHOW TABLES IN h2.bad_test"), Seq()) } test("drop a table and test whether the table exists") { From 419a377616b6444446fbb4cd688af356854a981a Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 11:47:17 +0300 Subject: [PATCH 02/22] Drop not existing table --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 73761a8b0962..4e017acca348 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -21,6 +21,7 @@ import java.util.Properties import org.apache.spark.SparkConf import org.apache.spark.sql.{QueryTest, Row} +import org.apache.spark.sql.catalyst.analysis.NoSuchTableException import org.apache.spark.sql.test.SharedSparkSession import org.apache.spark.sql.types._ import org.apache.spark.util.Utils @@ -74,6 +75,9 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { checkAnswer(sql("SHOW TABLES IN h2.test"), Seq(Row("test", "to_drop"), Row("test", "people"))) sql("DROP TABLE h2.test.to_drop") checkAnswer(sql("SHOW TABLES IN h2.test"), Seq(Row("test", "people"))) + intercept[NoSuchTableException] { + sql("DROP TABLE h2.test.not_existing_table") + } } test("rename a table") { From 8f7808c85d1fd0720d83670b0079f85121544e0d Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 11:51:39 +0300 Subject: [PATCH 03/22] Drop a table in not existing namespace --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 4e017acca348..7b8995f0fbb5 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -75,8 +75,10 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { checkAnswer(sql("SHOW TABLES IN h2.test"), Seq(Row("test", "to_drop"), Row("test", "people"))) sql("DROP TABLE h2.test.to_drop") checkAnswer(sql("SHOW TABLES IN h2.test"), Seq(Row("test", "people"))) - intercept[NoSuchTableException] { - sql("DROP TABLE h2.test.not_existing_table") + Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => + intercept[NoSuchTableException] { + sql(s"DROP TABLE $table") + } } } From 66f6311d895788185a5e3cbd9c7cef68610fe225 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:02:18 +0300 Subject: [PATCH 04/22] Load not existing namespace and table --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 7b8995f0fbb5..4971990f2cc6 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -20,7 +20,7 @@ import java.sql.{Connection, DriverManager} import java.util.Properties import org.apache.spark.SparkConf -import org.apache.spark.sql.{QueryTest, Row} +import org.apache.spark.sql.{AnalysisException, QueryTest, Row} import org.apache.spark.sql.catalyst.analysis.NoSuchTableException import org.apache.spark.sql.test.SharedSparkSession import org.apache.spark.sql.types._ @@ -103,6 +103,11 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { .add("NAME", StringType) .add("ID", IntegerType) assert(t.schema === expectedSchema) + Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => + intercept[AnalysisException] { + spark.table(s"h2.$table").schema + } + } } test("create a table") { From 0692121a824da0f1571f67c44b2aa270379e99bb Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:07:03 +0300 Subject: [PATCH 05/22] Rename not existing table or namespace --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 4971990f2cc6..0d3c6a184aed 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -95,6 +95,12 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { sql("SHOW TABLES IN h2.test"), Seq(Row("test", "dst_table"), Row("test", "people"))) } + // Rename not existing table or namespace + Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => + intercept[org.h2.jdbc.JdbcSQLException] { + sql(s"ALTER TABLE $table RENAME TO test.dst_table") + } + } } test("load a table") { From 29563a62dc49ee6706b33edf7c3c2174b150fb6a Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:12:24 +0300 Subject: [PATCH 06/22] Rename to an existing table --- .../v2/jdbc/JDBCTableCatalogSuite.scala | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 0d3c6a184aed..41aa76c304b2 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -101,6 +101,20 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { sql(s"ALTER TABLE $table RENAME TO test.dst_table") } } + // Rename to an existing table + withTable("h2.test.dst_table") { + withConnection { conn => + conn.prepareStatement("""CREATE TABLE "test"."dst_table" (id INTEGER)""").executeUpdate() + } + withTable("h2.test.src_table") { + withConnection { conn => + conn.prepareStatement("""CREATE TABLE "test"."src_table" (id INTEGER)""").executeUpdate() + } + intercept[org.h2.jdbc.JdbcSQLException] { + sql(s"ALTER TABLE h2.test.src_table RENAME TO h2.test.dst_table") + } + } + } } test("load a table") { From d82cb0542b4d663e4e42d7cd64bc47e10da82dcc Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:14:24 +0300 Subject: [PATCH 07/22] Create already existing table --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 41aa76c304b2..5e0ec2a5af0c 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -138,6 +138,12 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { sql("SHOW TABLES IN h2.test"), Seq(Row("test", "people"), Row("test", "new_table"))) } + withTable("h2.test.new_table") { + sql("CREATE TABLE h2.test.new_table(i INT, j STRING) USING _") + intercept[AnalysisException] { + sql("CREATE TABLE h2.test.new_table(i INT, j STRING) USING _") + } + } } test("alter table ... add column") { From dd7c4ba71bbf7b7bf34c0d8cb1c1a6e275aa6814 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:16:41 +0300 Subject: [PATCH 08/22] Create a table in not existing namespace --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 5e0ec2a5af0c..c9220481c44e 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -144,6 +144,9 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { sql("CREATE TABLE h2.test.new_table(i INT, j STRING) USING _") } } + intercept[org.h2.jdbc.JdbcSQLException] { + sql("CREATE TABLE h2.bad_test.new_table(i INT, j STRING) USING _") + } } test("alter table ... add column") { From d094e2c0d3fa195da8e13051c97e3f7505521afd Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:19:45 +0300 Subject: [PATCH 09/22] Add a column to not existing table and namespace --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index c9220481c44e..2daae450c306 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -164,6 +164,12 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { expectedSchema = expectedSchema.add("C3", DoubleType) assert(t.schema === expectedSchema) } + // Add a column to not existing table and namespace + Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => + intercept[AnalysisException] { + sql(s"ALTER TABLE $table ADD COLUMNS (C4 STRING)") + } + } } test("alter table ... rename column") { From fc45c5dd1c07dd5fd2747ec4493566cd51472eea Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:21:24 +0300 Subject: [PATCH 10/22] Add already existing column --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 2daae450c306..e4533244f1ca 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -163,6 +163,10 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { t = spark.table("h2.test.alt_table") expectedSchema = expectedSchema.add("C3", DoubleType) assert(t.schema === expectedSchema) + // Add already existing column + intercept[AnalysisException] { + sql(s"ALTER TABLE h2.test.alt_table ADD COLUMNS (C3 DOUBLE)") + } } // Add a column to not existing table and namespace Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => From 20d8c4593132e3d580402dff60b0c51797d1bd69 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:23:38 +0300 Subject: [PATCH 11/22] Rename a column in not existing table and namespace --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index e4533244f1ca..6b4e946fe113 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -184,6 +184,12 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { val expectedSchema = new StructType().add("C", IntegerType) assert(t.schema === expectedSchema) } + // Rename a column in not existing table and namespace + Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => + intercept[AnalysisException] { + sql(s"ALTER TABLE $table RENAME COLUMN ID TO C") + } + } } test("alter table ... drop column") { From 555c4809f39b12d2fcb529257d98137a22d1d55c Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:26:16 +0300 Subject: [PATCH 12/22] Rename to already existing column --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 6b4e946fe113..bfd5abe724a0 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -178,11 +178,17 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { test("alter table ... rename column") { withTable("h2.test.alt_table") { - sql("CREATE TABLE h2.test.alt_table (ID INTEGER) USING _") + sql("CREATE TABLE h2.test.alt_table (ID INTEGER, C0 INTEGER) USING _") sql("ALTER TABLE h2.test.alt_table RENAME COLUMN ID TO C") val t = spark.table("h2.test.alt_table") - val expectedSchema = new StructType().add("C", IntegerType) + val expectedSchema = new StructType() + .add("C", IntegerType) + .add("C0", IntegerType) assert(t.schema === expectedSchema) + // Rename to already existing column + intercept[AnalysisException] { + sql("ALTER TABLE h2.test.alt_table RENAME COLUMN C TO C0") + } } // Rename a column in not existing table and namespace Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => From db24d4918b776375f7756934471c777bf6095739 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:28:11 +0300 Subject: [PATCH 13/22] Drop not existing column --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index bfd5abe724a0..d0648324996c 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -205,6 +205,10 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { val t = spark.table("h2.test.alt_table") val expectedSchema = new StructType().add("C2", IntegerType) assert(t.schema === expectedSchema) + // Drop not existing column + intercept[AnalysisException] { + sql("ALTER TABLE h2.test.alt_table DROP COLUMN bad_column") + } } } From c75503cacae91428f19910780b2940c6c3cf6514 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:29:29 +0300 Subject: [PATCH 14/22] Drop a column to not existing table and namespace --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index d0648324996c..03c45b5b2642 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -210,6 +210,12 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { sql("ALTER TABLE h2.test.alt_table DROP COLUMN bad_column") } } + // Drop a column to not existing table and namespace + Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => + intercept[AnalysisException] { + sql(s"ALTER TABLE $table DROP COLUMN C1") + } + } } test("alter table ... update column type") { From 7a32df6fa28eda99aae2af71dcc591531662cabe Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:30:55 +0300 Subject: [PATCH 15/22] Update column type in not existing table and namespace --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 03c45b5b2642..6dc894723cf1 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -226,6 +226,12 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { val expectedSchema = new StructType().add("ID", DoubleType) assert(t.schema === expectedSchema) } + // Update column type in not existing table and namespace + Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => + intercept[AnalysisException] { + sql(s"ALTER TABLE $table ALTER COLUMN id TYPE DOUBLE") + } + } } test("alter table ... update column nullability") { From ece677788fd76adc0b98bf35eb25331fd5c002d6 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:32:17 +0300 Subject: [PATCH 16/22] Update not existing column --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 6dc894723cf1..07832133c8c1 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -225,6 +225,10 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { val t = spark.table("h2.test.alt_table") val expectedSchema = new StructType().add("ID", DoubleType) assert(t.schema === expectedSchema) + // Update not existing column + intercept[AnalysisException] { + sql("ALTER TABLE h2.test.alt_table ALTER COLUMN bad_column TYPE DOUBLE") + } } // Update column type in not existing table and namespace Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => From e7bd2f7ec9b32a956453bd5612d2b8cb4391fed1 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:33:30 +0300 Subject: [PATCH 17/22] Update column to wrong type --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 07832133c8c1..3e20d80b59d5 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -229,6 +229,10 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { intercept[AnalysisException] { sql("ALTER TABLE h2.test.alt_table ALTER COLUMN bad_column TYPE DOUBLE") } + // Update column to wrong type + intercept[AnalysisException] { + sql("ALTER TABLE h2.test.alt_table ALTER COLUMN id TYPE bad_type") + } } // Update column type in not existing table and namespace Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => From de73568c34f3689c96e682950a2b49bec82f32f0 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:34:54 +0300 Subject: [PATCH 18/22] Update column nullability in not existing table and namespace --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 3e20d80b59d5..63c24448759c 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -250,6 +250,12 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { val expectedSchema = new StructType().add("ID", IntegerType, nullable = true) assert(t.schema === expectedSchema) } + // Update column nullability in not existing table and namespace + Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => + intercept[AnalysisException] { + sql(s"ALTER TABLE $table ALTER COLUMN ID DROP NOT NULL") + } + } } test("alter table ... update column comment not supported") { From 930fe59e874d65e1118d903ff8fd5a40a439c390 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:36:18 +0300 Subject: [PATCH 19/22] Update nullability of not existing column --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 63c24448759c..258a519e3ec3 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -249,6 +249,10 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { val t = spark.table("h2.test.alt_table") val expectedSchema = new StructType().add("ID", IntegerType, nullable = true) assert(t.schema === expectedSchema) + // Update nullability of not existing column + intercept[AnalysisException] { + sql("ALTER TABLE h2.test.alt_table ALTER COLUMN bad_column DROP NOT NULL") + } } // Update column nullability in not existing table and namespace Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => From 7a7f34968299cafb98618423da7be017381b236a Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:38:00 +0300 Subject: [PATCH 20/22] Update column comments in not existing table and namespace --- .../datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 258a519e3ec3..8c78b4bbfa16 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -270,5 +270,11 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { } assert(thrown.getMessage.contains("Unsupported TableChange")) } + // Update column comments in not existing table and namespace + Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => + intercept[AnalysisException] { + sql(s"ALTER TABLE $table ALTER COLUMN ID COMMENT 'test'") + } + } } } From 77095516d7b17c1bd28895822beeeda9f45ad297 Mon Sep 17 00:00:00 2001 From: Max Gekk Date: Mon, 5 Oct 2020 12:41:00 +0300 Subject: [PATCH 21/22] Update comment for not existing column --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 8c78b4bbfa16..337b726c53df 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -269,6 +269,10 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { sql("ALTER TABLE h2.test.alt_table ALTER COLUMN ID COMMENT 'test'") } assert(thrown.getMessage.contains("Unsupported TableChange")) + // Update comment for not existing column + intercept[AnalysisException] { + sql("ALTER TABLE h2.test.alt_table ALTER COLUMN bad_column COMMENT 'test'") + } } // Update column comments in not existing table and namespace Seq("h2.test.not_existing_table", "h2.bad_test.not_existing_table").foreach { table => From e5aa53ff06995d6b17a6ef50a82afb95d992e790 Mon Sep 17 00:00:00 2001 From: Hyukjin Kwon Date: Tue, 6 Oct 2020 13:01:08 +0900 Subject: [PATCH 22/22] Apply suggestions from code review --- .../execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala index 337b726c53df..bf71f90779b7 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala @@ -111,7 +111,7 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { conn.prepareStatement("""CREATE TABLE "test"."src_table" (id INTEGER)""").executeUpdate() } intercept[org.h2.jdbc.JdbcSQLException] { - sql(s"ALTER TABLE h2.test.src_table RENAME TO h2.test.dst_table") + sql("ALTER TABLE h2.test.src_table RENAME TO h2.test.dst_table") } } } @@ -165,7 +165,7 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession { assert(t.schema === expectedSchema) // Add already existing column intercept[AnalysisException] { - sql(s"ALTER TABLE h2.test.alt_table ADD COLUMNS (C3 DOUBLE)") + sql("ALTER TABLE h2.test.alt_table ADD COLUMNS (C3 DOUBLE)") } } // Add a column to not existing table and namespace