Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/16626#discussion_r106098075 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala --- @@ -2182,4 +2218,85 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils { } } } + + Seq("parquet", "json", "csv").foreach { provider => + test(s"alter datasource table add columns - $provider") { + withTable("alter_add_ds") { + sql(s"CREATE TABLE alter_add_ds (c1 int) USING $provider") + sql("INSERT INTO alter_add_ds VALUES (1)") + sql("ALTER TABLE alter_add_ds ADD COLUMNS (c2 int)") + checkAnswer( + sql("SELECT * FROM alter_add_ds"), + Seq(Row(1, null)) + ) + checkAnswer( + sql("SELECT * FROM alter_add_ds where c2 is null"), + Seq(Row(1, null)) + ) + + sql("INSERT INTO alter_add_ds VALUES (3, 2)") + checkAnswer( + sql("SELECT * FROM alter_add_ds where c2 = 2"), + Seq(Row(3, 2)) + ) + } + } + } + + Seq("parquet", "json", "csv").foreach { provider => + test(s"alter datasource table add columns - partitioned - $provider") { + withTable("alter_add_ds") { + sql(s"CREATE TABLE alter_add_ds (c1 int, c2 int) USING $provider partitioned by (c2)") + sql("INSERT INTO alter_add_ds partition(c2 = 2) VALUES (1)") + sql("ALTER TABLE alter_add_ds ADD COLUMNS (c3 int)") + checkAnswer( + sql("SELECT * FROM alter_add_ds"), + Seq(Row(1, null, 2)) + ) + checkAnswer( + sql("SELECT * FROM alter_add_ds where c3 is null"), + Seq(Row(1, null, 2)) + ) + sql("INSERT INTO alter_add_ds partition(c2 =1) VALUES (2, 3)") + checkAnswer( + sql("SELECT * FROM alter_add_ds where c3 = 3"), + Seq(Row(2, 3, 1)) + ) + checkAnswer( + sql("SELECT * FROM alter_add_ds where c2 = 1"), + Seq(Row(2, 3, 1)) + ) + } + } + } + + test("alter datasource table add columns - text format not supported") { + withTable("alter_add_ds_text") { + sql(s"CREATE TABLE alter_add_ds_text (c1 int) USING text") + val e = intercept[AnalysisException] { + sql("ALTER TABLE alter_add_ds_text ADD COLUMNS (c2 int)") + }.getMessage + assert(e.contains("does not support ALTER ADD COLUMNS")) + } + } + + test("alter table add columns -- not support temp view") { + withTempView("tmp_v") { + sql("create temporary view tmp_v as select 1 as c1, 2 as c2") --- End diff -- Nit: make all the SQL keywords upper cases.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org