Skip to content

Commit b8a7b74

Browse files
committed
some stuff and rebase
1 parent f1bcd9b commit b8a7b74

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

vortex-datafusion/src/convert/exprs.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::sync::Arc;
55

66
use arrow_schema::{DataType, Schema};
7+
use datafusion_common::ScalarValue;
78
use datafusion_expr::Operator as DFOperator;
89
use datafusion_functions::core::getfield::GetFieldFunc;
910
use datafusion_physical_expr::{PhysicalExpr, PhysicalExprRef, ScalarFunctionExpr};
@@ -24,26 +25,42 @@ use vortex::scalar::Scalar;
2425

2526
use crate::convert::{FromDataFusion, TryFromDataFusion};
2627

28+
fn is_lit_true(e: &PhysicalExprRef) -> bool {
29+
e.as_any()
30+
.downcast_ref::<df_expr::Literal>()
31+
.is_some_and(|l| matches!(l.value(), ScalarValue::Boolean(Some(true))))
32+
}
33+
2734
/// Tries to convert the expressions into a vortex conjunction. Will return Ok(None) iff the input conjunction is empty.
2835
pub(crate) fn make_vortex_predicate(
2936
predicate: &[Arc<dyn PhysicalExpr>],
3037
) -> VortexResult<Option<Expression>> {
3138
let exprs = predicate
3239
.iter()
33-
.filter_map(|e| {
34-
if is_dynamic_physical_expr(e) {
35-
snapshot_physical_expr(e.clone()).ok().and_then(|e| {
36-
match Expression::try_from_df(e.as_ref()) {
37-
Ok(e) => Some(Ok(e)),
38-
Err(_) => {
39-
// If we fail to convert the expression to Vortex, its safe
40-
// to drop it as we don't declare it as pushed down
41-
None
42-
}
43-
}
44-
})
40+
.filter_map(|expr| {
41+
// Handle dynamic expressions by snapshotting them first
42+
let expr_to_convert = if is_dynamic_physical_expr(expr) {
43+
// If snapshot fails, filter out this expression
44+
let snapshot = snapshot_physical_expr(expr.clone()).ok()?;
45+
46+
// Filter out literal true expressions (they don't add constraints)
47+
if is_lit_true(&snapshot) {
48+
return None;
49+
}
50+
51+
snapshot
4552
} else {
46-
Some(Expression::try_from_df(e.as_ref()))
53+
expr.clone()
54+
};
55+
56+
// Try to convert to Vortex expression
57+
match Expression::try_from_df(expr_to_convert.as_ref()) {
58+
Ok(vortex_expr) => Some(Ok(vortex_expr)),
59+
Err(_) => {
60+
// If we fail to convert the expression to Vortex, it's safe
61+
// to drop it as we don't declare it as pushed down
62+
None
63+
}
4764
}
4865
})
4966
.collect::<VortexResult<Vec<_>>>()?;

0 commit comments

Comments
 (0)