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/22 16:02:41 UTC

[GitHub] [spark] huaxingao commented on a change in pull request #30089: [SPARK-33137][SQL] Support ALTER TABLE in JDBC v2 Table Catalog: update type and nullability of columns (Postgres dialect)

huaxingao commented on a change in pull request #30089:
URL: https://github.com/apache/spark/pull/30089#discussion_r510280543



##########
File path: external/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/V2JDBCTest.scala
##########
@@ -55,7 +55,54 @@ trait V2JDBCTest extends SharedSparkSession {
     assert(msg.contains("Table not found"))
   }
 
-  test("SPARK-33034: ALTER TABLE ... update column type") {
+  test("ALTER TABLE ... rename column") {
+    withTable(s"$catalogName.alt_table") {
+      sql(s"CREATE TABLE $catalogName.alt_table (id INTEGER, C0 INTEGER) USING _")
+      sql(s"ALTER TABLE $catalogName.alt_table RENAME COLUMN id TO C")
+      val t = spark.table(s"$catalogName.alt_table")
+      val expectedSchema = catalogName match {
+        case "oracle" => new StructType().add("C", DecimalType(10, 0)).add("C0", DecimalType(10, 0))
+        case _ => new StructType().add("C", IntegerType).add("C0", IntegerType)
+      }
+      assert(t.schema === expectedSchema)
+      // Rename to already existing column
+      val msg = intercept[AnalysisException] {
+        sql(s"ALTER TABLE $catalogName.alt_table RENAME COLUMN C TO C0")
+      }.getMessage
+      assert(msg.contains("Cannot rename column, because C0 already exists"))
+    }
+    // Rename a column in a not existing table
+    val msg = intercept[AnalysisException] {
+      sql(s"ALTER TABLE $catalogName.not_existing_table RENAME COLUMN ID TO C")
+    }.getMessage
+    assert(msg.contains("Table not found"))
+  }
+
+  test("ALTER TABLE ... drop column") {
+    withTable(s"$catalogName.alt_table") {
+      sql(s"CREATE TABLE $catalogName.alt_table (C1 INTEGER, C2 INTEGER, c3 INTEGER) USING _")
+      sql(s"ALTER TABLE $catalogName.alt_table DROP COLUMN C1")
+      sql(s"ALTER TABLE $catalogName.alt_table DROP COLUMN c3")
+      val t = spark.table(s"$catalogName.alt_table")
+      val expectedSchema = catalogName match {
+        case "oracle" => new StructType().add("C2", DecimalType(10, 0))

Review comment:
       Oracle uses `NUMBER(10)` for integer. Please see https://docs.oracle.com/cd/E19501-01/819-3659/gcmaz/




----------------------------------------------------------------
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