linliu-code commented on code in PR #11889:
URL: https://github.com/apache/hudi/pull/11889#discussion_r1746050337


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -79,17 +96,60 @@ public Map<ConfigProperty, String> 
downgrade(HoodieWriteConfig config, HoodieEng
     }
 
     downgradePartitionFields(config, context, upgradeDowngradeHelper, 
tablePropsToAdd);
+    downgradeMetadataPartitions(metaClient, context, tablePropsToAdd);
     return tablePropsToAdd;
   }
 
-  private static void downgradePartitionFields(HoodieWriteConfig config, 
HoodieEngineContext context, SupportsUpgradeDowngrade upgradeDowngradeHelper,
+  private static void downgradePartitionFields(HoodieWriteConfig config,
+                                               HoodieEngineContext context,
+                                               SupportsUpgradeDowngrade 
upgradeDowngradeHelper,
                                                Map<ConfigProperty, String> 
tablePropsToAdd) {
     HoodieTableConfig tableConfig = upgradeDowngradeHelper.getTable(config, 
context).getMetaClient().getTableConfig();
     String keyGenerator = tableConfig.getKeyGeneratorClassName();
     String partitionPathField = 
config.getString(KeyGeneratorOptions.PARTITIONPATH_FIELD_NAME.key());
-    if (keyGenerator != null && partitionPathField != null
-        && (keyGenerator.equals(KeyGeneratorType.CUSTOM.getClassName()) || 
keyGenerator.equals(KeyGeneratorType.CUSTOM_AVRO.getClassName()))) {
+    if (keyGenerator != null
+        && partitionPathField != null
+        && (keyGenerator.equals(KeyGeneratorType.CUSTOM.getClassName())
+          || 
keyGenerator.equals(KeyGeneratorType.CUSTOM_AVRO.getClassName()))) {
       tablePropsToAdd.put(HoodieTableConfig.PARTITION_FIELDS, 
tableConfig.getPartitionFieldProp());
     }
   }
+
+  static void downgradeMetadataPartitions(HoodieTableMetaClient metaClient,
+                                          HoodieEngineContext context,
+                                          Map<ConfigProperty, String> 
tablePropsToAdd) {
+    metaClient.reloadActiveTimeline();
+    StoragePath basePath = metaClient.getBasePath();
+
+    HoodieTableMetaClient mdtMetaClient = HoodieTableMetaClient.builder()
+        .setConf(HadoopFSUtils.getStorageConfWithCopy(
+            (Configuration) context.getStorageConf().unwrap()))
+        .setBasePath(
+            new Path(basePath.toString(),
+                HoodieTableMetaClient.METADATA_TABLE_FOLDER_PATH).toString())
+        .setLoadActiveTimelineOnLoad(true)
+        .build();
+
+    // Delete partitions.
+    deleteMetadataPartition(context, metaClient.getStorage(), mdtMetaClient);
+
+    // No matter if partitions have been removed, block their creation.
+    tablePropsToAdd.put(TABLE_METADATA_PARTITIONS, "");

Review Comment:
   Yeah, I will fix.



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