Skip to content
Merged
Show file tree
Hide file tree
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 @@ -311,8 +311,15 @@ class SparkCatalogMetaStoreClient(syncConfig: HiveSyncConfig)
// table property keys may not start with 'spark.sql.'") because they are reserved for
// Spark's internal use (provider, schema parts, create version). Spark re-derives and
// writes these from the CatalogTable itself, so dropping them on the way in is safe.
//
// Also strip "EXTERNAL". HMSDDLExecutor.createTable sets both
// `tableType=EXTERNAL_TABLE` and `parameters[EXTERNAL]=TRUE`. Spark's
// HiveExternalCatalog.verifyTableProperties rejects "EXTERNAL" as a property key
// ("Cannot set or change the preserved property key: 'EXTERNAL'") because it controls
// table type via CatalogTableType instead. The tableType field below already encodes
// that information, so dropping the property is safe.
val tableProperties = Option(table.getParameters).map(_.asScala.toMap).getOrElse(Map.empty)
.filterNot { case (k, _) => k.startsWith("spark.sql.") }
.filterNot { case (k, _) => k.startsWith("spark.sql.") || k == "EXTERNAL" }

CatalogTable(
identifier = TableIdentifier(tbl, Some(db)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,32 @@ class TestSparkCatalogMetaStoreClient extends FunSuite with BeforeAndAfterAll {
}
}

test("createTable accepts EXTERNAL=TRUE parameter (mirrors HMSDDLExecutor behavior)") {
withTempDir { tmp =>
val client = newClient()
val databaseName = generateName("db")
val tableName = generateName("tbl")

client.createDatabase(new Database(databaseName, "test database", new File(tmp, databaseName).toURI.toString, new util.HashMap[String, String]()))

// Hudi's HMSDDLExecutor.createTable sets BOTH `tableType=EXTERNAL_TABLE` and
// `parameters[EXTERNAL]=TRUE` on the Hive Table object. Spark's
// HiveExternalCatalog.verifyTableProperties rejects "EXTERNAL" as a property key
// unless we strip it in toCatalogTable. This test mirrors that real-world shape.
val createdTable = newTable(
databaseName,
tableName,
new File(tmp, tableName).toURI.toString,
Seq("id" -> "int", "name" -> "string"),
Seq("dt" -> "string"),
Map("EXTERNAL" -> "TRUE", "comment" -> "v1"))

client.createTable(createdTable)
assertTrue(client.tableExists(databaseName, tableName))
assertEquals("v1", client.getTable(databaseName, tableName).getParameters.get("comment"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 nit: the test verifies createTable doesn't throw and that comment survives, but it never explicitly asserts that EXTERNAL was removed. Could you add something like assertFalse(client.getTable(databaseName, tableName).getParameters.containsKey("EXTERNAL")) to directly validate the actual fix?

- AI-generated; verify before applying. React 👍/👎 to flag quality.

}
}

private def newClient(): SparkCatalogMetaStoreClient = {
SparkSession.setActiveSession(spark)
SparkSession.setDefaultSession(spark)
Expand Down
Loading