|
17 | 17 |
|
18 | 18 | package org.apache.spark.sql.connector |
19 | 19 |
|
| 20 | +import java.util |
20 | 21 | import java.util.Locale |
21 | 22 |
|
22 | 23 | import org.scalatest.BeforeAndAfter |
23 | 24 |
|
24 | | -import org.apache.spark.sql.{AnalysisException, DataFrame, SaveMode} |
| 25 | +import org.apache.spark.sql.{AnalysisException, DataFrame, Row, SaveMode} |
25 | 26 | import org.apache.spark.sql.catalyst.TableIdentifier |
26 | 27 | import org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException |
27 | 28 | import org.apache.spark.sql.connector.catalog._ |
@@ -53,6 +54,25 @@ class DataSourceV2DataFrameSessionCatalogSuite |
53 | 54 |
|
54 | 55 | override protected val catalogAndNamespace: String = "" |
55 | 56 |
|
| 57 | + test("display properties survive ALTER TABLE in the session catalog") { |
| 58 | + val t = "display_properties" |
| 59 | + withTable(t) { |
| 60 | + sql(s"CREATE TABLE $t (id bigint) USING $v2Format") |
| 61 | + val table = sessionCatalog.loadTable(Identifier.of(Array("default"), t)) |
| 62 | + .asInstanceOf[InMemoryTable] |
| 63 | + table.setDisplayProperties(util.Map.of("catalog-label", "catalog-value")) |
| 64 | + |
| 65 | + sql(s"ALTER TABLE $t SET TBLPROPERTIES ('k' = 'v')") |
| 66 | + checkAnswer(sql(s"SHOW TBLPROPERTIES $t"), |
| 67 | + Seq(Row("catalog-label", "catalog-value"), Row("k", "v"))) |
| 68 | + checkAnswer(sql(s"DESCRIBE TABLE EXTENDED $t").where("col_name = 'Table Properties'"), |
| 69 | + Row("Table Properties", "[catalog-label=catalog-value,k=v]", "")) |
| 70 | + |
| 71 | + sql(s"ALTER TABLE $t UNSET TBLPROPERTIES ('k')") |
| 72 | + checkAnswer(sql(s"SHOW TBLPROPERTIES $t"), Row("catalog-label", "catalog-value")) |
| 73 | + } |
| 74 | + } |
| 75 | + |
56 | 76 | test("saveAsTable: Append mode should not fail if the table already exists " + |
57 | 77 | "and a same-name temp view exist") { |
58 | 78 | withTable("same_name") { |
@@ -177,6 +197,7 @@ class InMemoryTableSessionCatalog extends TestV2SessionCatalogBase[InMemoryTable |
177 | 197 |
|
178 | 198 | val newTable = new InMemoryTable(table.name, schema, table.partitioning, properties) |
179 | 199 | .alterTableWithData(table.data, schema) |
| 200 | + newTable.setDisplayProperties(table.displayProperties()) |
180 | 201 |
|
181 | 202 | tables.put(ident, newTable) |
182 | 203 |
|
|
0 commit comments