You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@parquet.apache.org by GitBox <gi...@apache.org> on 2020/10/01 17:00:12 UTC

[GitHub] [parquet-mr] dossett opened a new pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

dossett opened a new pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820


   https://issues.apache.org/jira/browse/PARQUET-1917
   
   ### Jira
   
   - [X] My PR addresses the following [Parquet Jira](https://issues.apache.org/jira/browse/PARQUET-1917/) issues and references them in the PR title. 
   
   ### Tests
   
   - [X] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason:
   
   ### Commits
   
   - [X] My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [X] In case of new functionality, my PR adds documentation that describes how to use it.
     - All the public functions and the classes in the PR contain Javadoc that explain what it does
   


----------------------------------------------------------------
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] [parquet-mr] dossett closed pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
dossett closed pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820


   


----------------------------------------------------------------
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] [parquet-mr] gszadovszky merged pull request #820: PARQUET-1917: Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
gszadovszky merged pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820


   


----------------------------------------------------------------
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] [parquet-mr] belugabehr commented on pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
belugabehr commented on pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#issuecomment-702238058


   Please add a test for setting field 1 and not setting field 2.  Since setting the fields should reset the values for all other fields in the 'oneof' field, it could be possible that field 2, set to '0', would clear the value of the first field.  If it just so happens that Parquet is loading the fields in the order they are defined, field 2 would be last and would overwrite all the previous values, so we don't really understand here what is happening to those fields.


----------------------------------------------------------------
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] [parquet-mr] dossett commented on pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
dossett commented on pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#issuecomment-702269675


   Great feedback as always @belugabehr !


----------------------------------------------------------------
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] [parquet-mr] belugabehr commented on pull request #820: PARQUET-1917: Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
belugabehr commented on pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#issuecomment-714550284


   I looked at the unit test again, it's fine as-is.  +1
   
   Thanks.


----------------------------------------------------------------
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] [parquet-mr] dossett commented on pull request #820: PARQUET-1917: Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
dossett commented on pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#issuecomment-714553061


   Thank you both!


----------------------------------------------------------------
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] [parquet-mr] dossett commented on a change in pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
dossett commented on a change in pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#discussion_r498251359



##########
File path: parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java
##########
@@ -337,6 +337,12 @@ private void writeAllFields(MessageOrBuilder pb) {
         List<FieldDescriptor> fieldDescriptors = messageDescriptor.getFields();
         for (FieldDescriptor fieldDescriptor : fieldDescriptors) {
           FieldDescriptor.Type type = fieldDescriptor.getType();
+
+          //For a field in a oneOf that isn't set don't write anything
+          if (fieldDescriptor.getContainingOneof() != null && !pb.hasField(fieldDescriptor)) {
+            continue;
+          }

Review comment:
       To be clear, I will try to add tests for this to my PR.




----------------------------------------------------------------
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] [parquet-mr] belugabehr commented on a change in pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#discussion_r497642803



##########
File path: parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java
##########
@@ -337,6 +337,12 @@ private void writeAllFields(MessageOrBuilder pb) {
         List<FieldDescriptor> fieldDescriptors = messageDescriptor.getFields();
         for (FieldDescriptor fieldDescriptor : fieldDescriptors) {
           FieldDescriptor.Type type = fieldDescriptor.getType();
+
+          //For a field in a oneOf that isn't set don't write anything
+          if (fieldDescriptor.getContainingOneof() != null && !pb.hasField(fieldDescriptor)) {
+            continue;
+          }

Review comment:
       What about the read side?  Is there going to be any issue there?  Currently a value is always written, so there is a value to read.  Now that value is missing.




----------------------------------------------------------------
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] [parquet-mr] belugabehr commented on a change in pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#discussion_r497642803



##########
File path: parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java
##########
@@ -337,6 +337,12 @@ private void writeAllFields(MessageOrBuilder pb) {
         List<FieldDescriptor> fieldDescriptors = messageDescriptor.getFields();
         for (FieldDescriptor fieldDescriptor : fieldDescriptors) {
           FieldDescriptor.Type type = fieldDescriptor.getType();
+
+          //For a field in a oneOf that isn't set don't write anything
+          if (fieldDescriptor.getContainingOneof() != null && !pb.hasField(fieldDescriptor)) {
+            continue;
+          }

Review comment:
       What about the read side?  Is there going to be any issue there?  Currently a value is always written, so there is always a value to read.  With this change, the value is not written.  Can the read-side handle this?




----------------------------------------------------------------
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] [parquet-mr] gszadovszky commented on pull request #820: PARQUET-1917: Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#issuecomment-714544732


   @dossett, it looks good to me. Let me wait for @belugabehr's approval then I'll approve and push this.


----------------------------------------------------------------
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] [parquet-mr] dossett commented on a change in pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
dossett commented on a change in pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#discussion_r496959400



##########
File path: parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java
##########
@@ -337,6 +337,12 @@ private void writeAllFields(MessageOrBuilder pb) {
         List<FieldDescriptor> fieldDescriptors = messageDescriptor.getFields();
         for (FieldDescriptor fieldDescriptor : fieldDescriptors) {
           FieldDescriptor.Type type = fieldDescriptor.getType();
+
+          //For a field in a oneOf that isn't set don't write anything
+          if (fieldDescriptor.getContainingOneof() != null && !pb.hasField(fieldDescriptor)) {
+            continue;
+          }

Review comment:
       Maybe this approach is too simplistic, but it does seem like exactly the behavior 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:
users@infra.apache.org



[GitHub] [parquet-mr] belugabehr edited a comment on pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
belugabehr edited a comment on pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#issuecomment-702238058


   Please add a test for setting field 1 and not setting field 2.  Since setting the fields should reset the values for all other fields in the 'oneof' field, it could be possible that field 2, set to '0', would clear the value of the first field.  If it just so happens that Parquet is loading the fields in the order they are defined, field 2 would be last and would overwrite all the previous values, and work simply because it is last.  Need a test to demonstrate that the previous fields are not accidentally being cleared by 'null' values that come in later.


----------------------------------------------------------------
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] [parquet-mr] belugabehr commented on pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
belugabehr commented on pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#issuecomment-702232630


   Thanks for the collaboration here.
   
   For the unit tests you are using Java 'assert' functions.  It is required to use the JUnit Assert methods (look at other tests for reference).
   
   


----------------------------------------------------------------
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] [parquet-mr] dossett commented on a change in pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
dossett commented on a change in pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#discussion_r498250403



##########
File path: parquet-protobuf/src/main/java/org/apache/parquet/proto/ProtoWriteSupport.java
##########
@@ -337,6 +337,12 @@ private void writeAllFields(MessageOrBuilder pb) {
         List<FieldDescriptor> fieldDescriptors = messageDescriptor.getFields();
         for (FieldDescriptor fieldDescriptor : fieldDescriptors) {
           FieldDescriptor.Type type = fieldDescriptor.getType();
+
+          //For a field in a oneOf that isn't set don't write anything
+          if (fieldDescriptor.getContainingOneof() != null && !pb.hasField(fieldDescriptor)) {
+            continue;
+          }

Review comment:
       @belugabehr That's a great question.  Everything seems ok when I tested it out locally. I wrote some data out to a parquet file with this change, read the data back into protobuf messages, and then wrote the data back to a second parquet file.  The two parquet files were identical, so everything round tripped successfully.  
   
   I am struggling a bit to write unit tests for this case, but that's probably me getting up the parquet API learning curve.




----------------------------------------------------------------
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] [parquet-mr] dossett commented on pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
dossett commented on pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#issuecomment-714526665


   @gszadovszky Tagging you on this PR per discussion in the dev list.  If you approve the change I will also clean up the new tests a bit per David's comments.  Thanks!


----------------------------------------------------------------
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] [parquet-mr] belugabehr commented on a change in pull request #820: PARQUET-1917 Don't write values for oneOf fields that aren't set

Posted by GitBox <gi...@apache.org>.
belugabehr commented on a change in pull request #820:
URL: https://github.com/apache/parquet-mr/pull/820#discussion_r498818951



##########
File path: parquet-protobuf/src/test/java/org/apache/parquet/proto/ProtoWriteSupportTest.java
##########
@@ -913,4 +918,62 @@ public void testMessageWithExtensions() throws Exception {
 
     instance.write(msg.build());
   }
+
+  @Test
+  public void testMessageOneOf() {
+    RecordConsumer readConsumerMock =  Mockito.mock(RecordConsumer.class);
+    ProtoWriteSupport<TestProto3.OneOfTestMessage> spyWriter = createReadConsumerInstance(TestProto3.OneOfTestMessage.class, readConsumerMock);
+    final int theInt = 99;
+
+    TestProto3.OneOfTestMessage.Builder msg = TestProto3.OneOfTestMessage.newBuilder();
+    msg.setSecond(theInt);
+    spyWriter.write(msg.build());
+
+    InOrder inOrder = Mockito.inOrder(readConsumerMock);
+
+    inOrder.verify(readConsumerMock).startMessage();
+    inOrder.verify(readConsumerMock).startField("second", 1);
+    inOrder.verify(readConsumerMock).addInteger(theInt);
+    inOrder.verify(readConsumerMock).endField("second", 1);
+    inOrder.verify(readConsumerMock).endMessage();
+    Mockito.verifyNoMoreInteractions(readConsumerMock);
+  }
+
+  /**
+   * Ensure that a message with a oneOf gets written out correctly and can be
+   * read back as expected.
+   */
+  @Test
+  public void testMessageOneOfRoundTrip() throws IOException {
+
+    TestProto3.OneOfTestMessage.Builder msgBuilder = TestProto3.OneOfTestMessage.newBuilder();
+    msgBuilder.setSecond(99);
+    TestProto3.OneOfTestMessage theMessage = msgBuilder.build();
+
+    TestProto3.OneOfTestMessage.Builder msgBuilder2 = TestProto3.OneOfTestMessage.newBuilder();
+    TestProto3.OneOfTestMessage theMessageNothingSet = msgBuilder2.build();
+
+    TestProto3.OneOfTestMessage.Builder msgBuilder3 = TestProto3.OneOfTestMessage.newBuilder();
+    msgBuilder3.setFirst(42);
+    TestProto3.OneOfTestMessage theMessageFirstSet = msgBuilder3.build();
+
+    //Write them out and read them back
+    Path tmpFilePath = TestUtils.writeMessages(theMessage, theMessageNothingSet, theMessageFirstSet);
+    List<TestProto3.OneOfTestMessage> gotBack = TestUtils.readMessages(tmpFilePath, TestProto3.OneOfTestMessage.class);
+
+    //First message

Review comment:
       Bit of a nit here, but if you find yourself putting in comments like "this is test 1, this is test 2, this is test 3, etc." that is a clear sign that you need to break the test into multiple test methods.
   
   If a test fails, it will be much easier to figure out exactly what broke instead of having to step through all this code.  It also ensure that the tests are testing what is intended and that there aren't any side-effects/artifacts of the other test scenarios interfering.




----------------------------------------------------------------
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