use std::sync::Arc;
use arrow_array::{ArrayRef, RecordBatch, RecordBatchOptions};
use arrow_schema::{Field, Schema};
use crate::row_batches::_helpers::arrow_json::normalise_column;
pub fn normalise_batch(batch: &RecordBatch) -> Result<RecordBatch, String> {
let schema = batch.schema();
let (fields, arrays): (Vec<Field>, Vec<ArrayRef>) = schema
.fields()
.iter()
.zip(batch.columns())
.map(|(field, array)| normalise_column(field.name(), array))
.collect::<Result<Vec<_>, String>>()?
.into_iter()
.unzip();
let options = RecordBatchOptions::new().with_row_count(Some(batch.num_rows()));
RecordBatch::try_new_with_options(Arc::new(Schema::new(fields)), arrays, &options)
.map_err(|error| error.to_string())
}