You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "k-bx (via GitHub)" <gi...@apache.org> on 2025/02/23 10:27:44 UTC
[I] Derive Arrow IPC RecordBatch constructor [arrow-rs]
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: github-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Derive Arrow IPC RecordBatch constructor [arrow-rs]
Posted by "k-bx (via GitHub)" <gi...@apache.org>.
k-bx closed issue #7180: Derive Arrow IPC RecordBatch constructor
URL: https://github.com/apache/arrow-rs/issues/7180
--
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
Re: [I] Derive Arrow IPC RecordBatch constructor [arrow-rs]
Posted by "k-bx (via GitHub)" <gi...@apache.org>.
k-bx commented on issue #7180:
URL: https://github.com/apache/arrow-rs/issues/7180#issuecomment-2676840856
To answer my own request, there are:
- https://crates.io/crates/serde_arrow
- https://crates.io/crates/arrow_convert
Both looking good
--
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