alamb commented on a change in pull request #9469:
URL: https://github.com/apache/arrow/pull/9469#discussion_r574760259
##########
File path: rust/arrow/src/array/array.rs
##########
@@ -326,6 +327,167 @@ pub fn new_empty_array(data_type: &DataType) -> ArrayRef {
let data = ArrayData::new_empty(data_type);
make_array(Arc::new(data))
}
+/// Creates a new array of `data_type` of length `length` filled entirely of
`NULL` values
+pub fn new_null_array(data_type: &DataType, length: usize) -> ArrayRef {
+ match data_type {
+ DataType::Null => Arc::new(NullArray::new(length)),
+ DataType::Boolean => {
+ let null_buf: Buffer = MutableBuffer::new_null(length).into();
+ make_array(Arc::new(ArrayData::new(
+ data_type.clone(),
+ length,
+ Some(length),
+ Some(null_buf.clone()),
+ 0,
+ vec![null_buf],
+ vec![],
+ )))
+ }
+ DataType::Int8 | DataType::UInt8 => {
+ new_null_sized_array::<Int8Type>(data_type, length)
+ }
+ DataType::Int16 | DataType::UInt16 => {
+ new_null_sized_array::<Int16Type>(data_type, length)
+ }
+ DataType::Float16 => unreachable!(),
+ DataType::Int32
+ | DataType::UInt32
+ | DataType::Float32
+ | DataType::Date32
+ | DataType::Time32(_) => new_null_sized_array::<Int32Type>(data_type,
length),
+ DataType::Int64
+ | DataType::UInt64
+ | DataType::Float64
+ | DataType::Date64
+ | DataType::Timestamp(_, _)
+ | DataType::Time64(_)
+ | DataType::Duration(_) =>
new_null_sized_array::<Int64Type>(data_type, length),
+ DataType::Interval(unit) => match unit {
+ IntervalUnit::YearMonth => {
+ new_null_sized_array::<Int32Type>(data_type, length)
+ }
+ IntervalUnit::DayTime =>
new_null_sized_array::<Int64Type>(data_type, length),
+ },
+ DataType::FixedSizeBinary(value_len) =>
make_array(Arc::new(ArrayData::new(
+ data_type.clone(),
+ length,
+ Some(length),
+ Some(MutableBuffer::new_null(length).into()),
+ 0,
+ vec![Buffer::from(vec![0u8; *value_len as usize * length])],
+ vec![],
+ ))),
+ DataType::Binary | DataType::Utf8 => {
+ new_null_binary_array::<i32>(data_type, length)
+ }
+ DataType::LargeBinary | DataType::LargeUtf8 => {
+ new_null_binary_array::<i64>(data_type, length)
+ }
+ DataType::List(field) => {
+ new_null_list_array::<i32>(data_type, field.data_type(), length)
+ }
+ DataType::LargeList(field) => {
+ new_null_list_array::<i64>(data_type, field.data_type(), length)
+ }
+ DataType::FixedSizeList(field, value_len) => {
+ make_array(Arc::new(ArrayData::new(
+ data_type.clone(),
+ length,
+ Some(length),
+ Some(MutableBuffer::new_null(length).into()),
+ 0,
+ vec![],
+ vec![
+ new_null_array(field.data_type(), *value_len as usize *
length)
+ .data(),
+ ],
+ )))
+ }
+ DataType::Struct(fields) => make_array(Arc::new(ArrayData::new(
+ data_type.clone(),
+ length,
+ Some(length),
+ Some(MutableBuffer::new_null(length).into()),
+ 0,
+ vec![],
+ fields
+ .iter()
+ .map(|field| Arc::new(ArrayData::new_empty(field.data_type())))
+ .collect(),
+ ))),
+ DataType::Union(_) => {
+ unimplemented!("Creating null Union array not yet supported")
+ }
+ DataType::Dictionary(_, value) => {
+ make_array(Arc::new(ArrayData::new(
+ data_type.clone(),
+ length,
+ Some(length),
+ Some(MutableBuffer::new_null(length).into()),
+ 0,
+ vec![MutableBuffer::new(0).into()], // keys are empty
Review comment:
```suggestion
vec![MutableBuffer::new(0).into()], // values are empty
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]