Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-10962: [FlightRPC][Java] fill in empty body buffer if needed #8963

Closed
wants to merge 1 commit into from

Conversation

lidavidm
Copy link
Member

Fixes compatibility with standard Protobuf implementations, which may omit serialization of an empty field. In the case of an empty record batch, this would cause the Java client to fail a precondition check since there would be no body buffer instead of a single empty body buffer.

@github-actions
Copy link

@alamb
Copy link
Contributor

alamb commented Dec 31, 2020

Requesting review from @praveenbingo and @liyafan82 as they seem to have merged the last few Java PRs into the arrow repo.

The background here is that we are working on flight integration tests in Rust (e.g. #9049) and we found an edge case in the flight protobuf integration.

@liyafan82
Copy link
Contributor

Sorry for my late response. Will take a look late today.

@@ -317,6 +325,39 @@ private void test(BiConsumer<FlightClient, BufferAllocator> consumer) throws Exc
}
}

/** ARROW-10939: accept FlightData messages generated by Protobuf (which can omit empty fields). */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10939 -> 10962?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed.

@@ -317,6 +325,39 @@ private void test(BiConsumer<FlightClient, BufferAllocator> consumer) throws Exc
}
}

/** ARROW-10939: accept FlightData messages generated by Protobuf (which can omit empty fields). */
@Test
public void testProtobufCompat() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compat -> Compact?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded to 'compatibility'

final ArrowRecordBatch rb =
marshaller.parse(new ByteArrayInputStream(protobufData.toByteArray())).asRecordBatch();
Assert.assertEquals(rb.computeBodyLength(), 0);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do you think we also need a test case for which a schema has an empty body?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I added a test for this as well.

.build();
Assert.assertEquals(0, protobufData.getDataBody().size());
// Should not throw
marshaller.parse(new ByteArrayInputStream(protobufData.toByteArray())).asSchema();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to assign the schema to an object and verify that its body is null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema itself has no body. I've added a test to check the parsed message.

Flight.FlightDescriptor descriptor = FlightDescriptor.command(new byte[0]).toProtocol();
try (final ArrowMessage message = new ArrowMessage(descriptor, schema, new IpcOption())) {
Assert.assertEquals(ArrowMessage.HeaderType.SCHEMA, message.getMessageType());
try (final InputStream serialized = marshaller.stream(message)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can extract a common method for the logic of writing the message to a ByteArrayOutputStream?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

final MethodDescriptor.Marshaller<ArrowMessage> marshaller = ArrowMessage.createMarshaller(allocator);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
Flight.FlightDescriptor descriptor = FlightDescriptor.command(new byte[0]).toProtocol();
try (final ArrowMessage message = new ArrowMessage(descriptor, schema, new IpcOption())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check the message body here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added assertions here.

Copy link
Contributor

@liyafan82 liyafan82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will merge soon if there are no more comments.

@alamb
Copy link
Contributor

alamb commented Jan 7, 2021

#9049 is still blocked on getting this PR merged. Any chance you can do so @liyafan82 ?

@liyafan82
Copy link
Contributor

Merging. Thanks for your effort. @lidavidm @alamb

@liyafan82 liyafan82 closed this in 6b85f6e Jan 8, 2021
@alamb
Copy link
Contributor

alamb commented Jan 8, 2021

🎉 thanks @liyafan82 -- I didn't do anything, it was all @lidavidm . Thanks @lidavidm for the efforts!

nevi-me pushed a commit that referenced this pull request Jan 9, 2021
This PR has a few refactorings and then the main commit contains a new Flight integration test client and server 🎉

The middleware scenario tests are currently skipped because they will fail until `tonic` can be updated to a version containing [a fix having to do with trailers](hyperium/tonic#510); this is tracked in [ARROW-10961](https://issues.apache.org/jira/browse/ARROW-10961).

Some Rust <-> Java integration tests will fail until [this PR is merged](#8963); I'm happy to rebase once that goes in, but I wanted to get code review started on this. Thank you!!

Closes #9049 from carols10cents/rust-flight-integration

Lead-authored-by: Carol (Nichols || Goulding) <carol.nichols@gmail.com>
Co-authored-by: Jake Goulding <jake.goulding@gmail.com>
Signed-off-by: Neville Dipale <nevilledips@gmail.com>
alamb pushed a commit to apache/arrow-rs that referenced this pull request Apr 20, 2021
This PR has a few refactorings and then the main commit contains a new Flight integration test client and server 🎉

The middleware scenario tests are currently skipped because they will fail until `tonic` can be updated to a version containing [a fix having to do with trailers](hyperium/tonic#510); this is tracked in [ARROW-10961](https://issues.apache.org/jira/browse/ARROW-10961).

Some Rust <-> Java integration tests will fail until [this PR is merged](apache/arrow#8963); I'm happy to rebase once that goes in, but I wanted to get code review started on this. Thank you!!

Closes #9049 from carols10cents/rust-flight-integration

Lead-authored-by: Carol (Nichols || Goulding) <carol.nichols@gmail.com>
Co-authored-by: Jake Goulding <jake.goulding@gmail.com>
Signed-off-by: Neville Dipale <nevilledips@gmail.com>
GeorgeAp pushed a commit to sirensolutions/arrow that referenced this pull request Jun 7, 2021
Fixes compatibility with standard Protobuf implementations, which may omit serialization of an empty field. In the case of an empty record batch, this would cause the Java client to fail a precondition check since there would be no body buffer instead of a single empty body buffer.

Closes apache#8963 from lidavidm/arrow-10962

Authored-by: David Li <li.davidm96@gmail.com>
Signed-off-by: liyafan82 <fan_li_ya@foxmail.com>
GeorgeAp pushed a commit to sirensolutions/arrow that referenced this pull request Jun 7, 2021
This PR has a few refactorings and then the main commit contains a new Flight integration test client and server 🎉

The middleware scenario tests are currently skipped because they will fail until `tonic` can be updated to a version containing [a fix having to do with trailers](hyperium/tonic#510); this is tracked in [ARROW-10961](https://issues.apache.org/jira/browse/ARROW-10961).

Some Rust <-> Java integration tests will fail until [this PR is merged](apache#8963); I'm happy to rebase once that goes in, but I wanted to get code review started on this. Thank you!!

Closes apache#9049 from carols10cents/rust-flight-integration

Lead-authored-by: Carol (Nichols || Goulding) <carol.nichols@gmail.com>
Co-authored-by: Jake Goulding <jake.goulding@gmail.com>
Signed-off-by: Neville Dipale <nevilledips@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants