satishkotha commented on a change in pull request #2678:
URL: https://github.com/apache/hudi/pull/2678#discussion_r613635722
##########
File path:
hudi-cli/src/main/java/org/apache/hudi/cli/commands/CommitsCommand.java
##########
@@ -431,4 +429,23 @@ public String syncCommits(@CliOption(key = {"path"}, help
= "Path of the table t
return "Load sync state between " +
HoodieCLI.getTableMetaClient().getTableConfig().getTableName() + " and "
+ HoodieCLI.syncTableMetadata.getTableConfig().getTableName();
}
+
+ /*
+ Checks whether a commit or replacecommit action exists in the timeline.
+ * */
+ private Option<HoodieCommitMetadata>
getCommitMetadataForInstant(HoodieTimeline timeline, String instantTime) throws
IOException {
+ List<HoodieInstant> instants = Arrays.asList(
+ new HoodieInstant(false, HoodieTimeline.COMMIT_ACTION,
instantTime),
+ new HoodieInstant(false, HoodieTimeline.REPLACE_COMMIT_ACTION,
instantTime),
+ new HoodieInstant(false, HoodieTimeline.DELTA_COMMIT_ACTION,
instantTime));
+
+ Option<HoodieInstant> hoodieInstant =
Option.fromJavaOptional(instants.stream().filter(timeline::containsInstant).findAny());
+
+ if (hoodieInstant.isPresent()) {
+ return
Option.of(HoodieCommitMetadata.fromBytes(timeline.getInstantDetails(hoodieInstant.get()).get(),
Review comment:
I like the earlier implementation where we are actually parsing this as
HoodieReplaceCommitMetadata for 'REPLACE_COMMIT'. That allows callers to print
additional replace specific information.
##########
File path:
hudi-cli/src/main/java/org/apache/hudi/cli/commands/CommitsCommand.java
##########
@@ -43,11 +44,7 @@
import org.springframework.stereotype.Component;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
Review comment:
nit: you may want to change intellij editor settings. its generally
discouraged to use '*' imports.
##########
File path:
hudi-cli/src/main/java/org/apache/hudi/cli/commands/CommitsCommand.java
##########
@@ -431,4 +429,23 @@ public String syncCommits(@CliOption(key = {"path"}, help
= "Path of the table t
return "Load sync state between " +
HoodieCLI.getTableMetaClient().getTableConfig().getTableName() + " and "
+ HoodieCLI.syncTableMetadata.getTableConfig().getTableName();
}
+
+ /*
+ Checks whether a commit or replacecommit action exists in the timeline.
+ * */
+ private Option<HoodieCommitMetadata>
getCommitMetadataForInstant(HoodieTimeline timeline, String instantTime) throws
IOException {
+ List<HoodieInstant> instants = Arrays.asList(
+ new HoodieInstant(false, HoodieTimeline.COMMIT_ACTION,
instantTime),
+ new HoodieInstant(false, HoodieTimeline.REPLACE_COMMIT_ACTION,
instantTime),
+ new HoodieInstant(false, HoodieTimeline.DELTA_COMMIT_ACTION,
instantTime));
+
+ Option<HoodieInstant> hoodieInstant =
Option.fromJavaOptional(instants.stream().filter(timeline::containsInstant).findAny());
Review comment:
minor: timeline.containsInstant is linear search in all active instants.
Number of instants in timeline is expected to be small, so this may not be a
big issue. if its not lot of work consider trim timeline to specified instant
time using findInstantsBeforeOrEquals().getReverseOrderedInstants().findFirst()
##########
File path:
hudi-cli/src/main/java/org/apache/hudi/cli/commands/CommitsCommand.java
##########
@@ -266,12 +267,15 @@ public String showCommitPartitions(
HoodieActiveTimeline activeTimeline =
HoodieCLI.getTableMetaClient().getActiveTimeline();
HoodieTimeline timeline =
activeTimeline.getCommitsTimeline().filterCompletedInstants();
- HoodieInstant commitInstant = new HoodieInstant(false,
HoodieTimeline.COMMIT_ACTION, instantTime);
- if (!timeline.containsInstant(commitInstant)) {
+ Option<HoodieInstant> hoodieInstantOptional =
getCommitOrReplaceCommitInstant(timeline, instantTime);
+ if (!hoodieInstantOptional.isPresent()) {
return "Commit " + instantTime + " not found in Commits " + timeline;
}
- HoodieCommitMetadata meta =
HoodieCommitMetadata.fromBytes(activeTimeline.getInstantDetails(commitInstant).get(),
+
+ HoodieInstant hoodieInstant = hoodieInstantOptional.get();
+
+ HoodieCommitMetadata meta =
HoodieCommitMetadata.fromBytes(activeTimeline.getInstantDetails(hoodieInstant).get(),
HoodieCommitMetadata.class);
List<Comparable[]> rows = new ArrayList<>();
for (Map.Entry<String, List<HoodieWriteStat>> entry :
meta.getPartitionToWriteStats().entrySet()) {
Review comment:
sounds good. Its important for debugging to at least show commit action
type (commit vs deltacommit vs replacecommit) in the output. If possible, add
that information now. If not, please ping me when you have next PR.
##########
File path:
hudi-cli/src/test/java/org/apache/hudi/cli/testutils/HoodieTestReplaceCommitMetadatGenerator.java
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.testutils;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hudi.avro.model.HoodieRequestedReplaceMetadata;
+import org.apache.hudi.common.model.HoodieReplaceCommitMetadata;
+import org.apache.hudi.common.model.HoodieWriteStat;
+import org.apache.hudi.common.model.WriteOperationType;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.testutils.FileCreateUtils;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.testutils.HoodieTestTable;
+import org.apache.hudi.common.util.Option;
+
+import java.util.*;
Review comment:
nit: avoid * import
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]