• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16204612549

10 Jul 2025 07:50PM UTC coverage: 81.152% (+2.9%) from 78.263%
16204612549

Pull #3825

github

web-flow
Merge d0d2717da into be9c2fd3e
Pull Request #3825: feat: Add optimize ArrayOp with VBView implementation

178 of 211 new or added lines in 4 files covered. (84.36%)

330 existing lines in 34 files now uncovered.

45433 of 55985 relevant lines covered (81.15%)

145951.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.68
/vortex-expr/src/scope.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::any::TypeId;
5
use std::ops::Deref;
6

7
use vortex_array::arrays::StructArray;
8
use vortex_array::{ArrayRef, IntoArray};
9

10
use crate::scope_vars::{ScopeVar, ScopeVars};
11

12
/// Scope define the evaluation context/scope that an expression uses when being evaluated.
13
/// There is a special `Identifier` (`Identity`) which is used to bind the initial array being evaluated
14
///
15
/// Other identifier can be bound with variables either before execution or while executing (see `Let`).
16
/// Values can be extracted from the scope using the `Var` expression.
17
///
18
/// ```code
19
/// <let x = lit(1) in var(Identifier::Identity) + var(x), { Identity -> Primitive[1,2,3]> ->
20
/// <var(Identifier::Identity) + var(x), { Identity -> Primitive[1,2,3], x -> ConstantArray(1)> ->
21
/// <Primitive[1,2,3] + var(x), { Identity -> Primitive[1,2,3], x -> ConstantArray(1)> ->
22
/// <Primitive[1,2,3] + ConstantArray(1), { Identity -> Primitive[1,2,3], x -> ConstantArray(1)> ->
23
/// <Primitive[2,3,4], { Identity -> Primitive[1,2,3], x -> ConstantArray(1)>
24
/// ```
25
///
26
/// Other values can be bound before execution e.g.
27
///  `<var("x") + var("y") + var("z"), x -> ..., y -> ..., z -> ...>`
28
#[derive(Clone)]
29
pub struct Scope {
30
    root: ArrayRef,
31
    /// Variables that can be set on the scope during expression evaluation.
32
    scope_vars: ScopeVars,
33
}
34

35
impl Scope {
36
    /// Create a new scope with the given root array.
37
    pub fn new(root: ArrayRef) -> Self {
11,034✔
38
        Self {
11,034✔
39
            root,
11,034✔
40
            scope_vars: Default::default(),
11,034✔
41
        }
11,034✔
42
    }
11,034✔
43

44
    /// Create a new scope with the root array set an empty struct.
45
    pub fn empty(len: usize) -> Self {
1✔
46
        Self::new(StructArray::new_with_len(len).into_array())
1✔
47
    }
1✔
48

49
    /// Return the root array of the scope.
50
    pub fn root(&self) -> &ArrayRef {
15,194✔
51
        &self.root
15,194✔
52
    }
15,194✔
53

54
    /// Returns a new evaluation scope with the given variable applied.
55
    pub fn with_scope_var<V: ScopeVar>(mut self, var: V) -> Self {
1✔
56
        self.scope_vars.insert(TypeId::of::<V>(), Box::new(var));
1✔
57
        self
1✔
58
    }
1✔
59

60
    /// Returns the scope variable of type `V` if it exists.
61
    pub fn scope_var<V: ScopeVar>(&self) -> Option<&V> {
3✔
62
        self.scope_vars
3✔
63
            .get(&TypeId::of::<V>())
3✔
64
            .and_then(|boxed| (**boxed).as_any().downcast_ref::<V>())
3✔
65
    }
3✔
66

67
    /// Returns the mutable scope variable of type `V` if it exists.
68
    pub fn scope_var_mut<V: ScopeVar>(&mut self) -> Option<&mut V> {
1✔
69
        self.scope_vars
1✔
70
            .get_mut(&TypeId::of::<V>())
1✔
71
            .and_then(|boxed| (**boxed).as_any_mut().downcast_mut::<V>())
1✔
72
    }
1✔
73
}
74

75
impl Deref for Scope {
76
    type Target = ArrayRef;
77

78
    fn deref(&self) -> &Self::Target {
22,344✔
79
        &self.root
22,344✔
80
    }
22,344✔
81
}
82

83
impl From<ArrayRef> for Scope {
UNCOV
84
    fn from(value: ArrayRef) -> Self {
×
UNCOV
85
        Self::new(value)
×
UNCOV
86
    }
×
87
}
88

89
#[cfg(test)]
90
mod test {
91
    #[test]
92
    fn test_scope_var() {
1✔
93
        use super::*;
94

95
        #[derive(Clone, PartialEq, Eq, Debug)]
96
        struct TestVar {
97
            value: i32,
98
        }
99

100
        let scope = Scope::empty(100);
1✔
101
        assert!(scope.scope_var::<TestVar>().is_none());
1✔
102

103
        let var = TestVar { value: 42 };
1✔
104
        let mut scope = scope.with_scope_var(var.clone());
1✔
105
        assert_eq!(scope.scope_var::<TestVar>(), Some(&var));
1✔
106

107
        scope.scope_var_mut::<TestVar>().unwrap().value = 43;
1✔
108
        assert_eq!(scope.scope_var::<TestVar>(), Some(&TestVar { value: 43 }));
1✔
109
    }
1✔
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc