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

Implement FlightSQL spec change to support stateless prepared statements #5433

Conversation

erratic-pattern
Copy link
Contributor

@erratic-pattern erratic-pattern commented Feb 26, 2024

implements client changes for stateless management of FlightSQL prepared statement handles based on the design proposal described in apache/arrow#37720

@github-actions github-actions bot added arrow Changes to the arrow crate arrow-flight Changes to the arrow-flight crate labels Feb 26, 2024
@erratic-pattern erratic-pattern marked this pull request as ready for review February 28, 2024 20:47
@tustvold
Copy link
Contributor

Marking as draft as my understanding of the status of apache/arrow#37720 is that it is a protocol proposal that has yet to go through a mailing list approval process.

Feel free to unmark as a draft if I am mistaken here.

@tustvold tustvold marked this pull request as draft February 29, 2024 02:36
@erratic-pattern
Copy link
Contributor Author

Marking as draft as my understanding of the status of apache/arrow#37720 is that it is a protocol proposal that has yet to go through a mailing list approval process.

Feel free to unmark as a draft if I am mistaken here.

That's fair. I just marked it as ready to indicate that it's ready for review, but it does still need to undergo the formal spec change process. These PRs are intended to serve as conversation starters around specific implementation details of the spec change.

@tustvold
Copy link
Contributor

👍 I just wanted to avoid this accidentally getting merged early

@erratic-pattern erratic-pattern changed the title feat: stateless FlightSQL prepared statements Implement FlightSQL spec change to support stateless prepared statements Mar 1, 2024
@alamb
Copy link
Contributor

alamb commented Mar 3, 2024

Mailing list discussion thread: https://lists.apache.org/thread/3kb82ypx99q96g84qv555l6x8r0bppyq

@alamb alamb added the api-change Changes to the arrow API label Mar 3, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @erratic-pattern -- I think this is looking quite good. I had some questions about the API design, but otherwise 👍

.map_err(status_to_arrow_error)?
.unwrap();
// Attempt to update the stored handle with any updated handle in the DoPut result.
// Not all servers support this, so ignore any errors when attempting to decode.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might silently ignore legitimate errors and I think it would be a good way to distinguish between a server not sending a response vs sending an invalid response.

If the server doesn't support sending back an updated handle, the put_results should be empty, right? So perhaps we could check for an empty response rather than ignoring the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the logic here to not ignore legitimate errors and instead only look for empty responses instead.

@@ -617,7 +618,7 @@ impl FlightSqlService for FlightSqlServiceImpl {
&self,
_query: CommandPreparedStatementQuery,
_request: Request<PeekableFlightDataStream>,
) -> Result<Response<<Self as FlightService>::DoPutStream>, Status> {
) -> Result<Option<DoPutPreparedStatementResult>, Status> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it the field on DoPutPreparedStatementResult that is optional? It seems like this API would be cleaner and follow the rest of the API if it returned a DoPutPreparedStatementResult (and the client can handle / translate a missing message into a DoPutPreparedStatementResult)?

Suggested change
) -> Result<Option<DoPutPreparedStatementResult>, Status> {
) -> Result<DoPutPreparedStatementResult, Status> {

Or maybe it is important to distinguish between the case where the server didn't send back any message from the case where the server sent back a message with an empty prepared handle?

Copy link
Contributor Author

@erratic-pattern erratic-pattern Mar 4, 2024

Choose a reason for hiding this comment

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

This is a decision of whether or not we want to expressly forbid up-to-date servers from implementing the older version of the spec, even though clients still support it. I went with the more conservative decision of allowing existing implementations to continue doing what they were doing before without any major changes aside from changing their return value to Ok(None). That way they continue with the legacy behavior without being "locked out" of future crate updates.

A counterargument to this would be that it should be trivial for servers to simply return the existing handle so there's no need for this extra layer of backwards compatibility.

arrow-flight/src/sql/server.rs Show resolved Hide resolved
cmd.prepared_statement_handle,
PREPARED_STATEMENT_HANDLE.as_bytes()
);
if self.stateless_prepared_statements {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to do this kind of testing (simulate both stateful and stateless server behavior) in the Go implementation as well, but I am less confident around the Arrow Go test suite and general Go testing practices.

@erratic-pattern erratic-pattern force-pushed the adam/flightsql-stateless-prepared-statements branch from adf8361 to e8067f7 Compare March 10, 2024 18:28
@erratic-pattern erratic-pattern force-pushed the adam/flightsql-stateless-prepared-statements branch from e8067f7 to 3dcbeda Compare March 10, 2024 18:28
@erratic-pattern
Copy link
Contributor Author

TODO: update protobuf docs with latest changes to apache/arrow#40243 once the documentation in that PR has finalized

@alamb alamb marked this pull request as ready for review March 21, 2024 14:02
@alamb alamb marked this pull request as draft March 21, 2024 14:02
@erratic-pattern erratic-pattern marked this pull request as ready for review March 24, 2024 17:07
@erratic-pattern
Copy link
Contributor Author

The proposal for this specification change was approved on the Arrow dev mailing list. See thread here I've moved this PR out of draft status.

alamb added a commit to apache/arrow that referenced this pull request Mar 25, 2024
…ments (#40243)

documents changes for stateless management of FlightSQL prepared
statement handles based on the design proposal described in
#37720

* GitHub Issue: #37720

PRs for language implementations:
* Rust: apache/arrow-rs#5433
* Go: #40311

Mailing list discussion:
https://lists.apache.org/thread/3kb82ypx99q96g84qv555l6x8r0bppyq

---------

Co-authored-by: David Li <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
Co-authored-by: Sutou Kouhei <[email protected]>
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks again @erratic-pattern

Can you double check that the change to FlightSql.proto in this repo is the same as was merged into the arrow repo in apache/arrow#40243 ?

@@ -519,17 +521,37 @@ impl PreparedStatement<Channel> {
.await
.map_err(flight_error_to_arrow_error)?;

self.flight_sql_client
// Attempt to update the stored handle with any updated handle in the DoPut result.
// Not all servers support this, so ignore any errors when attempting to decode.
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment says errors are ignored, but the code doesn't seem to ignore errors. I wonder if I am misreading this or if the comment or code should be updated 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment says errors are ignored, but the code doesn't seem to ignore errors. I wonder if I am misreading this or if the comment or code should be updated 🤔

comments never lie ;)

updated this to explain that we ignore the lack of a response from legacy servers, rather than any error.

@erratic-pattern
Copy link
Contributor Author

I've updated the protobuf docs to match the docs that were merged into arrow here apache/arrow#40243

Let me know if there's anything else left to address.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

LGTM -- thank you very much @erratic-pattern

@alamb alamb merged commit 9a5ea83 into apache:master Mar 26, 2024
12 checks passed
erratic-pattern added a commit to erratic-pattern/arrow-rs that referenced this pull request Mar 28, 2024
…nts (apache#5433)

* feat: stateless FlightSQL prepared statements

* update protobuf and improve legacy behavior

* Update arrow-flight/src/sql/server.rs

Co-authored-by: Andrew Lamb <[email protected]>

* make DoPutPreparedStatenentResult mandatory

* update DoPutPreparedStatementResult docs to match arrow repo

* update comment about legacy server behavior in DoPut

---------

Co-authored-by: Andrew Lamb <[email protected]>
wiedld pushed a commit to wiedld/arrow-rs that referenced this pull request Mar 30, 2024
…nts (apache#5433)

* feat: stateless FlightSQL prepared statements

* update protobuf and improve legacy behavior

* Update arrow-flight/src/sql/server.rs

Co-authored-by: Andrew Lamb <[email protected]>

* make DoPutPreparedStatenentResult mandatory

* update DoPutPreparedStatementResult docs to match arrow repo

* update comment about legacy server behavior in DoPut

---------

Co-authored-by: Andrew Lamb <[email protected]>
erratic-pattern added a commit to erratic-pattern/arrow-rs that referenced this pull request Apr 2, 2024
…nts (apache#5433)

* feat: stateless FlightSQL prepared statements

* update protobuf and improve legacy behavior

* Update arrow-flight/src/sql/server.rs

Co-authored-by: Andrew Lamb <[email protected]>

* make DoPutPreparedStatenentResult mandatory

* update DoPutPreparedStatementResult docs to match arrow repo

* update comment about legacy server behavior in DoPut

---------

Co-authored-by: Andrew Lamb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-change Changes to the arrow API arrow Changes to the arrow crate arrow-flight Changes to the arrow-flight crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants