You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@orc.apache.org by GitBox <gi...@apache.org> on 2021/10/20 08:34:28 UTC

[GitHub] [orc] guiyanakuang opened a new pull request #943: ORC-1034: Fix the indexOf algorithm

guiyanakuang opened a new pull request #943:
URL: https://github.com/apache/orc/pull/943


   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If there is a discussion in the mailing list, please add the link.
   -->
   
   This matching algorithm is wrong when i does not backtrack after a failed match in the middle. As a simple example data = OOORC, pattern= ORC, index = 1, this algorithm will return -1.
   
   This pr aims to fix the indexOf algorithm.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   indexOf is used to find the ORC file ending identifier to recover the file, it is important to ensure that the method is correct.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   Add UT.


-- 
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: dev-unsubscribe@orc.apache.org

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



[GitHub] [orc] guiyanakuang commented on a change in pull request #943: ORC-1034: Fix the indexOf algorithm in FileDump.java

Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #943:
URL: https://github.com/apache/orc/pull/943#discussion_r733277252



##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -703,4 +703,12 @@ public void testHasNull() throws Exception {
     assumeTrue(!System.getProperty("os.name").startsWith("Windows"));
     TestFileDump.checkOutput(outputFilename, workDir + File.separator + outputFilename);
   }
+
+  @Test
+  public void testIndexOf() {
+    byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
+    byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
+
+    assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);

Review comment:
       I can fix this issue along with the code conflict in ORC-1030, is this acceptable?




-- 
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: dev-unsubscribe@orc.apache.org

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



[GitHub] [orc] dongjoon-hyun merged pull request #943: ORC-1034: Fix the indexOf algorithm in FileDump.java

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun merged pull request #943:
URL: https://github.com/apache/orc/pull/943


   


-- 
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: dev-unsubscribe@orc.apache.org

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



[GitHub] [orc] dongjoon-hyun commented on a change in pull request #943: ORC-1034: Fix the indexOf algorithm in FileDump.java

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #943:
URL: https://github.com/apache/orc/pull/943#discussion_r733289198



##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -703,4 +703,12 @@ public void testHasNull() throws Exception {
     assumeTrue(!System.getProperty("os.name").startsWith("Windows"));
     TestFileDump.checkOutput(outputFilename, workDir + File.separator + outputFilename);
   }
+
+  @Test
+  public void testIndexOf() {
+    byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
+    byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
+
+    assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);

Review comment:
       In this specific case, +1 for that.




-- 
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: dev-unsubscribe@orc.apache.org

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



[GitHub] [orc] dongjoon-hyun commented on a change in pull request #943: ORC-1034: Fix the indexOf algorithm in FileDump.java

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #943:
URL: https://github.com/apache/orc/pull/943#discussion_r733121428



##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -703,4 +703,12 @@ public void testHasNull() throws Exception {
     assumeTrue(!System.getProperty("os.name").startsWith("Windows"));
     TestFileDump.checkOutput(outputFilename, workDir + File.separator + outputFilename);
   }
+
+  @Test
+  public void testIndexOf() {
+    byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
+    byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
+
+    assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);

Review comment:
       Oh, I missed this has a wrong argument order.
   Please check the argument order next time.
   In this context, `assertEquals` should have the expected value as the first argument.




-- 
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: dev-unsubscribe@orc.apache.org

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



[GitHub] [orc] guiyanakuang commented on a change in pull request #943: ORC-1034: Fix the indexOf algorithm in FileDump.java

Posted by GitBox <gi...@apache.org>.
guiyanakuang commented on a change in pull request #943:
URL: https://github.com/apache/orc/pull/943#discussion_r733268269



##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -703,4 +703,12 @@ public void testHasNull() throws Exception {
     assumeTrue(!System.getProperty("os.name").startsWith("Windows"));
     TestFileDump.checkOutput(outputFilename, workDir + File.separator + outputFilename);
   }
+
+  @Test
+  public void testIndexOf() {
+    byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
+    byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
+
+    assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);

Review comment:
       You're right, I didn't realize for a long time that the order of the arguments would affect the prompt message




-- 
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: dev-unsubscribe@orc.apache.org

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



[GitHub] [orc] dongjoon-hyun commented on a change in pull request #943: ORC-1034: Fix the indexOf algorithm in FileDump.java

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #943:
URL: https://github.com/apache/orc/pull/943#discussion_r733126258



##########
File path: java/tools/src/test/org/apache/orc/tools/TestFileDump.java
##########
@@ -703,4 +703,12 @@ public void testHasNull() throws Exception {
     assumeTrue(!System.getProperty("os.name").startsWith("Windows"));
     TestFileDump.checkOutput(outputFilename, workDir + File.separator + outputFilename);
   }
+
+  @Test
+  public void testIndexOf() {
+    byte[] bytes = ("OO" + OrcFile.MAGIC).getBytes(StandardCharsets.UTF_8);
+    byte[] pattern = OrcFile.MAGIC.getBytes(StandardCharsets.UTF_8);
+
+    assertEquals(FileDump.indexOf(bytes, pattern, 1), 2);

Review comment:
       FYI, I fixed during backporting to branch-1.7/1.6, @guiyanakuang .




-- 
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: dev-unsubscribe@orc.apache.org

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