You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2022/09/01 10:20:48 UTC

[GitHub] [hudi] codope commented on a diff in pull request #6485: [HUDI-4528] Add diff tool to compare commit metadata

codope commented on code in PR #6485:
URL: https://github.com/apache/hudi/pull/6485#discussion_r960475936


##########
hudi-cli/src/main/java/org/apache/hudi/cli/commands/DiffCommand.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.cli.commands;
+
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.HoodieTableHeaderFields;
+import org.apache.hudi.common.model.HoodieCommitMetadata;
+import org.apache.hudi.common.model.HoodieWriteStat;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieArchivedTimeline;
+import org.apache.hudi.common.table.timeline.HoodieDefaultTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.util.NumericUtils;
+import org.apache.hudi.common.util.StringUtils;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.springframework.shell.core.CommandMarker;
+import org.springframework.shell.core.annotation.CliCommand;
+import org.springframework.shell.core.annotation.CliOption;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.cli.utils.TimelineUtil.getTimeDaysAgo;
+
+/**
+ * Given a file id or partition value, this command line utility tracks the changes to the file group or partition across range of commits.
+ * Usage: diff file --fileId <fileId>
+ */
+@Component
+public class DiffCommand implements CommandMarker {
+
+  private static final Logger LOG = LogManager.getLogger(DiffCommand.class);
+
+  @CliCommand(value = "diff file", help = "Check how file differs across range of commits")
+  public String diffFile(
+      @CliOption(key = {"fileId"}, help = "File ID to diff across range of commits", mandatory = true) String fileId,
+      @CliOption(key = {"startTs"}, help = "start time for compactions, default: now - 10 days") String startTs,
+      @CliOption(key = {"endTs"}, help = "end time for compactions, default: now - 1 day") String endTs,
+      @CliOption(key = {"limit"}, help = "Limit compactions", unspecifiedDefaultValue = "-1") final Integer limit,
+      @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField,
+      @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending,
+      @CliOption(key = {"headeronly"}, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly,
+      @CliOption(key = {"includeArchivedTimeline"}, help = "Include archived commits as well",
+          unspecifiedDefaultValue = "false") final boolean includeArchivedTimeline) throws IOException {
+    HoodieDefaultTimeline timeline = getTimelineInRange(startTs, endTs, includeArchivedTimeline);
+    return printCommitsWithMetadataForFileId(timeline, limit, sortByField, descending, headerOnly, "", fileId);
+  }
+
+  @CliCommand(value = "diff partition", help = "Check how file differs across range of commits")
+  public String diffPartition(
+      @CliOption(key = {"partitionPath"}, help = "Relative partition path to diff across range of commits", mandatory = true) String partitionPath,

Review Comment:
   This command tracks changes to a partition. It is meant to be used only for partitioned tables. I'll make it clear in the `help`. Without specifying `--partitionPath`, this command will fail.



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org