Skip to content

Commit

Permalink
Closes apache#1902: Print the original and projected RecordBatch in d…
Browse files Browse the repository at this point in the history
…ynamic_types example

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
  • Loading branch information
martin-g committed Jun 17, 2022
1 parent fc4044f commit 2378d1a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions arrow/examples/dynamic_types.rs
Expand Up @@ -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![
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -91,11 +99,16 @@ 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();
}
}

0 comments on commit 2378d1a

Please sign in to comment.