huaxingao commented on a change in pull request #29324:
URL: https://github.com/apache/spark/pull/29324#discussion_r464697692
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala
##########
@@ -106,4 +106,84 @@ class JDBCTableCatalogSuite extends QueryTest with
SharedSparkSession {
Seq(Row("test", "people"), Row("test", "new_table")))
}
}
+
+ test("alter table ... add column") {
+ withTable("h2.test.alt_table") {
+ sql("CREATE TABLE h2.test.alt_table (ID INTEGER) USING _")
+ sql("ALTER TABLE h2.test.alt_table ADD COLUMNS (C1 INTEGER, C2 STRING)")
+ var t = spark.table("h2.test.alt_table")
+ var expectedSchema = new StructType()
+ .add("ID", IntegerType)
+ .add("C1", IntegerType)
+ .add("C2", StringType)
+ assert(t.schema === expectedSchema)
+ sql("ALTER TABLE h2.test.alt_table ADD COLUMNS (C3 DOUBLE)")
+ t = spark.table("h2.test.alt_table")
+ expectedSchema = new StructType()
+ .add("ID", IntegerType)
+ .add("C1", IntegerType)
+ .add("C2", StringType)
+ .add("C3", DoubleType)
+ assert(t.schema === expectedSchema)
+ }
+ }
+
+ test("alter table ... rename column") {
+ withTable("h2.test.alt_table") {
+ sql("CREATE TABLE h2.test.alt_table (ID 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)
+ assert(t.schema === expectedSchema)
+ }
+ }
+
+ test("alter table ... drop column") {
+ withTable("h2.test.alt_table") {
+ sql("CREATE TABLE h2.test.alt_table (C1 INTEGER, C2 INTEGER) USING _")
+ sql("ALTER TABLE h2.test.alt_table DROP COLUMN C1")
+ val t = spark.table("h2.test.alt_table")
+ val expectedSchema = new StructType().add("C2", IntegerType)
+ assert(t.schema === expectedSchema)
+ }
+ }
+
+ test("alter table ... update column type") {
+ withTable("h2.test.alt_table") {
+ sql("CREATE TABLE h2.test.alt_table (ID INTEGER) USING _")
+ sql("ALTER TABLE h2.test.alt_table ALTER COLUMN id TYPE DOUBLE")
+ val t = spark.table("h2.test.alt_table")
+ val expectedSchema = new StructType().add("ID", DoubleType)
+ assert(t.schema === expectedSchema)
+ }
+ }
+
+ test("alter table ... update column nullability") {
+ withTable("h2.test.alt_table") {
+ sql("CREATE TABLE h2.test.alt_table (ID INTEGER NOT NULL) USING _")
+ var t = spark.table("h2.test.alt_table")
+ var expectedSchema = new StructType().add("ID", IntegerType, nullable =
false)
+ // Todo: find out why the nullable for ID INTEGER NOT NULL is true
+ // assert(t.schema === expectedSchema)
Review comment:
Somehow ```t.schema``` has ```StructType().add("ID", IntegerType,
nullable = true)```. I comment out this assert for now and will find out what
is wrong.
----------------------------------------------------------------
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]