arrow_csv

Module writer

Source
Expand description

CSV Writer

This CSV writer allows Arrow data (in record batches) to be written as CSV files. The writer does not support writing ListArray and StructArray.

Example:


let schema = Schema::new(vec![
    Field::new("c1", DataType::Utf8, false),
    Field::new("c2", DataType::Float64, true),
    Field::new("c3", DataType::UInt32, false),
    Field::new("c4", DataType::Boolean, true),
]);
let c1 = StringArray::from(vec![
    "Lorem ipsum dolor sit amet",
    "consectetur adipiscing elit",
    "sed do eiusmod tempor",
]);
let c2 = PrimitiveArray::<Float64Type>::from(vec![
    Some(123.564532),
    None,
    Some(-556132.25),
]);
let c3 = PrimitiveArray::<UInt32Type>::from(vec![3, 2, 1]);
let c4 = BooleanArray::from(vec![Some(true), Some(false), None]);

let batch = RecordBatch::try_new(
    Arc::new(schema),
    vec![Arc::new(c1), Arc::new(c2), Arc::new(c3), Arc::new(c4)],
)
.unwrap();

let mut output = Vec::with_capacity(1024);

let mut writer = Writer::new(&mut output);
let batches = vec![&batch, &batch];
for batch in batches {
    writer.write(batch).unwrap();
}

Structsยง