pub fn map2batch<T>(
m: BTreeMap<T::Native, u64>,
sch: &SchemaRef,
) -> Result<RecordBatch, Error>where
T: ArrowPrimitiveType,Expand description
Converts a BTreeMap of frequencies into an Arrow RecordBatch.
§Arguments
m: ABTreeMapwhere keys are the values and values are their frequencies.sch: TheSchemaReffor the outputRecordBatch.
§Returns
A Result containing a RecordBatch with two columns, whose names are defined by the provided SchemaRef,
or an io::Error if an error occurs.
§Example
use std::collections::BTreeMap;
use std::sync::Arc;
use arrow::datatypes::{DataType, Field, Schema};
use rs_arrow_array2freq2rbat::map2batch;
let mut freqs = BTreeMap::new();
freqs.insert(1, 1);
freqs.insert(2, 2);
freqs.insert(3, 3);
let schema = Arc::new(Schema::new(vec![
Field::new("value", DataType::Int32, false),
Field::new("frequency", DataType::UInt64, false),
]));
let batch = map2batch::<arrow::datatypes::Int32Type>(freqs, &schema).unwrap();
assert_eq!(batch.num_columns(), 2);
assert_eq!(batch.num_rows(), 3);