-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathexpression.rs
More file actions
46 lines (38 loc) · 1.42 KB
/
expression.rs
File metadata and controls
46 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use std::sync::Arc;
use itertools::Itertools;
use vortex_error::VortexResult;
use crate::ArrayRef;
use crate::DynArray;
use crate::IntoArray;
use crate::arrays::ConstantArray;
use crate::arrays::ScalarFnArray;
use crate::expr::Expression;
use crate::optimizer::ArrayOptimizer;
use crate::scalar_fn::fns::literal::Literal;
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: Arc<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.clone().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()
}
}