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

2022-09-01 Thread GitBox


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


##
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 
+ */
+@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,
+  @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 = 

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

2022-09-01 Thread GitBox


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


##
hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieDefaultTimeline.java:
##
@@ -399,4 +399,19 @@ public boolean isEmpty(HoodieInstant instant) {
   public String toString() {
 return this.getClass().getName() + ": " + 
instants.stream().map(Object::toString).collect(Collectors.joining(","));
   }
+
+  /**
+   * Merge this timeline with the given timeline.
+   */
+  public HoodieDefaultTimeline mergeTimeline(HoodieDefaultTimeline timeline) {
+Stream instantStream = Stream.concat(instants.stream(), 
timeline.getInstants()).sorted();
+Function> details = instant -> {
+  if (instants.stream().anyMatch(i -> i.equals(instant))) {
+return this.getInstantDetails(instant);
+  } else {
+return timeline.getInstantDetails(instant);
+  }

Review Comment:
   I went through the code. The archived timeline details are computed just 
once. But active tiimeline instant details are re-computed. Typically, for 
older tables, archive timeline is much bigger than active timeline so the 
amortized cost should be within bounds. 
   
   To optimize for active timeline, we need a map/cache of instant details in 
`HoodieActiveTimeline` and then in `HoodieActiveTimeline#getInstantDetails`, we 
have to check this cache before reading from file. I can take it up in a 
separate PR. It might be beneficial at other places too, irrespective of this 
patch. 



-- 
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-unsubscr...@hudi.apache.org

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



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

2022-09-01 Thread GitBox


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


##
hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieDefaultTimeline.java:
##
@@ -399,4 +399,19 @@ public boolean isEmpty(HoodieInstant instant) {
   public String toString() {
 return this.getClass().getName() + ": " + 
instants.stream().map(Object::toString).collect(Collectors.joining(","));
   }
+
+  /**
+   * Merge this timeline with the given timeline.
+   */
+  public HoodieDefaultTimeline mergeTimeline(HoodieDefaultTimeline timeline) {
+Stream instantStream = Stream.concat(instants.stream(), 
timeline.getInstants()).sorted();
+Function> details = instant -> {
+  if (instants.stream().anyMatch(i -> i.equals(instant))) {
+return this.getInstantDetails(instant);
+  } else {
+return timeline.getInstantDetails(instant);
+  }

Review Comment:
   I went through the code. The archived timeline details are computed just 
once. But active tiimeline instant details are re-computed. Typically, for 
older tables, archive timeline is much bigger than active timeline so the 
amortized cost should be within bounds. 
   
   To optimize for active timeline, we need a map/cache of instant details in 
`HoodieActiveTimeline` and then in `HoodieActiveTimeline#getInstantDetails`, we 
have to check this cache before reading from file. I can take it up in a 
separate PR. It might be beneficial at other places too, irrespective of this 
patch. HUDI-4768



-- 
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-unsubscr...@hudi.apache.org

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



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

2022-09-01 Thread GitBox


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


##
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 
+ */
+@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,
+  @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 = 

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

2022-09-01 Thread GitBox


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 
+ */
+@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-unsubscr...@hudi.apache.org

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