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 2020/04/16 07:47:25 UTC

[GitHub] [incubator-hudi] hddong opened a new pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

hddong opened a new pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand
URL: https://github.com/apache/incubator-hudi/pull/1522
 
 
   ## *Tips*
   - *Thank you very much for contributing to Apache Hudi.*
   - *Please review https://hudi.apache.org/contributing.html before opening a pull request.*
   
   ## What is the purpose of the pull request
   
   *Add unit test for HoodieLogFileCommand*
   
   ## Brief change log
   
   *(for example:)*
     - *Add unit test for HoodieLogFileCommand*
   
   ## Verify this pull request
   
   This pull request is a trivial rework / code cleanup without any test coverage.
   
   ## Committer checklist
   
    - [ ] Has a corresponding JIRA in PR title & commit
    
    - [ ] Commit message is descriptive of the change
    
    - [ ] CI is green
   
    - [ ] Necessary doc changes done or have another open PR
          
    - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA.

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


With regards,
Apache Git Services

[GitHub] [incubator-hudi] yanghua commented on pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
yanghua commented on pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#issuecomment-619662637


   @hddong Travis is red.


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



[GitHub] [incubator-hudi] codecov-io commented on pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#issuecomment-619698060


   # [Codecov](https://codecov.io/gh/apache/incubator-hudi/pull/1522?src=pr&el=h1) Report
   > Merging [#1522](https://codecov.io/gh/apache/incubator-hudi/pull/1522?src=pr&el=desc) into [master](https://codecov.io/gh/apache/incubator-hudi/commit/14d4fea8339913c0df8ea829036a45a187c55208&el=desc) will **decrease** coverage by `0.36%`.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-hudi/pull/1522/graphs/tree.svg?width=650&height=150&src=pr&token=VTTXabwbs2)](https://codecov.io/gh/apache/incubator-hudi/pull/1522?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #1522      +/-   ##
   ============================================
   - Coverage     72.19%   71.82%   -0.37%     
     Complexity      294      294              
   ============================================
     Files           373      383      +10     
     Lines         16282    16549     +267     
     Branches       1638     1663      +25     
   ============================================
   + Hits          11754    11887     +133     
   - Misses         3792     3930     +138     
   + Partials        736      732       -4     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-hudi/pull/1522?src=pr&el=tree) | Coverage Δ | Complexity Δ | |
   |---|---|---|---|
   | [...di/hadoop/realtime/HoodieRealtimeRecordReader.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1oYWRvb3AtbXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvaGFkb29wL3JlYWx0aW1lL0hvb2RpZVJlYWx0aW1lUmVjb3JkUmVhZGVyLmphdmE=) | `70.00% <0.00%> (-14.22%)` | `0.00% <0.00%> (ø%)` | |
   | [...ache/hudi/common/fs/inline/InMemoryFileSystem.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvY29tbW9uL2ZzL2lubGluZS9Jbk1lbW9yeUZpbGVTeXN0ZW0uamF2YQ==) | `79.31% <0.00%> (-10.35%)` | `0.00% <0.00%> (ø%)` | |
   | [...ain/java/org/apache/hudi/avro/HoodieAvroUtils.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvYXZyby9Ib29kaWVBdnJvVXRpbHMuamF2YQ==) | `84.82% <0.00%> (-7.18%)` | `0.00% <0.00%> (ø%)` | |
   | [...src/main/java/org/apache/hudi/metrics/Metrics.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1jbGllbnQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvbWV0cmljcy9NZXRyaWNzLmphdmE=) | `67.56% <0.00%> (-4.66%)` | `0.00% <0.00%> (ø%)` | |
   | [...g/apache/hudi/table/action/clean/CleanPlanner.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1jbGllbnQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvdGFibGUvYWN0aW9uL2NsZWFuL0NsZWFuUGxhbm5lci5qYXZh) | `87.50% <0.00%> (-2.25%)` | `0.00% <0.00%> (ø%)` | |
   | [...i/common/table/timeline/TimelineMetadataUtils.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvY29tbW9uL3RhYmxlL3RpbWVsaW5lL1RpbWVsaW5lTWV0YWRhdGFVdGlscy5qYXZh) | `93.02% <0.00%> (-2.22%)` | `0.00% <0.00%> (ø%)` | |
   | [...pache/hudi/common/table/HoodieTableMetaClient.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvY29tbW9uL3RhYmxlL0hvb2RpZVRhYmxlTWV0YUNsaWVudC5qYXZh) | `83.11% <0.00%> (-0.65%)` | `0.00% <0.00%> (ø%)` | |
   | [...ain/java/org/apache/hudi/io/HoodieWriteHandle.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1jbGllbnQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvaW8vSG9vZGllV3JpdGVIYW5kbGUuamF2YQ==) | `74.46% <0.00%> (-0.54%)` | `0.00% <0.00%> (ø%)` | |
   | [...i/common/table/timeline/HoodieDefaultTimeline.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvY29tbW9uL3RhYmxlL3RpbWVsaW5lL0hvb2RpZURlZmF1bHRUaW1lbGluZS5qYXZh) | `92.30% <0.00%> (-0.12%)` | `0.00% <0.00%> (ø%)` | |
   | [...in/java/org/apache/hudi/io/HoodieAppendHandle.java](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree#diff-aHVkaS1jbGllbnQvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1ZGkvaW8vSG9vZGllQXBwZW5kSGFuZGxlLmphdmE=) | `84.17% <0.00%> (ø)` | `0.00% <0.00%> (ø%)` | |
   | ... and [67 more](https://codecov.io/gh/apache/incubator-hudi/pull/1522/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-hudi/pull/1522?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-hudi/pull/1522?src=pr&el=footer). Last update [14d4fea...f721c67](https://codecov.io/gh/apache/incubator-hudi/pull/1522?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


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



[GitHub] [incubator-hudi] yanghua commented on a change in pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#discussion_r416721786



##########
File path: hudi-cli/src/main/java/org/apache/hudi/cli/commands/HoodieLogFileCommand.java
##########
@@ -173,7 +176,11 @@ public String showLogFileRecords(
     HoodieTableMetaClient client = HoodieCLI.getTableMetaClient();
     FileSystem fs = client.getFs();
     List<String> logFilePaths = Arrays.stream(fs.globStatus(new Path(logFilePathPattern)))
-        .map(status -> status.getPath().toString()).collect(Collectors.toList());
+        .map(status -> status.getPath().toString()).sorted(Comparator.reverseOrder())

Review comment:
       Got it! Github hid the unchanged part. I thought you only accessed the `.size()` method.




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



[GitHub] [incubator-hudi] hddong commented on pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
hddong commented on pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#issuecomment-619562775


   @yanghua Thanks for you review and comments.


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



[GitHub] [incubator-hudi] yanghua commented on a change in pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#discussion_r416402996



##########
File path: hudi-cli/src/main/java/org/apache/hudi/cli/commands/HoodieLogFileCommand.java
##########
@@ -173,7 +176,11 @@ public String showLogFileRecords(
     HoodieTableMetaClient client = HoodieCLI.getTableMetaClient();
     FileSystem fs = client.getFs();
     List<String> logFilePaths = Arrays.stream(fs.globStatus(new Path(logFilePathPattern)))
-        .map(status -> status.getPath().toString()).collect(Collectors.toList());
+        .map(status -> status.getPath().toString()).sorted(Comparator.reverseOrder())

Review comment:
       Do we need to sort this data set?

##########
File path: hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestHoodieLogFileCommand.java
##########
@@ -0,0 +1,218 @@
+/*
+ * 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 com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.cli.AbstractShellIntegrationTest;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodieTableHeaderFields;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.common.HoodieTestCommitMetadataGenerator;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.log.HoodieLogFormat;
+import org.apache.hudi.common.table.log.HoodieMergedLogRecordScanner;
+import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
+import org.apache.hudi.common.table.log.block.HoodieLogBlock;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieMemoryConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.SchemaTestUtil.getSimpleSchema;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test Cases for {@link HoodieLogFileCommand}.
+ */
+public class TestHoodieLogFileCommand extends AbstractShellIntegrationTest {
+
+  private String partitionPath;
+  private HoodieAvroDataBlock dataBlock;
+  private String tablePath;
+
+  private static final String INSTANT_TIME = "100";
+
+  @Before
+  public void init() throws IOException, InterruptedException, URISyntaxException {
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+
+    // Create table and connect
+    String tableName = "test_table";
+    tablePath = basePath + File.separator + tableName;
+    partitionPath = tablePath + File.separator + HoodieTestCommitMetadataGenerator.DEFAULT_FIRST_PARTITION_PATH;
+    new TableCommand().createTable(
+        tablePath, tableName, HoodieTableType.MERGE_ON_READ.name(),
+        "", TimelineLayoutVersion.VERSION_1, "org.apache.hudi.common.model.HoodieAvroPayload");
+
+    new File(partitionPath).mkdirs();
+
+    HoodieLogFormat.Writer writer = null;
+    try {
+      writer =
+          HoodieLogFormat.newWriterBuilder().onParentPath(new Path(partitionPath))
+              .withFileExtension(HoodieLogFile.DELTA_EXTENSION)
+              .withFileId("test-log-fileid1").overBaseCommit("100").withFs(fs).build();
+
+      // write data to file
+      List<IndexedRecord> records = SchemaTestUtil.generateTestRecords(0, 100);
+      Map<HoodieLogBlock.HeaderMetadataType, String> header = new HashMap<>();
+      header.put(HoodieLogBlock.HeaderMetadataType.INSTANT_TIME, INSTANT_TIME);
+      header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, getSimpleSchema().toString());
+      dataBlock = new HoodieAvroDataBlock(records, header);
+      writer = writer.appendBlock(dataBlock);
+    } finally {
+      writer.close();

Review comment:
       For avoiding NPE, consider add : 
   ```
   if (writer != null) {
   ```
   ?




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



[GitHub] [incubator-hudi] hddong commented on a change in pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
hddong commented on a change in pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#discussion_r415327225



##########
File path: hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestHoodieLogFileCommand.java
##########
@@ -0,0 +1,210 @@
+/*
+ * 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 com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.cli.AbstractShellIntegrationTest;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodieTableHeaderFields;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.common.HoodieTestCommitMetadataGenerator;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.log.HoodieLogFormat;
+import org.apache.hudi.common.table.log.HoodieMergedLogRecordScanner;
+import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
+import org.apache.hudi.common.table.log.block.HoodieLogBlock;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieMemoryConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.SchemaTestUtil.getSimpleSchema;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test Cases for {@link HoodieLogFileCommand}.
+ */
+public class TestHoodieLogFileCommand extends AbstractShellIntegrationTest {
+
+  private String partitionPath;
+  private HoodieAvroDataBlock dataBlock;
+  private String tablePath;
+
+  private static final String INSTANT_TIME = "100";
+
+  @Before
+  public void init() throws IOException, InterruptedException, URISyntaxException {
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+
+    // Create table and connect
+    String tableName = "test_table";
+    tablePath = basePath + File.separator + tableName;
+    partitionPath = tablePath + File.separator + HoodieTestCommitMetadataGenerator.DEFAULT_FIRST_PARTITION_PATH;
+    new TableCommand().createTable(
+        tablePath, tableName, HoodieTableType.MERGE_ON_READ.name(),
+        "", TimelineLayoutVersion.VERSION_1, "org.apache.hudi.common.model.HoodieAvroPayload");
+
+    new File(partitionPath).mkdirs();
+    HoodieLogFormat.Writer writer =
+        HoodieLogFormat.newWriterBuilder().onParentPath(new Path(partitionPath))
+            .withFileExtension(HoodieLogFile.DELTA_EXTENSION)
+            .withFileId("test-log-fileid1").overBaseCommit("100").withFs(fs).build();
+
+    // write data to file
+    List<IndexedRecord> records = SchemaTestUtil.generateTestRecords(0, 100);
+    Map<HoodieLogBlock.HeaderMetadataType, String> header = new HashMap<>();
+    header.put(HoodieLogBlock.HeaderMetadataType.INSTANT_TIME, INSTANT_TIME);
+    header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, getSimpleSchema().toString());
+    dataBlock = new HoodieAvroDataBlock(records, header);
+    writer = writer.appendBlock(dataBlock);
+    writer.close();

Review comment:
       > We should protect the resource leak here.
   
   `try (resource)` does not work very well here, use `try finally` instead.




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



[GitHub] [incubator-hudi] yanghua commented on a change in pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#discussion_r416723032



##########
File path: hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestHoodieLogFileCommand.java
##########
@@ -0,0 +1,220 @@
+/*
+ * 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 com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.cli.AbstractShellIntegrationTest;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodieTableHeaderFields;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.common.HoodieTestCommitMetadataGenerator;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.log.HoodieLogFormat;
+import org.apache.hudi.common.table.log.HoodieMergedLogRecordScanner;
+import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
+import org.apache.hudi.common.table.log.block.HoodieLogBlock;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieMemoryConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.SchemaTestUtil.getSimpleSchema;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test Cases for {@link HoodieLogFileCommand}.
+ */
+public class TestHoodieLogFileCommand extends AbstractShellIntegrationTest {
+
+  private String partitionPath;
+  private HoodieAvroDataBlock dataBlock;
+  private String tablePath;
+
+  private static final String INSTANT_TIME = "100";
+
+  @Before
+  public void init() throws IOException, InterruptedException, URISyntaxException {
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+
+    // Create table and connect
+    String tableName = "test_table";
+    tablePath = basePath + File.separator + tableName;
+    partitionPath = tablePath + File.separator + HoodieTestCommitMetadataGenerator.DEFAULT_FIRST_PARTITION_PATH;
+    new TableCommand().createTable(
+        tablePath, tableName, HoodieTableType.MERGE_ON_READ.name(),
+        "", TimelineLayoutVersion.VERSION_1, "org.apache.hudi.common.model.HoodieAvroPayload");
+
+    new File(partitionPath).mkdirs();

Review comment:
       Replace it with `Files.createDirectories` is a better choice?

##########
File path: hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestHoodieLogFileCommand.java
##########
@@ -0,0 +1,220 @@
+/*
+ * 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 com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.cli.AbstractShellIntegrationTest;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodieTableHeaderFields;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.common.HoodieTestCommitMetadataGenerator;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.log.HoodieLogFormat;
+import org.apache.hudi.common.table.log.HoodieMergedLogRecordScanner;
+import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
+import org.apache.hudi.common.table.log.block.HoodieLogBlock;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieMemoryConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.SchemaTestUtil.getSimpleSchema;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test Cases for {@link HoodieLogFileCommand}.
+ */
+public class TestHoodieLogFileCommand extends AbstractShellIntegrationTest {
+
+  private String partitionPath;
+  private HoodieAvroDataBlock dataBlock;
+  private String tablePath;
+
+  private static final String INSTANT_TIME = "100";
+
+  @Before
+  public void init() throws IOException, InterruptedException, URISyntaxException {
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+
+    // Create table and connect
+    String tableName = "test_table";
+    tablePath = basePath + File.separator + tableName;
+    partitionPath = tablePath + File.separator + HoodieTestCommitMetadataGenerator.DEFAULT_FIRST_PARTITION_PATH;
+    new TableCommand().createTable(
+        tablePath, tableName, HoodieTableType.MERGE_ON_READ.name(),
+        "", TimelineLayoutVersion.VERSION_1, "org.apache.hudi.common.model.HoodieAvroPayload");
+
+    new File(partitionPath).mkdirs();
+
+    HoodieLogFormat.Writer writer = null;
+    try {
+      writer =
+          HoodieLogFormat.newWriterBuilder().onParentPath(new Path(partitionPath))
+              .withFileExtension(HoodieLogFile.DELTA_EXTENSION)
+              .withFileId("test-log-fileid1").overBaseCommit("100").withFs(fs).build();
+
+      // write data to file
+      List<IndexedRecord> records = SchemaTestUtil.generateTestRecords(0, 100);
+      Map<HoodieLogBlock.HeaderMetadataType, String> header = new HashMap<>();
+      header.put(HoodieLogBlock.HeaderMetadataType.INSTANT_TIME, INSTANT_TIME);
+      header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, getSimpleSchema().toString());
+      dataBlock = new HoodieAvroDataBlock(records, header);
+      writer = writer.appendBlock(dataBlock);
+    } finally {
+      if (writer != null) {
+        writer.close();
+      }
+    }
+  }
+
+  /**
+   * Test case for 'show logfile metadata'.
+   */
+  @Test
+  public void testShowLogFileCommits() throws JsonProcessingException {
+    CommandResult cr = getShell().executeCommand("show logfile metadata --logFilePathPattern " + partitionPath + "/*");
+    assertTrue(cr.isSuccess());
+
+    TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT_TIME)
+        .addTableHeaderField(HoodieTableHeaderFields.HEADER_RECORD_COUNT)
+        .addTableHeaderField(HoodieTableHeaderFields.HEADER_BLOCK_TYPE)
+        .addTableHeaderField(HoodieTableHeaderFields.HEADER_HEADER_METADATA)
+        .addTableHeaderField(HoodieTableHeaderFields.HEADER_FOOTER_METADATA);
+
+    // construct expect result, there is only 1 line.
+    List<Comparable[]> rows = new ArrayList<>();
+    ObjectMapper objectMapper = new ObjectMapper();
+    String headerStr = objectMapper.writeValueAsString(dataBlock.getLogBlockHeader());
+    String footerStr = objectMapper.writeValueAsString(dataBlock.getLogBlockFooter());
+    Comparable[] output = new Comparable[]{INSTANT_TIME, 100, dataBlock.getBlockType(), headerStr, footerStr};
+    rows.add(output);
+
+    String expected = HoodiePrintHelper.print(header, new HashMap<>(), "", false, -1, false, rows);
+
+    assertEquals(expected, cr.getResult().toString());
+  }
+
+  /**
+   * Test case for 'show logfile records'.
+   */
+  @Test
+  public void testShowLogFileRecords() throws IOException, URISyntaxException {
+    CommandResult cr = getShell().executeCommand("show logfile records --logFilePathPattern " + partitionPath + "/*");
+    assertTrue(cr.isSuccess());
+
+    // construct expect result, get 10 records.
+    List<IndexedRecord> records = SchemaTestUtil.generateTestRecords(0, 10);
+    String[][] rows = records.stream().map(r -> new String[]{r.toString()}).toArray(String[][]::new);
+    String expected = HoodiePrintHelper.print(new String[] {HoodieTableHeaderFields.HEADER_RECORDS}, rows);
+
+    assertEquals(expected, cr.getResult().toString());
+  }
+
+  /**
+   * Test case for 'show logfile records' with merge.
+   */
+  @Test
+  public void testShowLogFileRecordsWithMerge() throws IOException, InterruptedException, URISyntaxException {
+    // create commit instant
+    HoodieTestCommitMetadataGenerator.createCommitFile(tablePath, INSTANT_TIME, HoodieCLI.conf);
+
+    // write to path '2015/03/16'.
+    Schema schema = HoodieAvroUtils.addMetadataFields(getSimpleSchema());
+    partitionPath = tablePath + File.separator + HoodieTestCommitMetadataGenerator.DEFAULT_SECOND_PARTITION_PATH;
+    new File(partitionPath).mkdirs();

Review comment:
       ditto




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



[GitHub] [incubator-hudi] hddong commented on pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
hddong commented on pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#issuecomment-619749885


   @yanghua It's green now.  Due to a issue in 
   https://github.com/apache/incubator-hudi/blob/f721c675f8ee25c6f93d9596cc28b02de918ea24/hudi-common/src/main/java/org/apache/hudi/common/table/log/HoodieLogFormatWriter.java#L167-L170
   `rolloverIfNeeded ` always create a blank file at last, and 'show logfile records' get schema from last file which is blank. So read schema from first log file instead. 
   BTW, I will try to fix the issue of the last blank file.


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



[GitHub] [incubator-hudi] hddong commented on a change in pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
hddong commented on a change in pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#discussion_r416482802



##########
File path: hudi-cli/src/main/java/org/apache/hudi/cli/commands/HoodieLogFileCommand.java
##########
@@ -173,7 +176,11 @@ public String showLogFileRecords(
     HoodieTableMetaClient client = HoodieCLI.getTableMetaClient();
     FileSystem fs = client.getFs();
     List<String> logFilePaths = Arrays.stream(fs.globStatus(new Path(logFilePathPattern)))
-        .map(status -> status.getPath().toString()).collect(Collectors.toList());
+        .map(status -> status.getPath().toString()).sorted(Comparator.reverseOrder())

Review comment:
       > Do we need to sort this data set?
   
   IMO, it should be. Default return value is unordered, we may touch the blank log file when `readSchemaFromLogFile`.




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



[GitHub] [incubator-hudi] yanghua commented on a change in pull request #1522: [HUDI-702]Add test for HoodieLogFileCommand

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1522:
URL: https://github.com/apache/incubator-hudi/pull/1522#discussion_r414502524



##########
File path: hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestHoodieLogFileCommand.java
##########
@@ -0,0 +1,210 @@
+/*
+ * 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 com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.cli.AbstractShellIntegrationTest;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodieTableHeaderFields;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.common.HoodieTestCommitMetadataGenerator;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.log.HoodieLogFormat;
+import org.apache.hudi.common.table.log.HoodieMergedLogRecordScanner;
+import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
+import org.apache.hudi.common.table.log.block.HoodieLogBlock;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieMemoryConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.SchemaTestUtil.getSimpleSchema;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test Cases for {@link HoodieLogFileCommand}.
+ */
+public class TestHoodieLogFileCommand extends AbstractShellIntegrationTest {
+
+  private String partitionPath;
+  private HoodieAvroDataBlock dataBlock;
+  private String tablePath;
+
+  private static final String INSTANT_TIME = "100";
+
+  @Before
+  public void init() throws IOException, InterruptedException, URISyntaxException {
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+
+    // Create table and connect
+    String tableName = "test_table";
+    tablePath = basePath + File.separator + tableName;
+    partitionPath = tablePath + File.separator + HoodieTestCommitMetadataGenerator.DEFAULT_FIRST_PARTITION_PATH;
+    new TableCommand().createTable(
+        tablePath, tableName, HoodieTableType.MERGE_ON_READ.name(),
+        "", TimelineLayoutVersion.VERSION_1, "org.apache.hudi.common.model.HoodieAvroPayload");
+
+    new File(partitionPath).mkdirs();
+    HoodieLogFormat.Writer writer =
+        HoodieLogFormat.newWriterBuilder().onParentPath(new Path(partitionPath))
+            .withFileExtension(HoodieLogFile.DELTA_EXTENSION)
+            .withFileId("test-log-fileid1").overBaseCommit("100").withFs(fs).build();
+
+    // write data to file
+    List<IndexedRecord> records = SchemaTestUtil.generateTestRecords(0, 100);
+    Map<HoodieLogBlock.HeaderMetadataType, String> header = new HashMap<>();
+    header.put(HoodieLogBlock.HeaderMetadataType.INSTANT_TIME, INSTANT_TIME);
+    header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, getSimpleSchema().toString());
+    dataBlock = new HoodieAvroDataBlock(records, header);
+    writer = writer.appendBlock(dataBlock);
+    writer.close();

Review comment:
       We should protect the resource leak here.

##########
File path: hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestHoodieLogFileCommand.java
##########
@@ -0,0 +1,210 @@
+/*
+ * 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 com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.IndexedRecord;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.cli.AbstractShellIntegrationTest;
+import org.apache.hudi.cli.HoodieCLI;
+import org.apache.hudi.cli.HoodieTableHeaderFields;
+import org.apache.hudi.cli.HoodiePrintHelper;
+import org.apache.hudi.cli.TableHeader;
+import org.apache.hudi.cli.common.HoodieTestCommitMetadataGenerator;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.model.HoodieTableType;
+import org.apache.hudi.common.table.log.HoodieLogFormat;
+import org.apache.hudi.common.table.log.HoodieMergedLogRecordScanner;
+import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
+import org.apache.hudi.common.table.log.block.HoodieLogBlock;
+import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.SchemaTestUtil;
+import org.apache.hudi.config.HoodieCompactionConfig;
+import org.apache.hudi.config.HoodieMemoryConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.shell.core.CommandResult;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.SchemaTestUtil.getSimpleSchema;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test Cases for {@link HoodieLogFileCommand}.
+ */
+public class TestHoodieLogFileCommand extends AbstractShellIntegrationTest {
+
+  private String partitionPath;
+  private HoodieAvroDataBlock dataBlock;
+  private String tablePath;
+
+  private static final String INSTANT_TIME = "100";
+
+  @Before
+  public void init() throws IOException, InterruptedException, URISyntaxException {
+    HoodieCLI.conf = jsc.hadoopConfiguration();
+
+    // Create table and connect
+    String tableName = "test_table";
+    tablePath = basePath + File.separator + tableName;
+    partitionPath = tablePath + File.separator + HoodieTestCommitMetadataGenerator.DEFAULT_FIRST_PARTITION_PATH;
+    new TableCommand().createTable(
+        tablePath, tableName, HoodieTableType.MERGE_ON_READ.name(),
+        "", TimelineLayoutVersion.VERSION_1, "org.apache.hudi.common.model.HoodieAvroPayload");
+
+    new File(partitionPath).mkdirs();
+    HoodieLogFormat.Writer writer =
+        HoodieLogFormat.newWriterBuilder().onParentPath(new Path(partitionPath))
+            .withFileExtension(HoodieLogFile.DELTA_EXTENSION)
+            .withFileId("test-log-fileid1").overBaseCommit("100").withFs(fs).build();
+
+    // write data to file
+    List<IndexedRecord> records = SchemaTestUtil.generateTestRecords(0, 100);
+    Map<HoodieLogBlock.HeaderMetadataType, String> header = new HashMap<>();
+    header.put(HoodieLogBlock.HeaderMetadataType.INSTANT_TIME, INSTANT_TIME);
+    header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, getSimpleSchema().toString());
+    dataBlock = new HoodieAvroDataBlock(records, header);
+    writer = writer.appendBlock(dataBlock);
+    writer.close();
+  }
+
+  /**
+   * Test case for 'show logfile metadata'.
+   */
+  @Test
+  public void testShowLogFileCommits() throws JsonProcessingException {
+    CommandResult cr = getShell().executeCommand("show logfile metadata --logFilePathPattern " + partitionPath + "/*");
+    assertTrue(cr.isSuccess());
+
+    TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT_TIME)
+        .addTableHeaderField(HoodieTableHeaderFields.HEADER_RECORD_COUNT)
+        .addTableHeaderField(HoodieTableHeaderFields.HEADER_BLOCK_TYPE)
+        .addTableHeaderField(HoodieTableHeaderFields.HEADER_HEADER_METADATA)
+        .addTableHeaderField(HoodieTableHeaderFields.HEADER_FOOTER_METADATA);
+
+    // construct expect result, there is only 1 line.
+    List<Comparable[]> rows = new ArrayList<>();
+    ObjectMapper objectMapper = new ObjectMapper();
+    String headerStr = objectMapper.writeValueAsString(dataBlock.getLogBlockHeader());
+    String footerStr = objectMapper.writeValueAsString(dataBlock.getLogBlockFooter());
+    Comparable[] output = new Comparable[]{INSTANT_TIME, 100, dataBlock.getBlockType(), headerStr, footerStr};
+    rows.add(output);
+
+    String expected = HoodiePrintHelper.print(header, new HashMap<>(), "", false, -1, false, rows);
+
+    assertEquals(expected, cr.getResult().toString());
+  }
+
+  /**
+   * Test case for 'show logfile records'.
+   */
+  @Test
+  public void testShowLogFileRecords() throws IOException, URISyntaxException {
+    CommandResult cr = getShell().executeCommand("show logfile records --logFilePathPattern " + partitionPath + "/*");
+    assertTrue(cr.isSuccess());
+
+    // construct expect result, get 10 records.
+    List<IndexedRecord> records = SchemaTestUtil.generateTestRecords(0, 10);
+    String[][] rows = records.stream().map(r -> new String[]{r.toString()}).toArray(String[][]::new);
+    String expected = HoodiePrintHelper.print(new String[] {HoodieTableHeaderFields.HEADER_RECORDS}, rows);
+
+    assertEquals(expected, cr.getResult().toString());
+  }
+
+  /**
+   * Test case for 'show logfile records' with merge.
+   */
+  @Test
+  public void testShowLogFileRecordsWithMerge() throws IOException, URISyntaxException, InterruptedException {
+    // create commit instant
+    HoodieTestCommitMetadataGenerator.createCommitFile(tablePath, INSTANT_TIME, HoodieCLI.conf);
+
+    // write to path '2015/03/16'.
+    Schema schema = HoodieAvroUtils.addMetadataFields(getSimpleSchema());
+    partitionPath = tablePath + File.separator + HoodieTestCommitMetadataGenerator.DEFAULT_SECOND_PARTITION_PATH;
+    new File(partitionPath).mkdirs();
+
+    // set little threshold to split file.
+    HoodieLogFormat.Writer writer =
+        HoodieLogFormat.newWriterBuilder().onParentPath(new Path(partitionPath))
+            .withFileExtension(HoodieLogFile.DELTA_EXTENSION)
+            .withFileId("test-log-fileid1").overBaseCommit(INSTANT_TIME).withFs(fs).withSizeThreshold(500).build();
+
+    //write1
+    List<IndexedRecord> records1 = SchemaTestUtil.generateHoodieTestRecords(0, 100);
+    Map<HoodieLogBlock.HeaderMetadataType, String> header = new HashMap<>();
+    header.put(HoodieLogBlock.HeaderMetadataType.INSTANT_TIME, INSTANT_TIME);
+    header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, schema.toString());
+    HoodieAvroDataBlock dataBlock = new HoodieAvroDataBlock(records1, header);
+    writer = writer.appendBlock(dataBlock);
+
+    //write2
+    List<IndexedRecord> records2 = SchemaTestUtil.generateHoodieTestRecords(0, 100);
+    header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, schema.toString());
+    dataBlock = new HoodieAvroDataBlock(records2, header);
+    writer = writer.appendBlock(dataBlock);
+    writer.close();

Review comment:
       ditto




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