Skip to content

Commit

Permalink
Formalize the default nested list field name to item
Browse files Browse the repository at this point in the history
  • Loading branch information
gruuya committed Nov 25, 2024
1 parent 73a0c26 commit 457fce5
Show file tree
Hide file tree
Showing 57 changed files with 271 additions and 271 deletions.
2 changes: 1 addition & 1 deletion arrow-array/benches/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn gen_fsl(len: usize, value_len: usize) -> FixedSizeListArray {
let values = Arc::new(Int32Array::from(
(0..len).map(|_| rng.gen::<i32>()).collect::<Vec<_>>(),
));
let field = Arc::new(Field::new("item", values.data_type().clone(), true));
let field = Arc::new(Field::new_list_field(values.data_type().clone(), true));
FixedSizeListArray::new(field, value_len as i32, values, None)
}

Expand Down
26 changes: 10 additions & 16 deletions arrow-array/src/array/binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,9 @@ mod tests {
.unwrap();
let binary_array1 = GenericBinaryArray::<O>::from(array_data1);

let data_type = GenericListArray::<O>::DATA_TYPE_CONSTRUCTOR(Arc::new(Field::new(
"item",
DataType::UInt8,
false,
)));
let data_type = GenericListArray::<O>::DATA_TYPE_CONSTRUCTOR(Arc::new(
Field::new_list_field(DataType::UInt8, false),
));

let array_data2 = ArrayData::builder(data_type)
.len(3)
Expand Down Expand Up @@ -421,11 +419,9 @@ mod tests {

let offsets = [0, 5, 8, 15].map(|n| O::from_usize(n).unwrap());
let null_buffer = Buffer::from_slice_ref([0b101]);
let data_type = GenericListArray::<O>::DATA_TYPE_CONSTRUCTOR(Arc::new(Field::new(
"item",
DataType::UInt8,
false,
)));
let data_type = GenericListArray::<O>::DATA_TYPE_CONSTRUCTOR(Arc::new(
Field::new_list_field(DataType::UInt8, false),
));

// [None, Some(b"Parquet")]
let array_data = ArrayData::builder(data_type)
Expand Down Expand Up @@ -466,11 +462,9 @@ mod tests {
.unwrap();

let offsets = [0, 5, 10].map(|n| O::from_usize(n).unwrap());
let data_type = GenericListArray::<O>::DATA_TYPE_CONSTRUCTOR(Arc::new(Field::new(
"item",
DataType::UInt8,
true,
)));
let data_type = GenericListArray::<O>::DATA_TYPE_CONSTRUCTOR(Arc::new(
Field::new_list_field(DataType::UInt8, true),
));

// [None, Some(b"Parquet")]
let array_data = ArrayData::builder(data_type)
Expand Down Expand Up @@ -558,7 +552,7 @@ mod tests {
.unwrap();
let offsets: [i32; 4] = [0, 5, 5, 12];

let data_type = DataType::List(Arc::new(Field::new("item", DataType::UInt32, false)));
let data_type = DataType::List(Arc::new(Field::new_list_field(DataType::UInt32, false)));
let array_data = ArrayData::builder(data_type)
.len(3)
.add_buffer(Buffer::from_slice_ref(offsets))
Expand Down
6 changes: 3 additions & 3 deletions arrow-array/src/array/fixed_size_binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ mod tests {
// [null, [10, 11, 12, 13]]
let array_data = unsafe {
ArrayData::builder(DataType::FixedSizeList(
Arc::new(Field::new("item", DataType::UInt8, false)),
Arc::new(Field::new_list_field(DataType::UInt8, false)),
4,
))
.len(2)
Expand Down Expand Up @@ -758,7 +758,7 @@ mod tests {

let array_data = unsafe {
ArrayData::builder(DataType::FixedSizeList(
Arc::new(Field::new("item", DataType::Binary, false)),
Arc::new(Field::new_list_field(DataType::Binary, false)),
4,
))
.len(3)
Expand All @@ -782,7 +782,7 @@ mod tests {

let array_data = unsafe {
ArrayData::builder(DataType::FixedSizeList(
Arc::new(Field::new("item", DataType::UInt8, false)),
Arc::new(Field::new_list_field(DataType::UInt8, false)),
4,
))
.len(3)
Expand Down
18 changes: 9 additions & 9 deletions arrow-array/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ use std::sync::Arc;
/// .build()
/// .unwrap();
/// let list_data_type = DataType::FixedSizeList(
/// Arc::new(Field::new("item", DataType::Int32, false)),
/// Arc::new(Field::new_list_field(DataType::Int32, false)),
/// 3,
/// );
/// let list_data = ArrayData::builder(list_data_type.clone())
Expand Down Expand Up @@ -487,7 +487,7 @@ mod tests {

// Construct a list array from the above two
let list_data_type =
DataType::FixedSizeList(Arc::new(Field::new("item", DataType::Int32, false)), 3);
DataType::FixedSizeList(Arc::new(Field::new_list_field(DataType::Int32, false)), 3);
let list_data = ArrayData::builder(list_data_type.clone())
.len(3)
.add_child_data(value_data.clone())
Expand Down Expand Up @@ -540,7 +540,7 @@ mod tests {

// Construct a list array from the above two
let list_data_type =
DataType::FixedSizeList(Arc::new(Field::new("item", DataType::Int32, false)), 3);
DataType::FixedSizeList(Arc::new(Field::new_list_field(DataType::Int32, false)), 3);
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
Expand Down Expand Up @@ -569,7 +569,7 @@ mod tests {

// Construct a fixed size list array from the above two
let list_data_type =
DataType::FixedSizeList(Arc::new(Field::new("item", DataType::Int32, false)), 2);
DataType::FixedSizeList(Arc::new(Field::new_list_field(DataType::Int32, false)), 2);
let list_data = ArrayData::builder(list_data_type)
.len(5)
.add_child_data(value_data.clone())
Expand Down Expand Up @@ -627,7 +627,7 @@ mod tests {

// Construct a fixed size list array from the above two
let list_data_type =
DataType::FixedSizeList(Arc::new(Field::new("item", DataType::Int32, false)), 2);
DataType::FixedSizeList(Arc::new(Field::new_list_field(DataType::Int32, false)), 2);
let list_data = ArrayData::builder(list_data_type)
.len(5)
.add_child_data(value_data)
Expand All @@ -650,7 +650,7 @@ mod tests {
Some(4),
]));

let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
let list = FixedSizeListArray::new(field.clone(), 2, values.clone(), None);
assert_eq!(list.len(), 3);

Expand All @@ -674,22 +674,22 @@ mod tests {
let err = FixedSizeListArray::try_new(field, 2, values.clone(), Some(nulls)).unwrap_err();
assert_eq!(err.to_string(), "Invalid argument error: Incorrect length of null buffer for FixedSizeListArray, expected 3 got 2");

let field = Arc::new(Field::new("item", DataType::Int32, false));
let field = Arc::new(Field::new_list_field(DataType::Int32, false));
let err = FixedSizeListArray::try_new(field.clone(), 2, values.clone(), None).unwrap_err();
assert_eq!(err.to_string(), "Invalid argument error: Found unmasked nulls for non-nullable FixedSizeListArray field \"item\"");

// Valid as nulls in child masked by parent
let nulls = NullBuffer::new(BooleanBuffer::new(Buffer::from([0b0000101]), 0, 3));
FixedSizeListArray::new(field, 2, values.clone(), Some(nulls));

let field = Arc::new(Field::new("item", DataType::Int64, true));
let field = Arc::new(Field::new_list_field(DataType::Int64, true));
let err = FixedSizeListArray::try_new(field, 2, values, None).unwrap_err();
assert_eq!(err.to_string(), "Invalid argument error: FixedSizeListArray expected data type Int64 got Int32 for \"item\"");
}

#[test]
fn empty_fixed_size_list() {
let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
let nulls = NullBuffer::new_null(2);
let values = new_empty_array(&DataType::Int32);
let list = FixedSizeListArray::new(field.clone(), 0, values, Some(nulls));
Expand Down
23 changes: 15 additions & 8 deletions arrow-array/src/array/list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ mod tests {
// [[0, 1, 2], [3, 4, 5], [6, 7]]
let values = Int32Array::from(vec![0, 1, 2, 3, 4, 5, 6, 7]);
let offsets = OffsetBuffer::new(ScalarBuffer::from(vec![0, 3, 6, 8]));
let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
ListArray::new(field, offsets, Arc::new(values), None)
}

Expand Down Expand Up @@ -595,7 +595,8 @@ mod tests {
let value_offsets = Buffer::from([]);

// Construct a list array from the above two
let list_data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, false)));
let list_data_type =
DataType::List(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = ArrayData::builder(list_data_type)
.len(0)
.add_buffer(value_offsets)
Expand All @@ -621,7 +622,8 @@ mod tests {
let value_offsets = Buffer::from_slice_ref([0, 3, 6, 8]);

// Construct a list array from the above two
let list_data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, false)));
let list_data_type =
DataType::List(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = ArrayData::builder(list_data_type.clone())
.len(3)
.add_buffer(value_offsets.clone())
Expand Down Expand Up @@ -766,7 +768,8 @@ mod tests {
bit_util::set_bit(&mut null_bits, 8);

// Construct a list array from the above two
let list_data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, false)));
let list_data_type =
DataType::List(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = ArrayData::builder(list_data_type)
.len(9)
.add_buffer(value_offsets)
Expand Down Expand Up @@ -917,7 +920,8 @@ mod tests {
.add_buffer(Buffer::from_slice_ref([0, 1, 2, 3, 4, 5, 6, 7]))
.build_unchecked()
};
let list_data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, false)));
let list_data_type =
DataType::List(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
Expand All @@ -934,7 +938,8 @@ mod tests {
#[cfg(not(feature = "force_validate"))]
fn test_list_array_invalid_child_array_len() {
let value_offsets = Buffer::from_slice_ref([0, 2, 5, 7]);
let list_data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, false)));
let list_data_type =
DataType::List(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
Expand Down Expand Up @@ -964,7 +969,8 @@ mod tests {

let value_offsets = Buffer::from_slice_ref([2, 2, 5, 7]);

let list_data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, false)));
let list_data_type =
DataType::List(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = ArrayData::builder(list_data_type)
.len(3)
.add_buffer(value_offsets)
Expand Down Expand Up @@ -1010,7 +1016,8 @@ mod tests {
.build_unchecked()
};

let list_data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, false)));
let list_data_type =
DataType::List(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.add_buffer(buf2)
Expand Down
26 changes: 13 additions & 13 deletions arrow-array/src/array/list_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ mod tests {
fn test_empty_list_view_array() {
// Construct an empty value array
let vec: Vec<i32> = vec![];
let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
let sizes = ScalarBuffer::from(vec![]);
let offsets = ScalarBuffer::from(vec![]);
let values = Int32Array::from(vec);
Expand All @@ -508,7 +508,7 @@ mod tests {
.build()
.unwrap();

let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
let sizes = ScalarBuffer::from(vec![3i32, 3, 2]);
let offsets = ScalarBuffer::from(vec![0i32, 3, 6]);
let values = Int32Array::from(vec![0, 1, 2, 3, 4, 5, 6, 7]);
Expand Down Expand Up @@ -544,7 +544,7 @@ mod tests {
.build()
.unwrap();

let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
let sizes = ScalarBuffer::from(vec![3i64, 3, 2]);
let offsets = ScalarBuffer::from(vec![0i64, 3, 6]);
let values = Int32Array::from(vec![0, 1, 2, 3, 4, 5, 6, 7]);
Expand Down Expand Up @@ -590,7 +590,7 @@ mod tests {
let buffer = BooleanBuffer::new(Buffer::from(null_bits), 0, 9);
let null_buffer = NullBuffer::new(buffer);

let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
let sizes = ScalarBuffer::from(vec![2, 0, 0, 2, 2, 0, 3, 0, 1]);
let offsets = ScalarBuffer::from(vec![0, 2, 2, 2, 4, 6, 6, 9, 9]);
let values = Int32Array::from(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
Expand Down Expand Up @@ -656,7 +656,7 @@ mod tests {
let null_buffer = NullBuffer::new(buffer);

// Construct a large list view array from the above two
let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
let sizes = ScalarBuffer::from(vec![2i64, 0, 0, 2, 2, 0, 3, 0, 1]);
let offsets = ScalarBuffer::from(vec![0i64, 2, 2, 2, 4, 6, 6, 9, 9]);
let values = Int32Array::from(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
Expand Down Expand Up @@ -718,7 +718,7 @@ mod tests {
// Construct a buffer for value offsets, for the nested array:
// [[0, 1], null, null, [2, 3], [4, 5], null, [6, 7, 8], null, [9]]
// Construct a list array from the above two
let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
let sizes = ScalarBuffer::from(vec![2i32, 0, 0, 2, 2, 0, 3, 0, 1]);
let offsets = ScalarBuffer::from(vec![0i32, 2, 2, 2, 4, 6, 6, 9, 9]);
let values = Int32Array::from(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
Expand All @@ -741,7 +741,7 @@ mod tests {
.build_unchecked()
};
let list_data_type =
DataType::ListView(Arc::new(Field::new("item", DataType::Int32, false)));
DataType::ListView(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
Expand All @@ -759,7 +759,7 @@ mod tests {
fn test_list_view_array_invalid_child_array_len() {
let value_offsets = Buffer::from_slice_ref([0, 2, 5, 7]);
let list_data_type =
DataType::ListView(Arc::new(Field::new("item", DataType::Int32, false)));
DataType::ListView(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
Expand All @@ -771,7 +771,7 @@ mod tests {

#[test]
fn test_list_view_array_offsets_need_not_start_at_zero() {
let field = Arc::new(Field::new("item", DataType::Int32, true));
let field = Arc::new(Field::new_list_field(DataType::Int32, true));
let sizes = ScalarBuffer::from(vec![0i32, 0, 3]);
let offsets = ScalarBuffer::from(vec![2i32, 2, 5]);
let values = Int32Array::from(vec![0, 1, 2, 3, 4, 5, 6, 7]);
Expand Down Expand Up @@ -800,7 +800,7 @@ mod tests {
};

let list_data_type =
DataType::ListView(Arc::new(Field::new("item", DataType::Int32, false)));
DataType::ListView(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.add_buffer(offset_buf2)
Expand Down Expand Up @@ -942,7 +942,7 @@ mod tests {
.build_unchecked()
};
let list_data_type =
DataType::ListView(Arc::new(Field::new("item", DataType::Int32, false)));
DataType::ListView(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(2)
Expand Down Expand Up @@ -976,7 +976,7 @@ mod tests {
.build_unchecked()
};
let list_data_type =
DataType::ListView(Arc::new(Field::new("item", DataType::Int32, false)));
DataType::ListView(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
Expand Down Expand Up @@ -1015,7 +1015,7 @@ mod tests {
.build_unchecked()
};
let list_data_type =
DataType::ListView(Arc::new(Field::new("item", DataType::Int32, false)));
DataType::ListView(Arc::new(Field::new_list_field(DataType::Int32, false)));
let list_data = unsafe {
ArrayData::builder(list_data_type)
.len(3)
Expand Down
4 changes: 2 additions & 2 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ mod tests {

#[test]
fn test_empty_list_primitive() {
let data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, false)));
let data_type = DataType::List(Arc::new(Field::new_list_field(DataType::Int32, false)));
let array = new_empty_array(&data_type);
let a = array.as_any().downcast_ref::<ListArray>().unwrap();
assert_eq!(a.len(), 0);
Expand Down Expand Up @@ -969,7 +969,7 @@ mod tests {

#[test]
fn test_null_list_primitive() {
let data_type = DataType::List(Arc::new(Field::new("item", DataType::Int32, true)));
let data_type = DataType::List(Arc::new(Field::new_list_field(DataType::Int32, true)));
let array = new_null_array(&data_type, 9);
let a = array.as_any().downcast_ref::<ListArray>().unwrap();
assert_eq!(a.len(), 9);
Expand Down
Loading

0 comments on commit 457fce5

Please sign in to comment.