blob: a81421fc9b27f6f493658f02f871835bd65cc0e0 [file] [log] [blame]
// Copyright 2022 The Blaze Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use datafusion::arrow::array::{make_builder, ArrayBuilder};
use datafusion::arrow::datatypes::SchemaRef;
use datafusion::arrow::error::Result as ArrowResult;
use datafusion::arrow::record_batch::RecordBatch;
pub fn new_array_builders(
schema: &SchemaRef,
batch_size: usize,
) -> Vec<Box<dyn ArrayBuilder>> {
schema
.fields()
.iter()
.map(|field| {
let dt = field.data_type();
make_builder(dt, batch_size)
})
.collect::<Vec<_>>()
}
pub fn make_batch(
schema: SchemaRef,
mut arrays: Vec<Box<dyn ArrayBuilder>>,
) -> ArrowResult<RecordBatch> {
let columns = arrays.iter_mut().map(|array| array.finish()).collect();
RecordBatch::try_new(schema, columns)
}