You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/27 02:25:57 UTC

[GitHub] [arrow-datafusion] thomas-k-cameron opened a new pull request, #2969: Example to show how to convert query result into rust struct #2959

thomas-k-cameron opened a new pull request, #2969:
URL: https://github.com/apache/arrow-datafusion/pull/2969

   # 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] xudong963 merged pull request #2969: Example that shows how to convert query result into rust struct #2959

Posted by GitBox <gi...@apache.org>.
xudong963 merged PR #2969:
URL: https://github.com/apache/arrow-datafusion/pull/2969


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ursabot commented on pull request #2969: Example that shows how to convert query result into rust struct #2959

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #2969:
URL: https://github.com/apache/arrow-datafusion/pull/2969#issuecomment-1196647435

   Benchmark runs are scheduled for baseline = 884101e106c580c518409a8685c36d0c48c1403b and contender = e47c4eb1ac8a5c3c07a0ed2bad74ecd6509bae7b. e47c4eb1ac8a5c3c07a0ed2bad74ecd6509bae7b is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/abca3262ede14dcda5786f1e75edc856...b1f3bb703691492cbc23f880d7bf95a7/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/4be9a2c8803648659167552d46a12549...bb159ddf978241edbbc971ddb8ef70c1/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/37ab1da8b5b246a295e5ddfa92c1b9a7...e4e477d00e264d3ca20ca1f21b232c04/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/95edb7f53eda4c8ba7414b73a34ff328...9b14d8dc0da1491384e198ec054ac3d8/)
   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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] codecov-commenter commented on pull request #2969: Example that shows how to convert query result into rust struct #2959

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #2969:
URL: https://github.com/apache/arrow-datafusion/pull/2969#issuecomment-1196556468

   # [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2969?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#2969](https://codecov.io/gh/apache/arrow-datafusion/pull/2969?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d94c8be) into [master](https://codecov.io/gh/apache/arrow-datafusion/commit/4005076d8e3e4fa07541da62f7a6c9c755029da1?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (4005076) will **decrease** coverage by `0.00%`.
   > The diff coverage is `n/a`.
   
   ```diff
   @@            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](https://codecov.io/gh/apache/arrow-datafusion/pull/2969?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [datafusion/expr/src/logical\_plan/plan.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2969/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9leHByL3NyYy9sb2dpY2FsX3BsYW4vcGxhbi5ycw==) | `77.43% <0.00%> (-0.35%)` | :arrow_down: |
   | [datafusion/expr/src/window\_frame.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2969/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9leHByL3NyYy93aW5kb3dfZnJhbWUucnM=) | `93.27% <0.00%> (+0.84%)` | :arrow_up: |
   
   Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2969: Example that shows how to convert query result into rust struct #2959

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2969:
URL: https://github.com/apache/arrow-datafusion/pull/2969#discussion_r930957504


##########
datafusion-examples/examples/deserialize_to_struct.rs:
##########
@@ -0,0 +1,75 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datafusion::error::Result;
+use datafusion::prelude::*;
+use serde::Deserialize;
+
+/// This example shows that it is possible to convert query results into Rust structs .
+/// It will collect the query results into RecordBatch, then convert it to serde_json::Value.
+/// Then, serde_json::Value is turned into Rust's struct.
+/// Any datatype with `Deserialize` implemeneted works.
+#[tokio::main]
+async fn main() -> Result<()> {
+    let data_list = Data::new().await?;
+    println!("{:#?}", data_list);
+    Ok(())
+}
+
+#[derive(Deserialize, Debug)]
+struct Data {
+    #[allow(dead_code)]
+    int_col: i64,
+    #[allow(dead_code)]
+    double_col: f64,
+}
+
+impl Data {
+    pub async fn new() -> Result<Vec<Self>> {
+        // this group is almost the same as the one you find it in parquet_sql.rs
+        let batches = {
+            let ctx = SessionContext::new();
+
+            let testdata = datafusion::test_util::parquet_test_data();
+
+            ctx.register_parquet(
+                "alltypes_plain",
+                &format!("{}/alltypes_plain.parquet", testdata),
+                ParquetReadOptions::default(),
+            )
+            .await?;
+
+            let df = ctx
+                .sql("SELECT int_col, double_col FROM alltypes_plain")
+                .await?;
+
+            df.show().await?;
+
+            df.collect().await?
+        };
+        // converts it to serde_json type and then convert that into Rust type
+        let list =

Review Comment:
   👍  this is very cool
   
   



##########
datafusion-examples/examples/deserialize_to_struct.rs:
##########
@@ -0,0 +1,75 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datafusion::error::Result;
+use datafusion::prelude::*;
+use serde::Deserialize;
+
+/// This example shows that it is possible to convert query results into Rust structs .

Review Comment:
   👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] thomas-k-cameron commented on pull request #2969: Example that shows how to convert query result into rust struct #2959

Posted by GitBox <gi...@apache.org>.
thomas-k-cameron commented on PR #2969:
URL: https://github.com/apache/arrow-datafusion/pull/2969#issuecomment-1196585531

   Fixed all the stuff mentioned by the tests


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] thomas-k-cameron commented on a diff in pull request #2969: Example that shows how to convert query result into rust struct #2959

Posted by GitBox <gi...@apache.org>.
thomas-k-cameron commented on code in PR #2969:
URL: https://github.com/apache/arrow-datafusion/pull/2969#discussion_r930963112


##########
datafusion-examples/examples/deserialize_to_struct.rs:
##########
@@ -0,0 +1,75 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datafusion::error::Result;
+use datafusion::prelude::*;
+use serde::Deserialize;
+
+/// This example shows that it is possible to convert query results into Rust structs .
+/// It will collect the query results into RecordBatch, then convert it to serde_json::Value.
+/// Then, serde_json::Value is turned into Rust's struct.
+/// Any datatype with `Deserialize` implemeneted works.
+#[tokio::main]
+async fn main() -> Result<()> {
+    let data_list = Data::new().await?;
+    println!("{:#?}", data_list);
+    Ok(())
+}
+
+#[derive(Deserialize, Debug)]
+struct Data {
+    #[allow(dead_code)]
+    int_col: i64,
+    #[allow(dead_code)]
+    double_col: f64,
+}
+
+impl Data {
+    pub async fn new() -> Result<Vec<Self>> {
+        // this group is almost the same as the one you find it in parquet_sql.rs
+        let batches = {
+            let ctx = SessionContext::new();
+
+            let testdata = datafusion::test_util::parquet_test_data();
+
+            ctx.register_parquet(
+                "alltypes_plain",
+                &format!("{}/alltypes_plain.parquet", testdata),
+                ParquetReadOptions::default(),
+            )
+            .await?;
+
+            let df = ctx
+                .sql("SELECT int_col, double_col FROM alltypes_plain")
+                .await?;
+
+            df.show().await?;
+
+            df.collect().await?
+        };
+        // converts it to serde_json type and then convert that into Rust type
+        let list =

Review Comment:
   Thanks :D



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org