apache / arrow-rs

Official Rust implementation of Apache Arrow
https://arrow.apache.org/
Apache License 2.0
2.33k stars 684 forks source link

Implement TryFrom<primitive> for Arrow Flight protobuf Enums #4022

Open c-thiel opened 1 year ago

c-thiel commented 1 year ago

Is your feature request related to a problem or challenge? Please describe what you are trying to do. I am trying to implement a flight server. As such, for example in the get_flight_info_sql_info method, we get a CommandGetSqlInfo result. It's .info field is of type Vec<u32>. I would like to get the original Semantic (enum) back, so a Vec<SqlInfo>

Describe the solution you'd like Implement TryFrom or something similar to get the enum back from the primitive. Prost might even be able to generate this by adding #[derive(::prost::Enumeration)]: https://docs.rs/prost/0.11.8/prost/index.html

Describe alternatives you've considered Match all cases manually.

c-thiel commented 1 year ago

Actually, this might be a bug. I see #[derive(::prost::Enumeration)] is already implemented. The Problem is that SqlInfo is an i32 while CommandGetSqlInfo is a vec of u32. This should be compatible.

https://github.com/apache/arrow-rs/blob/2b2ce2f93b6c1798ef04658b286353b71d17682e/arrow-flight/src/sql/arrow.flight.protocol.sql.rs#L561-L563

https://github.com/apache/arrow-rs/blob/2b2ce2f93b6c1798ef04658b286353b71d17682e/arrow-flight/src/sql/arrow.flight.protocol.sql.rs#L42-L43