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 that shows how to convert query result into rust struct #2959 #2969

Merged
merged 6 commits into from
Jul 27, 2022

Conversation

thomas-k-cameron
Copy link
Contributor

Which issue does this PR close?

Closes #2959 .

Rationale for this change

Add an example that shows how to convert query result into rust struct.
Details/Background in the issue.

What changes are included in this PR?

New example.

Are there any user-facing changes?

No.

@thomas-k-cameron thomas-k-cameron changed the title Example to show how to convert query result into rust struct #2959 Example that shows how to convert query result into rust struct #2959 Jul 27, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #2969 (d94c8be) into master (4005076) will decrease coverage by 0.00%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #2969      +/-   ##
==========================================
- Coverage   85.71%   85.71%   -0.01%     
==========================================
  Files         280      280              
  Lines       51313    51313              
==========================================
- Hits        43983    43982       -1     
- Misses       7330     7331       +1     
Impacted Files Coverage Δ
datafusion/expr/src/logical_plan/plan.rs 77.43% <0.00%> (-0.35%) ⬇️
datafusion/expr/src/window_frame.rs 93.27% <0.00%> (+0.84%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us.

@thomas-k-cameron
Copy link
Contributor Author

Fixed all the stuff mentioned by the tests

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.

I tried it out -- and it looks great to me.

cargo run --example deserialize_to_struct
...

+---------+------------+
| int_col | double_col |
+---------+------------+
| 0       | 0          |
| 1       | 10.1       |
| 0       | 0          |
| 1       | 10.1       |
| 0       | 0          |
| 1       | 10.1       |
| 0       | 0          |
| 1       | 10.1       |
+---------+------------+
[
    Data {
        int_col: 0,
        double_col: 0.0,
    },
    Data {
        int_col: 1,
        double_col: 10.1,
    },
    Data {
        int_col: 0,
        double_col: 0.0,
    },
    Data {
        int_col: 1,
        double_col: 10.1,
    },
    Data {
        int_col: 0,
        double_col: 0.0,
    },
    Data {
        int_col: 1,
        double_col: 10.1,
    },
    Data {
        int_col: 0,
        double_col: 0.0,
    },
    Data {
        int_col: 1,
        double_col: 10.1,
    },
]

👍

Thanks @thomas-k-cameron

use datafusion::prelude::*;
use serde::Deserialize;

/// This example shows that it is possible to convert query results into Rust structs .
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

df.collect().await?
};
// converts it to serde_json type and then convert that into Rust type
let list =
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 this is very cool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks :D

Copy link
Member

@xudong963 xudong963 left a comment

Choose a reason for hiding this comment

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

Cool example! @thomas-k-cameron

@xudong963 xudong963 merged commit e47c4eb into apache:master Jul 27, 2022
@thomas-k-cameron thomas-k-cameron deleted the to_struct branch July 27, 2022 12:05
@ursabot
Copy link

ursabot commented Jul 27, 2022

Benchmark runs are scheduled for baseline = 884101e and contender = e47c4eb. e47c4eb is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Example to show how to convert query result into rust struct
5 participants