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

Make it easier to match FlightSQL messages #3874

Closed
alamb opened this issue Mar 16, 2023 · 4 comments · Fixed by #3887
Closed

Make it easier to match FlightSQL messages #3874

alamb opened this issue Mar 16, 2023 · 4 comments · Fixed by #3887
Labels
arrow Changes to the arrow crate arrow-flight Changes to the arrow-flight crate enhancement Any new improvement worthy of a entry in the changelog

Comments

@alamb
Copy link
Contributor

alamb commented Mar 16, 2023

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
When implementing FlightSQL the do_get and get_flight_info gRPC methods are called for several of the message types. Thus those endpoints need to decode the incoming message and then do the appropriate action

However, the current way the messages are decoded from prost::Any means the only way I have figured out how to check dynamically for each message type is an if chain like this

        } else if let Some(decoded_cmd) = Any::unpack::<CommandGetCatalogs>(&msg)? {
          // act
        } else if let Some(decoded_cmd) = Any::unpack::<CommandGetDbSchemas>(&msg)? {
          // act
        } else if let Some(decoded_cmd) = Any::unpack::<ActionCreatePreparedStatementRequest>(&msg)?
        {
          // ...
        }

It would be great to have an enum so a rust match statement could be used

Describe alternatives you've considered
@stuartcarnie proposed the following in https://github.com/influxdata/influxdb_iox/pull/7213/files#r1137963627:

I created a gist that extends the sql crate in arrow-flight, that demonstrates an approach allowing us to remove all the if Some(..) to a single match:

match Commands::unpack(&msg)? {
    Commands::CommandStatementQuery(cmd) => Ok(Self::CommandStatementQuery(cmd)),
    Commands::CommandPreparedStatementQuery(CommandPreparedStatementQuery { prepared_statement_handle }) => Ok(Self::CommandPreparedStatementQuery(preparedstatementhandle::try_decode(prepared_statement_handle)?)),
    // etc
}

I extended the prost_message_ext macro to create a Commands enum with all the messages passed to the macro. The Commands macro has a static function, unpack, that is capable of unpacking any of the registered messages.

Additional context

@alamb alamb added enhancement Any new improvement worthy of a entry in the changelog arrow-flight Changes to the arrow-flight crate labels Mar 16, 2023
@alamb
Copy link
Contributor Author

alamb commented Mar 16, 2023

cc @avantgardnerio

@avantgardnerio
Copy link
Contributor

This would be awesome to solve, thanks @stuartcarnie !

@stuartcarnie
Copy link
Contributor

@avantgardnerio and @alamb figured I'd clean up the Gist and open the PR:

@tustvold tustvold added the arrow Changes to the arrow crate label Apr 7, 2023
@tustvold
Copy link
Contributor

tustvold commented Apr 7, 2023

label_issue.py automatically added labels {'arrow'} from #3887

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate arrow-flight Changes to the arrow-flight crate enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants