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

vortex-data / vortex / 16440250234

22 Jul 2025 09:25AM UTC coverage: 81.473% (-0.07%) from 81.54%
16440250234

push

github

web-flow
feat: Refactor traversal logic (#3926)

The main rationale for this change is that I would like to use this
logic elsewhere, but it wasn't touched in a while and needed some
polishing.

I've moved most of the code that deals with actually applying operations
in a certain order into the default implementation of `Node::accept`,
`Node::rewrite` and the `transform_` functions.
A future user of `Node` will only need to fill in the structure of their
tree, getting the fiddly bits OOTB.

This is not a fully-fledged solution for any possible usecase, but its
an attempt at tightening the existing abstractions and leaving something
that could be extended to new or more advanced patterns.

---------

Signed-off-by: Adam Gutglick <adam@spiraldb.com>

254 of 298 new or added lines in 8 files covered. (85.23%)

8 existing lines in 3 files now uncovered.

41953 of 51493 relevant lines covered (81.47%)

171685.53 hits per line

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

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

4
use std::fmt::Display;
5

6
use vortex_array::stats::Stat;
7
use vortex_array::{ArrayRef, DeserializeMetadata, EmptyMetadata};
8
use vortex_dtype::{DType, FieldPath};
9
use vortex_error::{VortexResult, vortex_bail};
10

11
use crate::{
12
    AnalysisExpr, ExprEncodingRef, ExprId, ExprRef, IntoExpr, Scope, StatsCatalog, VTable, vtable,
13
};
14

15
vtable!(Root);
16

17
/// An expression that returns the full scope of the expression evaluation.
18
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
19
pub struct RootExpr;
20

21
pub struct RootExprEncoding;
22

23
impl VTable for RootVTable {
24
    type Expr = RootExpr;
25
    type Encoding = RootExprEncoding;
26
    type Metadata = EmptyMetadata;
27

28
    fn id(_encoding: &Self::Encoding) -> ExprId {
131✔
29
        ExprId::new_ref("root")
131✔
30
    }
131✔
31

32
    fn encoding(_expr: &Self::Expr) -> ExprEncodingRef {
3✔
33
        ExprEncodingRef::new_ref(RootExprEncoding.as_ref())
3✔
34
    }
3✔
35

36
    fn metadata(_expr: &Self::Expr) -> Option<Self::Metadata> {
3✔
37
        Some(EmptyMetadata)
3✔
38
    }
3✔
39

40
    fn children(_expr: &Self::Expr) -> Vec<&ExprRef> {
176,023✔
41
        vec![]
176,023✔
42
    }
176,023✔
43

UNCOV
44
    fn with_children(expr: &Self::Expr, _children: Vec<ExprRef>) -> VortexResult<Self::Expr> {
×
UNCOV
45
        Ok(expr.clone())
×
UNCOV
46
    }
×
47

48
    fn build(
3✔
49
        _encoding: &Self::Encoding,
3✔
50
        _metadata: &<Self::Metadata as DeserializeMetadata>::Output,
3✔
51
        children: Vec<ExprRef>,
3✔
52
    ) -> VortexResult<Self::Expr> {
3✔
53
        if !children.is_empty() {
3✔
54
            vortex_bail!(
×
55
                "Root expression does not have children, got: {:?}",
×
56
                children
57
            );
58
        }
3✔
59
        Ok(RootExpr)
3✔
60
    }
3✔
61

62
    fn evaluate(_expr: &Self::Expr, scope: &Scope) -> VortexResult<ArrayRef> {
16,491✔
63
        Ok(scope.root().clone())
16,491✔
64
    }
16,491✔
65

66
    fn return_dtype(_expr: &Self::Expr, scope: &DType) -> VortexResult<DType> {
30,743✔
67
        Ok(scope.clone())
30,743✔
68
    }
30,743✔
69
}
70

71
impl Display for RootExpr {
72
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
540✔
73
        write!(f, "$")
540✔
74
    }
540✔
75
}
76

77
impl AnalysisExpr for RootExpr {
78
    fn max(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
521✔
79
        catalog.stats_ref(&self.field_path()?, Stat::Max)
521✔
80
    }
521✔
81

82
    fn min(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
399✔
83
        catalog.stats_ref(&self.field_path()?, Stat::Min)
399✔
84
    }
399✔
85

86
    fn field_path(&self) -> Option<FieldPath> {
941✔
87
        Some(FieldPath::root())
941✔
88
    }
941✔
89
}
90

91
/// Return a global pointer to the identity token.
92
/// This is the name of the data found in a vortex array or file.
93
pub fn root() -> ExprRef {
31,553✔
94
    RootExpr.into_expr()
31,553✔
95
}
31,553✔
96

97
/// Return whether the expression is a root expression.
98
pub fn is_root(expr: &ExprRef) -> bool {
34,099✔
99
    expr.is::<RootVTable>()
34,099✔
100
}
34,099✔
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

© 2025 Coveralls, Inc