danny0405 commented on code in PR #19733:
URL: https://github.com/apache/hudi/pull/19733#discussion_r3870039411


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/command/AlterTableCommand.scala:
##########
@@ -208,10 +211,98 @@ 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 val protectedTableConfigs = Set(
+    HoodieTableConfig.NAME.key,
+    HoodieTableConfig.TYPE.key,
+    HoodieTableConfig.VERSION.key,
+    HoodieTableConfig.INITIAL_VERSION.key,
+    HoodieTableConfig.PRECOMBINE_FIELD.key,
+    HoodieTableConfig.LOG_FILE_FORMAT.key,
+    HoodieTableConfig.RECORDKEY_FIELDS.key,
+    HoodieTableConfig.PARTITION_FIELDS.key,
+    HoodieTableConfig.ORDERING_FIELDS.key,
+    HoodieTableConfig.KEY_GENERATOR_CLASS_NAME.key,
+    HoodieTableConfig.KEY_GENERATOR_TYPE.key,
+    HoodieTableConfig.RECORD_MERGE_MODE.key,
+    HoodieTableConfig.RECORD_MERGE_STRATEGY_ID.key,
+    HoodieTableConfig.PAYLOAD_CLASS_NAME.key,
+    HoodieTableConfig.LEGACY_PAYLOAD_CLASS_NAME.key,
+    HoodieTableConfig.TABLE_CHECKSUM.key,
+    HoodieTableConfig.CREATE_SCHEMA.key,
+    HoodieTableConfig.POPULATE_META_FIELDS.key,
+    HoodieTableConfig.META_FIELDS_MODE.key,
+    HoodieTableConfig.BOOTSTRAP_BASE_PATH.key,
+    HoodieTableConfig.DATABASE_NAME.key,
+    HoodieTableConfig.TIMELINE_LAYOUT_VERSION.key,
+    HoodieTableConfig.TABLE_STORAGE_LAYOUT.key,
+    HoodieTableConfig.TABLE_FORMAT.key

Review Comment:
   **[P1] Keep metadata-partition state system-managed**
   
   `HoodieTableConfig.TABLE_METADATA_PARTITIONS` and 
`TABLE_METADATA_PARTITIONS_INFLIGHT` are also absent from this set. Since 
arbitrary `hoodie.*` keys reach `HoodieTableConfig.update/delete`, SQL can mark 
an unbuilt metadata partition as completed or remove a real completed/inflight 
marker. Readers and index support trust `getMetadataPartitions` to decide which 
metadata indexes are available, while the metadata writer uses both sets to 
decide what to update, so altering these values can route reads to missing or 
stale indexes and corrupt subsequent metadata maintenance. These internal state 
keys must not be user-mutable through TBLPROPERTIES.



-- 
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]

Reply via email to