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

vortex-data / vortex / 16935267080

13 Aug 2025 11:00AM UTC coverage: 24.312% (-63.3%) from 87.658%
16935267080

Pull #4226

github

web-flow
Merge 81b48c7fb into baa6ea202
Pull Request #4226: Support converting TimestampTZ to and from duckdb

0 of 2 new or added lines in 1 file covered. (0.0%)

20666 existing lines in 469 files now uncovered.

8726 of 35892 relevant lines covered (24.31%)

147.74 hits per line

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

70.69
/vortex-array/src/array/visitor.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::fmt::Formatter;
5
use std::ops::Deref;
6
use std::sync::Arc;
7

8
use vortex_buffer::ByteBuffer;
9
use vortex_error::VortexResult;
10

11
use crate::arrays::ConstantArray;
12
use crate::patches::Patches;
13
use crate::validity::Validity;
14
use crate::{Array, ArrayRef};
15

16
pub trait ArrayVisitor {
17
    /// Returns the children of the array.
18
    fn children(&self) -> Vec<ArrayRef>;
19

20
    /// Returns the number of children of the array.
21
    fn nchildren(&self) -> usize;
22

23
    /// Returns the names of the children of the array.
24
    fn children_names(&self) -> Vec<String>;
25

26
    /// Returns the array's children with their names.
27
    fn named_children(&self) -> Vec<(String, ArrayRef)>;
28

29
    /// Returns the buffers of the array.
30
    fn buffers(&self) -> Vec<ByteBuffer>;
31

32
    /// Returns the number of buffers of the array.
33
    fn nbuffers(&self) -> usize;
34

35
    /// Returns the serialized metadata of the array, or `None` if the array does not
36
    /// support serialization.
37
    fn metadata(&self) -> VortexResult<Option<Vec<u8>>>;
38

39
    /// Formats a human-readable metadata description.
40
    fn metadata_fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result;
41
}
42

43
impl ArrayVisitor for Arc<dyn Array> {
44
    fn children(&self) -> Vec<ArrayRef> {
434✔
45
        self.as_ref().children()
434✔
46
    }
434✔
47

48
    fn nchildren(&self) -> usize {
×
49
        self.as_ref().nchildren()
×
50
    }
×
51

UNCOV
52
    fn children_names(&self) -> Vec<String> {
×
UNCOV
53
        self.as_ref().children_names()
×
UNCOV
54
    }
×
55

56
    fn named_children(&self) -> Vec<(String, ArrayRef)> {
×
57
        self.as_ref().named_children()
×
58
    }
×
59

60
    fn buffers(&self) -> Vec<ByteBuffer> {
330✔
61
        self.as_ref().buffers()
330✔
62
    }
330✔
63

64
    fn nbuffers(&self) -> usize {
64✔
65
        self.as_ref().nbuffers()
64✔
66
    }
64✔
67

68
    fn metadata(&self) -> VortexResult<Option<Vec<u8>>> {
72✔
69
        self.as_ref().metadata()
72✔
70
    }
72✔
71

UNCOV
72
    fn metadata_fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
×
UNCOV
73
        self.as_ref().metadata_fmt(f)
×
UNCOV
74
    }
×
75
}
76

77
pub trait ArrayVisitorExt: Array {
78
    /// Count the number of buffers encoded by self and all child arrays.
79
    fn nbuffers_recursive(&self) -> usize {
32✔
80
        self.children()
32✔
81
            .iter()
32✔
82
            .map(ArrayVisitorExt::nbuffers_recursive)
32✔
83
            .sum::<usize>()
32✔
84
            + self.nbuffers()
32✔
85
    }
32✔
86

87
    /// Depth-first traversal of the array and its children.
88
    fn depth_first_traversal(&self) -> impl Iterator<Item = ArrayRef> {
224✔
89
        /// A depth-first pre-order iterator over an Array.
90
        struct ArrayChildrenIterator {
91
            stack: Vec<ArrayRef>,
92
        }
93

94
        impl Iterator for ArrayChildrenIterator {
95
            type Item = ArrayRef;
96

97
            fn next(&mut self) -> Option<Self::Item> {
594✔
98
                let next = self.stack.pop()?;
594✔
99
                for child in next.children().into_iter().rev() {
370✔
100
                    self.stack.push(child);
146✔
101
                }
146✔
102
                Some(next)
370✔
103
            }
594✔
104
        }
105

106
        ArrayChildrenIterator {
224✔
107
            stack: vec![self.to_array()],
224✔
108
        }
224✔
109
    }
224✔
110
}
111

112
impl<A: Array + ?Sized> ArrayVisitorExt for A {}
113

114
pub trait ArrayBufferVisitor {
115
    fn visit_buffer(&mut self, buffer: &ByteBuffer);
116
}
117

118
pub trait ArrayChildVisitor {
119
    /// Visit a child of this array.
120
    fn visit_child(&mut self, _name: &str, _array: &dyn Array);
121

122
    /// Utility for visiting Array validity.
123
    fn visit_validity(&mut self, validity: &Validity, len: usize) {
382✔
124
        if let Some(vlen) = validity.maybe_len() {
382✔
UNCOV
125
            assert_eq!(vlen, len, "Validity length mismatch");
×
126
        }
382✔
127

128
        match validity {
382✔
129
            Validity::NonNullable | Validity::AllValid => {}
382✔
130
            Validity::AllInvalid => {
131
                // To avoid storing metadata about validity, we store all invalid as a
132
                // constant array of false values.
133
                // This gives:
134
                //  * is_nullable & has_validity => Validity::Array (or Validity::AllInvalid)
135
                //  * is_nullable & !has_validity => Validity::AllValid
136
                //  * !is_nullable => Validity::NonNullable
UNCOV
137
                self.visit_child("validity", ConstantArray::new(false, len).deref())
×
138
            }
UNCOV
139
            Validity::Array(array) => {
×
UNCOV
140
                self.visit_child("validity", array);
×
UNCOV
141
            }
×
142
        }
143
    }
382✔
144

145
    /// Utility for visiting Array patches.
146
    fn visit_patches(&mut self, patches: &Patches) {
12✔
147
        self.visit_child("patch_indices", patches.indices());
12✔
148
        self.visit_child("patch_values", patches.values());
12✔
149
    }
12✔
150
}
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