Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,41 +181,25 @@ class HiveExternalCatalogSuite extends ExternalCatalogSuite {
"INSERT overwrite directory \"fs://localhost/tmp\" select 1 as a"))
}

test("SPARK-31061: alterTable should be able to change table provider") {
test("SPARK-31061: alterTable should be able to change table provider/hive") {
val catalog = newBasicCatalog()
val parquetTable = CatalogTable(
identifier = TableIdentifier("parq_tbl", Some("db1")),
tableType = CatalogTableType.MANAGED,
storage = storageFormat.copy(locationUri = Some(new URI("file:/some/path"))),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file:/some/path seems not very suitable.

schema = new StructType().add("col1", "int").add("col2", "string"),
provider = Some("parquet"))
catalog.createTable(parquetTable, ignoreIfExists = false)

val rawTable = externalCatalog.getTable("db1", "parq_tbl")
assert(rawTable.provider === Some("parquet"))

val fooTable = parquetTable.copy(provider = Some("foo"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we should use rawTableget from catalog instead of parquetTable from the beginning.

catalog.alterTable(fooTable)
val alteredTable = externalCatalog.getTable("db1", "parq_tbl")
assert(alteredTable.provider === Some("foo"))
}

test("SPARK-31061: alterTable should be able to change table provider from hive") {
val catalog = newBasicCatalog()
val hiveTable = CatalogTable(
identifier = TableIdentifier("parq_tbl", Some("db1")),
tableType = CatalogTableType.MANAGED,
storage = storageFormat,
schema = new StructType().add("col1", "int").add("col2", "string"),
provider = Some("hive"))
catalog.createTable(hiveTable, ignoreIfExists = false)

val rawTable = externalCatalog.getTable("db1", "parq_tbl")
assert(rawTable.provider === Some("hive"))

val fooTable = rawTable.copy(provider = Some("foo"))
catalog.alterTable(fooTable)
val alteredTable = externalCatalog.getTable("db1", "parq_tbl")
assert(alteredTable.provider === Some("foo"))
Seq("parquet", "hive").foreach( provider => {
val tableDDL = CatalogTable(
identifier = TableIdentifier("parq_tbl", Some("db1")),
tableType = CatalogTableType.MANAGED,
storage = storageFormat,
schema = new StructType().add("col1", "int"),
provider = Some(provider))
catalog.dropTable("db1", "parq_tbl", true, true)
catalog.createTable(tableDDL, ignoreIfExists = false)

val rawTable = externalCatalog.getTable("db1", "parq_tbl")
assert(rawTable.provider === Some(provider))

val fooTable = rawTable.copy(provider = Some("foo"))
catalog.alterTable(fooTable)
val alteredTable = externalCatalog.getTable("db1", "parq_tbl")
assert(alteredTable.provider === Some("foo"))
})
}
}