Skip to content

Commit 86e72d8

Browse files
committed
[Variant] Add path index access tests for list
1 parent 4cd2d14 commit 86e72d8

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

parquet-variant-compute/src/variant_get.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4163,8 +4163,8 @@ mod test {
41634163
#[test]
41644164
fn test_variant_get_list_like_safe_cast() {
41654165
let string_array: ArrayRef = Arc::new(StringArray::from(vec![
4166-
r#"[1, "two", 3]"#,
4167-
"\"not a list\"",
4166+
r#"{"outer":{"list":[1, "two", 3]}}"#,
4167+
r#"{"outer":{"list":"not a list"}}"#,
41684168
]));
41694169
let variant_array = ArrayRef::from(json_to_variant(&string_array).unwrap());
41704170

@@ -4237,16 +4237,34 @@ mod test {
42374237
];
42384238

42394239
for (request_type, expected) in expectations {
4240-
let options = GetOptions::new().with_as_type(Some(FieldRef::from(Field::new(
4241-
"result",
4242-
request_type.clone(),
4243-
true,
4244-
))));
4240+
let options = GetOptions::new_with_path(VariantPath::from("outer").join("list"))
4241+
.with_as_type(Some(FieldRef::from(Field::new(
4242+
"result",
4243+
request_type.clone(),
4244+
true,
4245+
))));
42454246

42464247
let result = variant_get(&variant_array, options).unwrap();
42474248
assert_eq!(result.data_type(), expected.data_type());
42484249
assert_eq!(&result, &expected);
42494250
}
4251+
4252+
for (idx, expected) in [
4253+
(0, vec![Some(1), None]),
4254+
(1, vec![None, None]),
4255+
(2, vec![Some(3), None]),
4256+
] {
4257+
let index_options =
4258+
GetOptions::new_with_path(VariantPath::from("outer").join("list").join(idx))
4259+
.with_as_type(Some(FieldRef::from(Field::new(
4260+
"result",
4261+
DataType::Int64,
4262+
true,
4263+
))));
4264+
let index_result = variant_get(&variant_array, index_options).unwrap();
4265+
let index_expected: ArrayRef = Arc::new(Int64Array::from(expected));
4266+
assert_eq!(&index_result, &index_expected);
4267+
}
42504268
}
42514269

42524270
#[test]

0 commit comments

Comments
 (0)