Skip to content

Commit f7025c4

Browse files
committed
wip
Signed-off-by: Joe Isaacs <[email protected]>
1 parent c2cd0ab commit f7025c4

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

encodings/alp/src/alp/compute/expr_pushdown.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,10 @@ impl ArrayParentReduceRule<ALPVTable, ExprVTable> for ALPExprPushdownRule {
4949
_child_idx: usize,
5050
_ctx: &ArrayRuleContext,
5151
) -> VortexResult<Option<ArrayRef>> {
52-
// Only optimize if there are no patches
53-
if alp.patches().is_some() {
52+
if alp.patches().is_some() || parent.dtype().is_nullable() || alp.dtype().is_nullable() {
5453
return Ok(None);
5554
}
5655

57-
// Only optimize if the array is not nullable
58-
if alp.dtype().is_nullable() {
59-
return Ok(None);
60-
}
61-
62-
// Check if the expression is a binary comparison
6356
let Some(binary_view) = parent.expr().as_opt::<Binary>() else {
6457
return Ok(None);
6558
};
@@ -90,19 +83,20 @@ impl ArrayParentReduceRule<ALPVTable, ExprVTable> for ALPExprPushdownRule {
9083
};
9184

9285
// Check if this is a comparison of root() with a literal
93-
// For simplicity, we only handle `root() op literal` (not swapped)
94-
if !binary_view.lhs().is::<Root>() {
95-
return Ok(None);
96-
}
97-
if !binary_view.rhs().is::<Literal>() {
98-
return Ok(None);
99-
}
86+
// Handle both `root() op literal` and `literal op root()` (swapped)
87+
let (literal_expr, compute_op) =
88+
if binary_view.lhs().is::<Root>() && binary_view.rhs().is::<Literal>() {
89+
// Normal case: root() op literal
90+
(binary_view.rhs(), compute_op)
91+
} else if binary_view.lhs().is::<Literal>() && binary_view.rhs().is::<Root>() {
92+
// Swapped case: literal op root() -> swap operator
93+
(binary_view.lhs(), compute_op.swap())
94+
} else {
95+
return Ok(None);
96+
};
10097

10198
// Get the literal scalar - literals evaluate to a constant array with one element
102-
let literal_array = binary_view.rhs().evaluate(&alp.clone().into_array())?;
103-
let Some(literal_value) = literal_array.as_constant() else {
104-
return Ok(None);
105-
};
99+
let literal_value = literal_expr.as_::<Literal>().data().clone();
106100

107101
// Don't optimize nullable comparisons
108102
if literal_value.dtype().is_nullable() {

0 commit comments

Comments
 (0)