k-bx opened a new issue, #7180:
URL: https://github.com/apache/arrow-rs/issues/7180
At the moment I do this:
```rust
use arrow::array::{Int64Array, StringArray};
use arrow::datatypes::{DataType, Field, Schema};
use arrow::record_batch::RecordBatch;
use parquet_derive::ParquetRecordWriter;
use std::sync::Arc;
#[derive(ParquetRecordWriter)]
pub struct Mavlog {
pub id: String,
pub headers: Option<String>,
pub data: Option<String>,
pub created_at: i64,
}
pub fn mk_batch(mavlogs: &[Mavlog]) -> anyhow::Result<RecordBatch> {
// Map struct fields into Arrow arrays
let id_vals: Vec<&str> = mavlogs.iter().map(|m| m.id.as_str()).collect();
let id_array = StringArray::from(id_vals);
let headers_vals: Vec<Option<&str>> = mavlogs.iter().map(|m|
m.headers.as_deref()).collect();
let headers_array = StringArray::from(headers_vals);
let data_vals: Vec<Option<&str>> = mavlogs.iter().map(|m|
m.data.as_deref()).collect();
let data_array = StringArray::from(data_vals);
let created_vals: Vec<i64> = mavlogs.iter().map(|m|
m.created_at).collect();
let created_array = Int64Array::from(created_vals);
// Build a schema matching the batch macro structure
let schema = Schema::new(vec![
Field::new("id", DataType::Utf8, false),
Field::new("headers", DataType::Utf8, true),
Field::new("data", DataType::Utf8, true),
Field::new("created_at", DataType::Int64, false),
]);
let batch = RecordBatch::try_new(Arc::new(schema), vec![
Arc::new(id_array),
Arc::new(headers_array),
Arc::new(data_array),
Arc::new(created_array),
])?;
Ok(batch)
}
```
Would be nice to derive this capability.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]