[GitHub] [hudi] hddong commented on a change in pull request #2325: [HUDI-699]Fix CompactionCommand and add unit test for CompactionCommand

2021-04-02 Thread GitBox


hddong commented on a change in pull request #2325:
URL: https://github.com/apache/hudi/pull/2325#discussion_r606166490



##
File path: 
hudi-cli/src/main/java/org/apache/hudi/cli/commands/CompactionCommand.java
##
@@ -175,25 +174,26 @@ public String compactionShowArchived(
 HoodieArchivedTimeline archivedTimeline = client.getArchivedTimeline();
 HoodieInstant instant = new HoodieInstant(HoodieInstant.State.COMPLETED,
 HoodieTimeline.COMPACTION_ACTION, compactionInstantTime);
-String startTs = CommitUtil.addHours(compactionInstantTime, -1);
-String endTs = CommitUtil.addHours(compactionInstantTime, 1);

Review comment:
   > if we want to load a `ts` equals `compactionInstantTime`, can we add a 
new method that takes only one `instantTime` as input param? WDYT
   
   Yes, had add it.




-- 
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:
us...@infra.apache.org




[GitHub] [hudi] hddong commented on a change in pull request #2325: [HUDI-699]Fix CompactionCommand and add unit test for CompactionCommand

2021-02-05 Thread GitBox


hddong commented on a change in pull request #2325:
URL: https://github.com/apache/hudi/pull/2325#discussion_r570082278



##
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestCommitsCommand.java
##
@@ -194,7 +194,7 @@ public void testShowArchivedCommits() throws Exception {
 // archived 101 and 102 instants, remove 103 and 104 instant
 data.remove("103");
 data.remove("104");
-String expected = generateExpectData(3, data);
+String expected = generateExpectData(1, data);

Review comment:
   > Why do we need to change this?
   
   
https://github.com/apache/hudi/blob/647e9faf255b9ae5796f513d13c769a8c87788d4/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieArchivedTimeline.java#L133
   
   
https://github.com/apache/hudi/blob/647e9faf255b9ae5796f513d13c769a8c87788d4/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieInstant.java#L103-L108
   
   `new HoodieInstant(false, action, instantTime)` always return `COMPLETED` 
when State is not `INFLIGHT`, so there is 3 `COMPLETED` records for one 
instanct. Now, use the real state instead, and can get the correct number.

##
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestCommitsCommand.java
##
@@ -194,7 +194,7 @@ public void testShowArchivedCommits() throws Exception {
 // archived 101 and 102 instants, remove 103 and 104 instant
 data.remove("103");
 data.remove("104");
-String expected = generateExpectData(3, data);
+String expected = generateExpectData(1, data);

Review comment:
   `return new 
HoodieInstant(HoodieInstant.State.valueOf(record.get(ACTION_STATE).toString()), 
action, instantTime);`

##
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestCompactionCommand.java
##
@@ -0,0 +1,207 @@
+/*
+ * 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.avro.model.HoodieCompactionPlan;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.testutils.AbstractShellIntegrationTest;
+import org.apache.hudi.cli.testutils.HoodieTestCommitMetadataGenerator;
+import org.apache.hudi.common.model.HoodieAvroPayload;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.table.timeline.TimelineMetadataUtils;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.testutils.CompactionTestUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.table.HoodieSparkTable;
+import org.apache.hudi.table.HoodieTimelineArchiveLog;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+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.common.table.timeline.HoodieTimeline.COMPACTION_ACTION;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Test Cases for {@link CompactionCommand}.
+ */
+public class TestCompactionCommand extends AbstractShellIntegrationTest {
+
+  private String tableName;
+  private String tablePath;
+
+  @BeforeEach
+  public void init() {
+tableName = "test_table";
+tablePath = basePath + tableName;
+  }
+
+  @Test
+  public void testVerifyTableType() throws IOException {
+// create COW table.
+new TableCommand().createTable(
+tablePath, 

[GitHub] [hudi] hddong commented on a change in pull request #2325: [HUDI-699]Fix CompactionCommand and add unit test for CompactionCommand

2021-02-04 Thread GitBox


hddong commented on a change in pull request #2325:
URL: https://github.com/apache/hudi/pull/2325#discussion_r570087122



##
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestCompactionCommand.java
##
@@ -0,0 +1,207 @@
+/*
+ * 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.avro.model.HoodieCompactionPlan;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.testutils.AbstractShellIntegrationTest;
+import org.apache.hudi.cli.testutils.HoodieTestCommitMetadataGenerator;
+import org.apache.hudi.common.model.HoodieAvroPayload;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieInstant;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.table.timeline.TimelineMetadataUtils;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.testutils.CompactionTestUtils;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.table.HoodieSparkTable;
+import org.apache.hudi.table.HoodieTimelineArchiveLog;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+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.common.table.timeline.HoodieTimeline.COMPACTION_ACTION;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * Test Cases for {@link CompactionCommand}.
+ */
+public class TestCompactionCommand extends AbstractShellIntegrationTest {
+
+  private String tableName;
+  private String tablePath;
+
+  @BeforeEach
+  public void init() {
+tableName = "test_table";
+tablePath = basePath + tableName;
+  }
+
+  @Test
+  public void testVerifyTableType() throws IOException {
+// create COW table.
+new TableCommand().createTable(
+tablePath, tableName, HoodieTableType.COPY_ON_WRITE.name(),
+"", TimelineLayoutVersion.VERSION_1, 
HoodieAvroPayload.class.getName());
+
+// expect HoodieException for COPY_ON_WRITE table.
+assertThrows(HoodieException.class,
+() -> new CompactionCommand().compactionsAll(false, -1, "", false, 
false));
+  }
+
+  @Test
+  public void testCompactionsAll() throws IOException {

Review comment:
   > Can we follow this naming pattern: `testXXXCommand` ?
   
   Add java doc for them first as before. Will modify it if needed. 





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:
us...@infra.apache.org




[GitHub] [hudi] hddong commented on a change in pull request #2325: [HUDI-699]Fix CompactionCommand and add unit test for CompactionCommand

2021-02-04 Thread GitBox


hddong commented on a change in pull request #2325:
URL: https://github.com/apache/hudi/pull/2325#discussion_r570082863



##
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestCommitsCommand.java
##
@@ -194,7 +194,7 @@ public void testShowArchivedCommits() throws Exception {
 // archived 101 and 102 instants, remove 103 and 104 instant
 data.remove("103");
 data.remove("104");
-String expected = generateExpectData(3, data);
+String expected = generateExpectData(1, data);

Review comment:
   `return new 
HoodieInstant(HoodieInstant.State.valueOf(record.get(ACTION_STATE).toString()), 
action, instantTime);`





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:
us...@infra.apache.org




[GitHub] [hudi] hddong commented on a change in pull request #2325: [HUDI-699]Fix CompactionCommand and add unit test for CompactionCommand

2021-02-04 Thread GitBox


hddong commented on a change in pull request #2325:
URL: https://github.com/apache/hudi/pull/2325#discussion_r570082278



##
File path: 
hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestCommitsCommand.java
##
@@ -194,7 +194,7 @@ public void testShowArchivedCommits() throws Exception {
 // archived 101 and 102 instants, remove 103 and 104 instant
 data.remove("103");
 data.remove("104");
-String expected = generateExpectData(3, data);
+String expected = generateExpectData(1, data);

Review comment:
   > Why do we need to change this?
   
   
https://github.com/apache/hudi/blob/647e9faf255b9ae5796f513d13c769a8c87788d4/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieArchivedTimeline.java#L133
   
   
https://github.com/apache/hudi/blob/647e9faf255b9ae5796f513d13c769a8c87788d4/hudi-common/src/main/java/org/apache/hudi/common/table/timeline/HoodieInstant.java#L103-L108
   
   `new HoodieInstant(false, action, instantTime)` always return `COMPLETED` 
when State is not `INFLIGHT`, so there is 3 `COMPLETED` records for one 
instanct. Now, use the real state instead, and can get the correct number.





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:
us...@infra.apache.org