Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Add test for list_nested_decimal (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
ariesdevil authored Sep 28, 2023
1 parent 8880501 commit 6271f48
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
12 changes: 12 additions & 0 deletions parquet_integration/write_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ def case_nested() -> Tuple[dict, pa.Schema, str]:
]

decimal_nullable = [[Decimal(n) if n is not None else None for n in sublist] if sublist is not None else None for sublist in items_nullable]
decimal_nested = [
[[Decimal(0), Decimal(1)]],
None,
[[Decimal(2), None], [Decimal(3)]],
[[Decimal(4), Decimal(5)], [Decimal(6)]],
[],
[[Decimal(7)], None, [Decimal(9)]],
[[], [None], None],
[[Decimal(10)]],
]

list_struct_nullable = [
[{"a": "a"}, {"a": "b"}],
Expand Down Expand Up @@ -227,6 +237,7 @@ def case_nested() -> Tuple[dict, pa.Schema, str]:
pa.field("list_decimal", pa.list_(pa.decimal128(9, 0))),
pa.field("list_decimal256", pa.list_(pa.decimal256(9, 0))),
pa.field("list_nested_i64", pa.list_(pa.list_(pa.int64()))),
pa.field("list_nested_decimal", pa.list_(pa.list_(pa.decimal128(9, 0)))),
pa.field("list_nested_inner_required_i64", pa.list_(pa.list_(pa.int64()))),
pa.field(
"list_nested_inner_required_required_i64", pa.list_(pa.list_(pa.int64()))
Expand Down Expand Up @@ -258,6 +269,7 @@ def case_nested() -> Tuple[dict, pa.Schema, str]:
"list_decimal": decimal_nullable,
"list_decimal256": decimal_nullable,
"list_nested_i64": items_nested,
"list_nested_decimal": decimal_nested,
"list_nested_inner_required_i64": items_required_nested,
"list_nested_inner_required_required_i64": items_required_nested_2,
"list_struct_nullable": list_struct_nullable,
Expand Down
73 changes: 73 additions & 0 deletions tests/it/io/parquet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ pub fn pyarrow_nested_nullable(column: &str) -> Box<dyn Array> {
Box::new(array)
}
"list_nested_i64"
| "list_nested_decimal"
| "list_nested_inner_required_i64"
| "list_nested_inner_required_required_i64" => Box::new(NullArray::new(DataType::Null, 1)),
"struct_list_nullable" => pyarrow_nested_nullable("list_utf8"),
Expand Down Expand Up @@ -389,6 +390,48 @@ pub fn pyarrow_nested_nullable(column: &str) -> Box<dyn Array> {
let array: ListArray<i32> = a.into();
Box::new(array)
}
"list_nested_decimal" => {
// [
// [[Decimal(0), Decimal(1)]],
// None,
// [[Decimal(2), None], [Decimal(3)]],
// [[Decimal(4), Decimal(5)], [Decimal(6)]],
// [],
// [[Decimal(7)], None, [Decimal(9)]],
// [[], [None], None],
// [[Decimal(10)]],
// ]

let data = [
Some(vec![Some(vec![Some(0), Some(1)])]),
None,
Some(vec![Some(vec![Some(2), None]), Some(vec![Some(3)])]),
Some(vec![Some(vec![Some(4), Some(5)]), Some(vec![Some(6)])]),
Some(vec![]),
Some(vec![Some(vec![Some(7)]), None, Some(vec![Some(9)])]),
Some(vec![Some(vec![]), Some(vec![None]), None]),
Some(vec![Some(vec![Some(10)])]),
];

let inner_array = MutablePrimitiveArray::<i128>::from(DataType::Decimal(9, 0));
let middle_array = MutableListArray::<i32, MutablePrimitiveArray<i128>>::new_from(
inner_array.clone(),
ListArray::<i32>::default_datatype(inner_array.data_type().clone()),
0,
);
let mut outer_array = MutableListArray::<
i32,
MutableListArray<i32, MutablePrimitiveArray<i128>>,
>::new_from(
middle_array.clone(),
ListArray::<i32>::default_datatype(middle_array.data_type().clone()),
0,
);

outer_array.try_extend(data).unwrap();
let array: ListArray<i32> = outer_array.into();
Box::new(array)
}
"list_nested_inner_required_i64" => {
let data = [
Some(vec![Some(vec![Some(0), Some(1)])]),
Expand Down Expand Up @@ -948,6 +991,36 @@ pub fn pyarrow_nested_nullable_statistics(column: &str) -> Statistics {
)
.boxed(),
},
"list_nested_decimal" => Statistics {
distinct_count: new_list(
new_list(UInt64Array::from([None]).boxed(), true).boxed(),
true,
)
.boxed(),
null_count: new_list(
new_list(Box::new(UInt64Array::from_slice([7])), true).boxed(),
true,
)
.boxed(),
min_value: new_list(
new_list(
Box::new(Int128Array::from_slice([0]).to(DataType::Decimal(9, 0))),
true,
)
.boxed(),
true,
)
.boxed(),
max_value: new_list(
new_list(
Box::new(Int128Array::from_slice([10]).to(DataType::Decimal(9, 0))),
true,
)
.boxed(),
true,
)
.boxed(),
},
"list_nested_inner_required_required_i64" => Statistics {
distinct_count: UInt64Array::from([None]).boxed(),
null_count: UInt64Array::from([Some(0)]).boxed(),
Expand Down
5 changes: 5 additions & 0 deletions tests/it/io/parquet/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ fn v2_nested_nested() -> Result<()> {
test_pyarrow_integration("list_nested_i64", 2, "nested", false, false, None)
}

#[test]
fn v2_nested_nested_decimal() -> Result<()> {
test_pyarrow_integration("list_nested_decimal", 2, "nested", false, false, None)
}

#[test]
fn v2_nested_nested_required() -> Result<()> {
test_pyarrow_integration(
Expand Down

0 comments on commit 6271f48

Please sign in to comment.