Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions vortex-array/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,32 @@ use crate::scalar_fn::fns::root::Root;
impl dyn DynArray + '_ {
/// Apply the expression to this array, producing a new array in constant time.
pub fn apply(&self, expr: &Expression) -> VortexResult<ArrayRef> {
// If the expression is a root, return self.
if expr.is::<Root>() {
return Ok(self.to_array());
}

// Manually convert literals to ConstantArray.
if let Some(scalar) = expr.as_opt::<Literal>() {
return Ok(ConstantArray::new(scalar.clone(), self.len()).into_array());
}

// Otherwise, collect the child arrays.
let children: Vec<_> = expr
.children()
.iter()
.map(|e| self.apply(e))
.try_collect()?;

// And wrap the scalar function up in an array.
let array =
ScalarFnArray::try_new(expr.scalar_fn().clone(), children, self.len())?.into_array();

// Optimize the resulting array's root.
array.optimize()
apply_inner(&self.to_array(), expr)
}
}

fn apply_inner(array: &ArrayRef, expr: &Expression) -> VortexResult<ArrayRef> {
// If the expression is a root, return self — O(1) Arc clone.
if expr.is::<Root>() {
return Ok(array.clone());
}

// Manually convert literals to ConstantArray.
if let Some(scalar) = expr.as_opt::<Literal>() {
return Ok(ConstantArray::new(scalar.clone(), array.len()).into_array());
}

// Otherwise, collect the child arrays.
let children: Vec<_> = expr
.children()
.iter()
.map(|e| apply_inner(array, e))
.try_collect()?;

// And wrap the scalar function up in an array.
let result =
ScalarFnArray::try_new(expr.scalar_fn().clone(), children, array.len())?.into_array();

// Optimize the resulting array's root.
result.optimize()
}
Loading