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


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -20,18 +20,63 @@
 
 import org.apache.hudi.common.config.ConfigProperty;
 import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
 import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.table.HoodieTable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
 import java.util.Collections;
+import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
+
+import static org.apache.hudi.common.table.timeline.HoodieInstant.NAME_FORMAT;
+import static org.apache.hudi.common.table.timeline.HoodieInstant.UNDERSCORE;
+
 
 /**
  * Version 7 is going to be placeholder version for bridge release 0.16.0.
  * Version 8 is the placeholder version to track 1.x.
  */
 public class EightToSevenDowngradeHandler implements DowngradeHandler {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(EightToSevenDowngradeHandler.class);
+
   @Override
   public Map<ConfigProperty, String> downgrade(HoodieWriteConfig config, 
HoodieEngineContext context, String instantTime, SupportsUpgradeDowngrade 
upgradeDowngradeHelper) {
+    final HoodieTable table = upgradeDowngradeHelper.getTable(config, context);
+    UpgradeDowngradeUtils.runCompaction(table, context, config, 
upgradeDowngradeHelper);
+    UpgradeDowngradeUtils.syncCompactionRequestedFileToAuxiliaryFolder(table);
+
+    HoodieTableMetaClient metaClient = 
HoodieTableMetaClient.builder().setConf(context.getStorageConf().newInstance()).setBasePath(config.getBasePath()).build();
+    List<HoodieInstant> instants = 
metaClient.getActiveTimeline().getInstants();
+    if (!instants.isEmpty()) {
+      context.map(instants, instant -> {
+        Matcher matcher = NAME_FORMAT.matcher(instant.getFileName());
+        if (matcher.find()) {
+          try {
+            // Rename the metadata file name from the 
${instant_time}_${completion_time}.action[.state] format in version 1.x to the 
${instant_time}.action[.state] format in version 0.x.
+            StoragePath fromPath = new StoragePath(metaClient.getMetaPath(), 
instant.getFileName());
+            String regexStr = matcher.group(1);
+            StoragePath toPath = new StoragePath(metaClient.getMetaPath(), 
instant.getFileName().replaceAll(regexStr.substring(regexStr.indexOf(UNDERSCORE)),
 ""));

Review Comment:
   Maybe we can make it simpler, first split the file name by dot `.` we get 
the file name and suffix, then split the file name with `_` and we get the 
instant time, then we concatenate the instant time and the suffix and it's done.



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