duckdb / duckdb-rs

Ergonomic bindings to duckdb for Rust
MIT License
517 stars 113 forks source link

Support UTF8 in nested Apache Arrow data types (e.g. List) #300

Closed Jeadie closed 7 months ago

Jeadie commented 7 months ago

Changes

Illustrative Example

let mut stmt = db.prepare(format!(r#"CREATE TABLE "{name}" AS SELECT * FROM arrow(?, ?);"#).as_str()).unwrap();

// [["foo", "baz"], ["bar", "foo"], ["baz"]]
let list_array: ArrayRef = Arc::new(ListArray::new(
    Arc::new(Field::new("item", DataType::Utf8, true)),
    OffsetBuffer::new(ScalarBuffer::from(vec![0, 2, 4, 5])), 
    Arc::new(StringArray::from(vec![Some("foo"), Some("baz"), Some("bar"), Some("foo"), Some("baz")])), None)
);

let b: Result<RecordBatch, arrow::error::ArrowError> = RecordBatch::try_from_iter(vec![("my_col", list_array)]); 
stmt.execute(arrow_recordbatch_to_query_params(
    RecordBatch::try_from_iter(vec![("col_name", list_array)])?)
);
Mause commented 7 months ago

Can you add a test please?

Jeadie commented 7 months ago

Will do