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

Example to show how to convert query result into rust struct #2959

Closed
thomas-k-cameron opened this issue Jul 23, 2022 · 2 comments · Fixed by #2969
Closed

Example to show how to convert query result into rust struct #2959

thomas-k-cameron opened this issue Jul 23, 2022 · 2 comments · Fixed by #2969
Labels
enhancement New feature or request

Comments

@thomas-k-cameron
Copy link
Contributor

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
Add an example that shows how to convert query result into rust struct.

Describe the solution you'd like
Add an example.

Describe alternatives you've considered
Implementing a macro to convert record batch into rust struct.
Performance wise, this should have less overhead when implemented properly, but it takes some time to get it right. In the mean time, I think my solution is the most straight forward way to do this.

Additional context
Here is my implementation.
https://github.com/thomas-k-cameron/arrow-datafusion/blob/to_struct/datafusion-examples/examples/deserialize_to_struct.rs
If this is ok, I'd love to create a pull request.

I needed to convert the query result into rust struct for my project: I initially tried to implement a macro but after a while I discovered that you can actually do this using functions that are already implemented by the library. It took me some time to figure this out, and I think this use case is relevant to many people.
I also saw a repository that is trying to implement a way to turn record batches into rust struct.

It would be very nice if you could let me know if I'm getting this wrong.

@thomas-k-cameron thomas-k-cameron added the enhancement New feature or request label Jul 23, 2022
@andygrove
Copy link
Member

Thanks @thomas-k-cameron. That looks like a very useful example to me.

@thomas-k-cameron
Copy link
Contributor Author

Thanks @thomas-k-cameron. That looks like a very useful example to me.

Thanks!
I just created a pull request.
#2969

xudong963 pushed a commit that referenced this issue Jul 27, 2022
#2969)

* shows how to turn query result into struct

* fix

* tomlfmt for Cargo.toml in examples

* cargo fmt
allow-deadcode
delete unused import/derive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants