danny0405 commented on code in PR #19733:
URL: https://github.com/apache/hudi/pull/19733#discussion_r3859309219
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/AlterTableCommand.scala:
##########
@@ -208,10 +210,57 @@ case class AlterTableCommand(table: CatalogTable,
changes: Seq[TableChange], cha
val newTable = table.copy(
properties = table.properties ++ properties,
comment =
properties.get(TableCatalog.PROP_COMMENT).orElse(table.comment))
+ updateHoodieTableConfigs(sparkSession, properties)
catalog.alterTable(newTable)
logInfo("table properties change finished")
}
+ /**
+ * Persists Hudi table properties in hoodie.properties as well as the Spark
catalog.
+ *
+ * The analyzer only creates this command for Hudi V2 tables, so the table
is known to be a Hudi
+ * table. Keep non-Hudi properties catalog-only, matching Spark's normal
ALTER TABLE behavior.
+ * Hudi's SQL aliases and datasource options are converted to the canonical
keys stored in
+ * hoodie.properties before validation and persistence.
+ */
+ private def updateHoodieTableConfigs(sparkSession: SparkSession, properties:
Map[String, String]): Unit = {
+ val tableConfigs = HoodieOptionConfig.mapSqlOptionsToTableConfigs(
+ HoodieOptionConfig.extractHoodieOptions(properties))
+
+ if (tableConfigs.nonEmpty) {
+ val metaClient = getMetaClient(sparkSession)
+
+ HoodieWriterUtils.validateTableConfig(
Review Comment:
**[P1] Validate invariants against the merged table config**
`validateTableConfig` mainly compares each incoming key with an existing
value; it does not re-run the cross-property validation used at table creation.
For example, a normal single-partition table can already have
`hoodie.datasource.write.hive_style_partitioning=true` and no explicit
slash-separated property. Setting
`hoodie.datasource.write.slash.separated.date.partitioning=true` passes here
because the new key has no existing value and the partition count is one, then
persists both flags even though `HoodieCatalogTable.extraTableConfig`
explicitly rejects that pair as mutually exclusive. Please validate the merged
existing+incoming configuration, including cross-property and value
constraints, before updating `hoodie.properties`.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]