Skip to content

Special case for NewType as a part of StructArray #246

@v1gnesh

Description

@v1gnesh

Given the below program

use arrow_array::RecordBatch;
use narrow::{array::StructArray,  ArrayType};

#[derive(ArrayType)]
// `String` is just an example; let's say it can be any type that `narrow` supports
struct NewType(String);

impl NewType {
    fn new(s: String) -> Self {
        Self(s)
    }
}


fn main() {
    let nt = NewType::new("test".to_string());

    let struct_array = vec![nt].into_iter().collect::<StructArray<NewType>>();
    let record_batch = RecordBatch::from(struct_array);

    println!("{}", &record_batch.schema());
    // println!("{:#?}", record_batch);
    arrow_cast::pretty::print_batches(&[record_batch]).unwrap();
}

and the program's output is

Field { name: "_0", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} }
+------+
| _0   |
+------+
| test |
+------+

is it possible to add a specialization to narrow-derive/src/struct.rs, such that if it's a struct with just one field, assume it's a NewType (struct w/ unnamed field), and create an ArrayType (serialize) not the struct but the inner field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions