You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2022/06/17 18:25:24 UTC

[arrow-rs] branch master updated: Closes #1902: Print the original and projected RecordBatch in dynamic_types example (#1903)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new faac59ab8 Closes #1902: Print the original and projected RecordBatch in dynamic_types example (#1903)
faac59ab8 is described below

commit faac59ab8434b15d44c28d2b187471a2e7ca4bcb
Author: Martin Grigorov <ma...@users.noreply.github.com>
AuthorDate: Fri Jun 17 21:25:18 2022 +0300

    Closes #1902: Print the original and projected RecordBatch in dynamic_types example (#1903)
    
    * Closes #1902: Print the original and projected RecordBatch in dynamic_types example
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    
    * Issue #1902: Fix formatting issue
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---
 arrow/examples/dynamic_types.rs | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/arrow/examples/dynamic_types.rs b/arrow/examples/dynamic_types.rs
index 58e41560e..f98596f2e 100644
--- a/arrow/examples/dynamic_types.rs
+++ b/arrow/examples/dynamic_types.rs
@@ -25,6 +25,9 @@ use arrow::datatypes::*;
 use arrow::error::Result;
 use arrow::record_batch::*;
 
+#[cfg(feature = "prettyprint")]
+use arrow::util::pretty::print_batches;
+
 fn main() -> Result<()> {
     // define schema
     let schema = Schema::new(vec![
@@ -62,6 +65,11 @@ fn main() -> Result<()> {
     let batch =
         RecordBatch::try_new(Arc::new(schema), vec![Arc::new(id), Arc::new(nested)])?;
 
+    #[cfg(feature = "prettyprint")]
+    {
+        print_batches(&[batch.clone()]).unwrap();
+    }
+
     process(&batch);
     Ok(())
 }
@@ -91,11 +99,17 @@ fn process(batch: &RecordBatch) {
         Field::new("sum", DataType::Float64, false),
     ]);
 
-    let _ = RecordBatch::try_new(
+    let projection = RecordBatch::try_new(
         Arc::new(projected_schema),
         vec![
             id.clone(), // NOTE: this is cloning the Arc not the array data
             Arc::new(Float64Array::from(nested_c.data().clone())),
         ],
-    );
+    )
+    .unwrap();
+
+    #[cfg(feature = "prettyprint")]
+    {
+        print_batches(&[projection]).unwrap();
+    }
 }