You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/10/15 23:11:27 UTC

[GitHub] [spark] dongjoon-hyun commented on a change in pull request #30063: [SPARK-32402][SQL][FOLLOW-UP] Add case sensitivity tests for column resolution in ALTER TABLE

dongjoon-hyun commented on a change in pull request #30063:
URL: https://github.com/apache/spark/pull/30063#discussion_r505914686



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala
##########
@@ -318,4 +319,69 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession {
       assert(msg.contains("Table not found"))
     }
   }
+
+  test("ALTER TABLE case sensitivity") {
+    withTable("h2.test.alt_table") {
+      sql("CREATE TABLE h2.test.alt_table (c1 INTEGER NOT NULL, c2 INTEGER) USING _")
+      var t = spark.table("h2.test.alt_table")
+      var expectedSchema = new StructType().add("c1", IntegerType).add("c2", IntegerType)
+      assert(t.schema === expectedSchema)
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") {
+        val msg = intercept[AnalysisException] {
+          sql("ALTER TABLE h2.test.alt_table RENAME COLUMN C2 TO c3")
+        }.getMessage
+        assert(msg.contains("Cannot rename missing field C2 in test.alt_table schema"))
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") {
+        sql("ALTER TABLE h2.test.alt_table RENAME COLUMN C2 TO c3")
+        expectedSchema = new StructType().add("c1", IntegerType).add("c3", IntegerType)
+        t = spark.table("h2.test.alt_table")
+        assert(t.schema === expectedSchema)
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") {
+        val msg = intercept[AnalysisException] {
+          sql("ALTER TABLE h2.test.alt_table DROP COLUMN C3")
+        }.getMessage
+        assert(msg.contains("Cannot delete missing field C3 in test.alt_table schema"))
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") {
+        sql("ALTER TABLE h2.test.alt_table DROP COLUMN C3")
+        expectedSchema = new StructType().add("c1", IntegerType)
+        t = spark.table("h2.test.alt_table")
+        assert(t.schema === expectedSchema)
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") {
+        val msg = intercept[AnalysisException] {
+        sql("ALTER TABLE h2.test.alt_table ALTER COLUMN C1 TYPE DOUBLE")

Review comment:
       indentation?

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala
##########
@@ -318,4 +319,69 @@ class JDBCTableCatalogSuite extends QueryTest with SharedSparkSession {
       assert(msg.contains("Table not found"))
     }
   }
+
+  test("ALTER TABLE case sensitivity") {
+    withTable("h2.test.alt_table") {
+      sql("CREATE TABLE h2.test.alt_table (c1 INTEGER NOT NULL, c2 INTEGER) USING _")
+      var t = spark.table("h2.test.alt_table")
+      var expectedSchema = new StructType().add("c1", IntegerType).add("c2", IntegerType)
+      assert(t.schema === expectedSchema)
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") {
+        val msg = intercept[AnalysisException] {
+          sql("ALTER TABLE h2.test.alt_table RENAME COLUMN C2 TO c3")
+        }.getMessage
+        assert(msg.contains("Cannot rename missing field C2 in test.alt_table schema"))
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") {
+        sql("ALTER TABLE h2.test.alt_table RENAME COLUMN C2 TO c3")
+        expectedSchema = new StructType().add("c1", IntegerType).add("c3", IntegerType)
+        t = spark.table("h2.test.alt_table")
+        assert(t.schema === expectedSchema)
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") {
+        val msg = intercept[AnalysisException] {
+          sql("ALTER TABLE h2.test.alt_table DROP COLUMN C3")
+        }.getMessage
+        assert(msg.contains("Cannot delete missing field C3 in test.alt_table schema"))
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") {
+        sql("ALTER TABLE h2.test.alt_table DROP COLUMN C3")
+        expectedSchema = new StructType().add("c1", IntegerType)
+        t = spark.table("h2.test.alt_table")
+        assert(t.schema === expectedSchema)
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") {
+        val msg = intercept[AnalysisException] {
+        sql("ALTER TABLE h2.test.alt_table ALTER COLUMN C1 TYPE DOUBLE")
+        }.getMessage
+        assert(msg.contains("Cannot update missing field C1 in test.alt_table schema"))
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") {
+        sql("ALTER TABLE h2.test.alt_table ALTER COLUMN C1 TYPE DOUBLE")
+        expectedSchema = new StructType().add("c1", DoubleType)
+        t = spark.table("h2.test.alt_table")
+        assert(t.schema === expectedSchema)
+      }
+
+      withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") {
+        val msg = intercept[AnalysisException] {
+        sql("ALTER TABLE h2.test.alt_table ALTER COLUMN C1 DROP NOT NULL")

Review comment:
       indentation?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org