Skip to main content

make_array

Function make_array 

pub fn make_array(data: ArrayData) -> Arc<dyn Array>
Expand description

Constructs an ArrayRef from an ArrayData.

§Notes:

It is more efficient to directly construct the concrete array type rather than using this function as creating an ArrayData requires at least one additional allocation (the Vec of buffers).

§Example:

// Create an Int32Array with values [1, 2, 3]
let values_buffer = Buffer::from_slice_ref(&[1, 2, 3]);
// ArrayData can be constructed using ArrayDataBuilder
 let builder = ArrayData::builder(DataType::Int32)
   .len(3)
   .add_buffer(values_buffer.clone());
let array_data = builder.build().unwrap();
// Create the ArrayRef from the ArrayData
let array = make_array(array_data);

// It is equivalent to directly constructing the Int32Array
let scalar_buffer = ScalarBuffer::from(values_buffer);
let int32_array: ArrayRef = Arc::new(Int32Array::new(scalar_buffer, None));
assert_eq!(&array, &int32_array);