From commits-return-9952-archive-asf-public=cust-asf.ponee.io@hudi.apache.org Fri Jan 17 09:21:55 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id AD9AD180636 for ; Fri, 17 Jan 2020 10:21:54 +0100 (CET) Received: (qmail 15541 invoked by uid 500); 17 Jan 2020 09:21:54 -0000 Mailing-List: contact commits-help@hudi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hudi.apache.org Delivered-To: mailing list commits@hudi.apache.org Received: (qmail 15532 invoked by uid 99); 17 Jan 2020 09:21:54 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jan 2020 09:21:54 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id E400281975; Fri, 17 Jan 2020 09:21:53 +0000 (UTC) Date: Fri, 17 Jan 2020 09:21:53 +0000 To: "commits@hudi.apache.org" Subject: [incubator-hudi] branch master updated: [HUDI-537] Introduce `repair overwrite-hoodie-props` CLI command (#1241) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <157925291380.30651.17511141825614168602@gitbox.apache.org> From: vinoth@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-hudi X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: c2c0f6b13d5b72b3098ed1b343b0a89679f854b3 X-Git-Newrev: baa6b5e8899eb976b8b8cce92b1ba2cefaee8501 X-Git-Rev: baa6b5e8899eb976b8b8cce92b1ba2cefaee8501 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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 oldProps = client.getTableConfig().getProps(); + Path metaPathDir = new Path(client.getBasePath(), METAFOLDER_NAME); + HoodieTableConfig.createHoodieProperties(client.getFs(), metaPathDir, newProps); + + TreeSet 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); + } }