Skip to content

Commit 31586f3

Browse files
committed
expr test
Signed-off-by: Onur Satici <onur@spiraldb.com>
1 parent db00b43 commit 31586f3

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

vortex-array/src/expression.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,32 @@ use crate::scalar_fn::fns::root::Root;
1717
impl dyn DynArray + '_ {
1818
/// Apply the expression to this array, producing a new array in constant time.
1919
pub fn apply(&self, expr: &Expression) -> VortexResult<ArrayRef> {
20-
// If the expression is a root, return self.
21-
if expr.is::<Root>() {
22-
return Ok(self.to_array());
23-
}
24-
25-
// Manually convert literals to ConstantArray.
26-
if let Some(scalar) = expr.as_opt::<Literal>() {
27-
return Ok(ConstantArray::new(scalar.clone(), self.len()).into_array());
28-
}
29-
30-
// Otherwise, collect the child arrays.
31-
let children: Vec<_> = expr
32-
.children()
33-
.iter()
34-
.map(|e| self.apply(e))
35-
.try_collect()?;
36-
37-
// And wrap the scalar function up in an array.
38-
let array =
39-
ScalarFnArray::try_new(expr.scalar_fn().clone(), children, self.len())?.into_array();
40-
41-
// Optimize the resulting array's root.
42-
array.optimize()
20+
apply_inner(&self.to_array(), expr)
4321
}
4422
}
23+
24+
fn apply_inner(array: &ArrayRef, expr: &Expression) -> VortexResult<ArrayRef> {
25+
// If the expression is a root, return self — O(1) Arc clone.
26+
if expr.is::<Root>() {
27+
return Ok(array.clone());
28+
}
29+
30+
// Manually convert literals to ConstantArray.
31+
if let Some(scalar) = expr.as_opt::<Literal>() {
32+
return Ok(ConstantArray::new(scalar.clone(), array.len()).into_array());
33+
}
34+
35+
// Otherwise, collect the child arrays.
36+
let children: Vec<_> = expr
37+
.children()
38+
.iter()
39+
.map(|e| apply_inner(array, e))
40+
.try_collect()?;
41+
42+
// And wrap the scalar function up in an array.
43+
let result =
44+
ScalarFnArray::try_new(expr.scalar_fn().clone(), children, array.len())?.into_array();
45+
46+
// Optimize the resulting array's root.
47+
result.optimize()
48+
}

0 commit comments

Comments
 (0)