You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by vi...@apache.org on 2020/01/17 09:21:53 UTC

[incubator-hudi] branch master updated: [HUDI-537] Introduce `repair overwrite-hoodie-props` CLI command (#1241)

This is an automated email from the ASF dual-hosted git repository.

vinoth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new baa6b5e  [HUDI-537] Introduce `repair overwrite-hoodie-props` CLI command (#1241)
baa6b5e is described below

commit baa6b5e8899eb976b8b8cce92b1ba2cefaee8501
Author: vinoth chandar <vi...@users.noreply.github.com>
AuthorDate: Fri Jan 17 01:21:44 2020 -0800

    [HUDI-537] Introduce `repair overwrite-hoodie-props` CLI command (#1241)
---
 .../apache/hudi/cli/commands/RepairsCommand.java   | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/hudi-cli/src/main/java/org/apache/hudi/cli/commands/RepairsCommand.java b/hudi-cli/src/main/java/org/apache/hudi/cli/commands/RepairsCommand.java
index c021766..83af13c 100644
--- a/hudi-cli/src/main/java/org/apache/hudi/cli/commands/RepairsCommand.java
+++ b/hudi-cli/src/main/java/org/apache/hudi/cli/commands/RepairsCommand.java
@@ -23,6 +23,7 @@ import org.apache.hudi.cli.HoodiePrintHelper;
 import org.apache.hudi.cli.utils.InputStreamConsumer;
 import org.apache.hudi.cli.utils.SparkUtil;
 import org.apache.hudi.common.model.HoodiePartitionMetadata;
+import org.apache.hudi.common.table.HoodieTableConfig;
 import org.apache.hudi.common.table.HoodieTableMetaClient;
 import org.apache.hudi.common.util.FSUtils;
 
@@ -33,8 +34,16 @@ import org.springframework.shell.core.annotation.CliCommand;
 import org.springframework.shell.core.annotation.CliOption;
 import org.springframework.stereotype.Component;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.table.HoodieTableMetaClient.METAFOLDER_NAME;
 
 /**
  * CLI command to display and trigger repair options.
@@ -99,4 +108,33 @@ public class RepairsCommand implements CommandMarker {
 
     return HoodiePrintHelper.print(new String[] {"Partition Path", "Metadata Present?", "Action"}, rows);
   }
+
+  @CliCommand(value = "repair overwrite-hoodie-props", help = "Overwrite hoodie.properties with provided file. Risky operation. Proceed with caution!")
+  public String overwriteHoodieProperties(
+      @CliOption(key = {"new-props-file"}, help = "Path to a properties file on local filesystem to overwrite the table's hoodie.properties with")
+      final String overwriteFilePath) throws IOException {
+
+    HoodieTableMetaClient client = HoodieCLI.getTableMetaClient();
+    Properties newProps = new Properties();
+    newProps.load(new FileInputStream(new File(overwriteFilePath)));
+    Map<String, String> oldProps = client.getTableConfig().getProps();
+    Path metaPathDir = new Path(client.getBasePath(), METAFOLDER_NAME);
+    HoodieTableConfig.createHoodieProperties(client.getFs(), metaPathDir, newProps);
+
+    TreeSet<String> allPropKeys = new TreeSet<>();
+    allPropKeys.addAll(newProps.keySet().stream().map(Object::toString).collect(Collectors.toSet()));
+    allPropKeys.addAll(oldProps.keySet());
+
+    String[][] rows = new String[allPropKeys.size()][];
+    int ind = 0;
+    for (String propKey : allPropKeys) {
+      String[] row = new String[]{
+          propKey,
+          oldProps.getOrDefault(propKey, "null"),
+          newProps.getOrDefault(propKey, "null").toString()
+      };
+      rows[ind++] = row;
+    }
+    return HoodiePrintHelper.print(new String[] {"Property", "Old Value", "New Value"}, rows);
+  }
 }