dnsco opened a new issue, #3644:
URL: https://github.com/apache/arrow-rs/issues/3644
I'm generating an arrow schema, and because there is not a macro, when it's
time set the values I need to invoke a macro like this:
```rust
macro_rules! set_value {
($builder:expr,$i:expr,$typ:ty,$getter:ident,$value:expr) => {{
let b: &mut $typ = $builder.field_builder::<$typ>($i).unwrap();
match $value {
Some(cow) => {
let v = cow.$getter().unwrap();
b.append_value(v)
}
None => b.append_null(),
}
}};
}
```
```rust
fn append_value(
f: &Field,
builder: &mut StructBuilder,
i: usize,
value: Option<Cow<Value>>,
) -> Result<()> {
match f.data_type() {
DataType::Float64 => set_value!(builder, i, Float64Builder, as_f64,
value),
DataType::Float32 => set_value!(builder, i, Float32Builder, as_f32,
value),
DataType::Int64 => set_value!(builder, i, Int64Builder, as_i64,
value),
DataType::Int32 => set_value!(builder, i, Int32Builder, as_i32,
value),
DataType::UInt64 => set_value!(builder, i, UInt64Builder, as_u64,
value),
DataType::UInt32 => set_value!(builder, i, UInt32Builder, as_u32,
value),
DataType::Utf8 => set_value!(builder, i, StringBuilder, as_str,
value),
DataType::LargeUtf8 => set_value!(builder, i, LargeStringBuilder,
as_str, value),
DataType::Binary => set_value!(builder, i, BinaryBuilder, as_bytes,
value),
DataType::LargeBinary => set_value!(builder, i, LargeBinaryBuilder,
as_bytes, value),
DataType::Boolean => set_value!(builder, i, BooleanBuilder, as_bool,
value),
...
}
```
If there was a trait that contained append_value and append_null this macro
could be replaced with a generic function, which would be a much better
developer experience.
Thanks for the library!
--
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]