-
Notifications
You must be signed in to change notification settings - Fork 839
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
feat: Add Commands enum to decode prost messages to strong type #3887
Conversation
8c0521a
to
727e420
Compare
I plan to review this shortly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @stuartcarnie -- this is very helpful ❤️ -- I really like it
Some things I noticed while playing with this:
- In order to make this code more "discoverable" I think it would be great to add some additional documentation / examples and update the examples. I am working on a PR to do so
- . It would be nice if the FlightSQL implementation used
FlightError
rather than ArrowError (not caused by this PR). I will file a follow on PR to track this
arrow-flight/src/sql/mod.rs
Outdated
)* | ||
|
||
as_item! { | ||
pub enum Commands { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call – do you think adding some docs to the enum and then describing using the TryFrom<Any>
trait to decoding them?
arrow-flight/src/sql/mod.rs
Outdated
type_url: <$name>::type_url().to_string(), | ||
value: self.encode_to_vec().into(), | ||
impl Commands { | ||
pub fn unpack(any: Any) -> Result<Commands, ArrowError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a TryFrom
impl would also be the standard way to expose this function. I will propose one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed – I've removed unpack completely, as Command::try_from
or any.try_into()
is much better 👍🏻
Here are some suggested improvements: stuartcarnie#2 (docs + revamp some of the server.rs code to use the new dispatch logic 👍 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @stuartcarnie -- I think this is looking great
One thing I would really like to do is to translate
async fn do_get(
in arrow-flight/src/sql/server.rs
to use this new pattern too (mostly as an exercise in trying out the API). I ran out of time last night. I think we could do it in a follow on PR too
Any { | ||
type_url: <$name>::type_url().to_string(), | ||
value: self.encode_to_vec().into(), | ||
/// Get the URL for the command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this is great
arrow-flight/src/sql/server.rs
Outdated
| Command::TicketStatementQuery(_) | ||
| Command::ActionCreatePreparedStatementResult(_) => { | ||
Err(Status::unimplemented(format!( | ||
"get_flight_info: The defined request is invalid: {command:?}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"get_flight_info: The defined request is invalid: {command:?}", | |
"get_flight_info: The defined request is invalid: {}", command.type_url(), |
I pushed a few minor doc updates directly to this branch. |
I found an issue with this approach while trying to use this |
* Updated `do_get` and `do_put` functions to use `Command` enum * Added test for Unknown variant
cmd => Err(Status::unimplemented(format!( | ||
"get_flight_info: The defined request is invalid: {}", | ||
cmd.type_url() | ||
))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alamb I combined all remaining variants into a single error. I left it as unimplemented
, as it is unclear to me if there are additional commands that may be implemented in the future. If not, perhaps invalid_argument
is a more appropriate response, however, given that is a change that could break downstream clients, I've left it.
Thanks -- I plan to come back to this PR over the weekend but got overloaded with other things this week |
# Conflicts: # arrow-flight/src/sql/server.rs
I am sorry for the delay -- I will get this done / merged this week |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @stuartcarnie -- I reviewed this again and I think it looks great. I merged up from main to resolve a conflict and plan to merge this PR in when it passes CI
|
||
// Unknown variant | ||
|
||
let any = Any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I propose some additional documentation for this feature here #4012 |
Which issue does this PR close?
Closes #3874
Rationale for this change
Per the issue, this PR introduces a
Commands
enum to allow client to match on all supported messages.The following minor improvements were made to the
prost_message_ext
macro:1. Generate a constant for the type URLs:
2.
Commands
enum to unpack any of the supported FlightSQL commands:with an associated
unpack
function:3. Update other generated code to use the shared constant for the type URL:
What changes are included in this PR?
Are there any user-facing changes?
API improvements for users of the FlightSQL module.