Skip to content

Commit 44a02f3

Browse files
add test showing list predicate wrapping
1 parent 156b5dc commit 44a02f3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

datafusion/datasource-parquet/src/row_filter.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ mod test {
935935
};
936936
use arrow::datatypes::{Field, TimeUnit::Nanosecond};
937937
use datafusion_expr::{Expr, col};
938+
use datafusion_functions::core::get_field;
938939
use datafusion_functions_nested::array_has::{
939940
array_has_all_udf, array_has_any_udf, array_has_udf,
940941
};
@@ -1493,6 +1494,41 @@ mod test {
14931494
assert!(!can_expr_be_pushed_down_with_schemas(&expr, &table_schema));
14941495
}
14951496

1497+
/// get_field returning a list inside a struct should allow pushdown when
1498+
/// wrapped in a supported list predicate like `array_has_any`.
1499+
/// e.g. `array_has_any(get_field(s, 'items'), make_array('x'))`
1500+
#[test]
1501+
fn get_field_list_leaf_with_array_predicate_allows_pushdown() {
1502+
let item_field = Arc::new(Field::new("item", DataType::Utf8, true));
1503+
let table_schema = Arc::new(Schema::new(vec![Field::new(
1504+
"s",
1505+
DataType::Struct(
1506+
vec![
1507+
Arc::new(Field::new("id", DataType::Int32, true)),
1508+
Arc::new(Field::new("items", DataType::List(item_field), true)),
1509+
]
1510+
.into(),
1511+
),
1512+
true,
1513+
)]));
1514+
1515+
// array_has_any(get_field(s, 'items'), make_array('x'))
1516+
let get_field_expr = get_field().call(vec![
1517+
col("s"),
1518+
Expr::Literal(ScalarValue::Utf8(Some("items".to_string())), None),
1519+
]);
1520+
let expr = array_has_any(
1521+
get_field_expr,
1522+
make_array(vec![Expr::Literal(
1523+
ScalarValue::Utf8(Some("x".to_string())),
1524+
None,
1525+
)]),
1526+
);
1527+
let expr = logical2physical(&expr, &table_schema);
1528+
1529+
assert!(can_expr_be_pushed_down_with_schemas(&expr, &table_schema));
1530+
}
1531+
14961532
/// get_field on a struct produces correct Parquet leaf indices.
14971533
#[test]
14981534
fn get_field_filter_candidate_has_correct_leaf_indices() {

0 commit comments

Comments
 (0)