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

vortex-data / vortex / 16419023817

21 Jul 2025 01:56PM UTC coverage: 81.673%. First build
16419023817

Pull #3876

github

web-flow
Merge 3389f94e0 into 56156aa03
Pull Request #3876: feat[layout]: replace register_splits with a layout splits stream

726 of 777 new or added lines in 17 files covered. (93.44%)

42577 of 52131 relevant lines covered (81.67%)

169631.2 hits per line

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

88.0
/vortex-scan/src/selection.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::ops::Range;
5
use std::sync::Arc;
6

7
use roaring::RoaringTreemap;
8
use vortex_buffer::Buffer;
9
use vortex_layout::tree_row_mask::TreeRowMask;
10

11
/// A selection identifies a set of rows to include in the scan (in addition to applying any
12
/// filter predicates).
13
#[derive(Default, Clone)]
14
pub enum Selection {
15
    /// No selection, all rows are included.
16
    #[default]
17
    All,
18
    // TODO(joe): replace this with IncludeRoaring
19
    /// A selection of rows to include by index.
20
    IncludeByIndex(Buffer<u64>),
21
    /// A selection of rows to exclude by index.
22
    ExcludeByIndex(Buffer<u64>),
23
    /// A selection of rows to include using a [`roaring::RoaringTreemap`].
24
    IncludeRoaring(Arc<RoaringTreemap>),
25
    /// A selection of rows to exclude using a [`roaring::RoaringTreemap`].
26
    ExcludeRoaring(Arc<RoaringTreemap>),
27
}
28

29
impl Selection {
30
    pub fn tree_row_mask(&self, length: u64, range: Option<Range<u64>>) -> TreeRowMask {
1,398✔
31
        let row_mask = TreeRowMask::all(length);
1,398✔
32

33
        let row_mask = if let Some(range) = range {
1,398✔
34
            row_mask.with_range(range)
358✔
35
        } else {
36
            row_mask
1,040✔
37
        };
38

39
        match &self {
1,398✔
40
            Selection::All => row_mask,
1,248✔
41
            Selection::IncludeByIndex(indices) => {
150✔
42
                let mut treemap = RoaringTreemap::new();
150✔
43
                for idx in indices.iter() {
18,454✔
44
                    treemap.insert(*idx);
18,454✔
45
                }
18,454✔
46
                row_mask.with_treemap(Arc::new(treemap))
150✔
47
            }
NEW
48
            Selection::ExcludeByIndex(indices) => {
×
NEW
49
                let mut treemap = RoaringTreemap::new();
×
NEW
50
                for idx in indices.iter() {
×
NEW
51
                    treemap.insert(*idx);
×
52
                }
×
NEW
53
                row_mask.with_treemap(Arc::new(treemap)).with_exclude()
×
54
            }
NEW
55
            Selection::IncludeRoaring(treemap) => row_mask.with_treemap(treemap.clone()),
×
NEW
56
            Selection::ExcludeRoaring(treemap) => {
×
NEW
57
                row_mask.with_treemap(treemap.clone()).with_exclude()
×
58
            }
59
        }
60
    }
1,398✔
61
}
62

63
#[cfg(test)]
64
mod tests {
65
    use vortex_buffer::Buffer;
66
    use vortex_error::VortexResult;
67
    use vortex_mask::Mask;
68

69
    use super::Selection;
70

71
    #[test]
72
    fn test_row_mask_all() {
1✔
73
        let selection = Selection::IncludeByIndex(Buffer::from_iter(vec![1, 3, 5, 7]));
1✔
74
        let range = 1..8;
1✔
75
        let mask = selection.tree_row_mask(7, Some(range.clone())).slice(range);
1✔
76

77
        println!(
1✔
78
            "{:?}",
1✔
79
            mask.mask()
1✔
80
                .collect::<VortexResult<Mask>>()
1✔
81
                .unwrap()
1✔
82
                .to_vec()
1✔
83
        );
84

85
        assert_eq!(
1✔
86
            mask.mask().collect::<VortexResult<Mask>>().unwrap(),
1✔
87
            Mask::from_indices(7, vec![0, 2, 4, 6])
1✔
88
        );
89
    }
1✔
90

91
    #[test]
92
    fn test_row_mask_slice() {
1✔
93
        let selection = Selection::IncludeByIndex(Buffer::from_iter(vec![1, 3, 5, 7]));
1✔
94
        let range = 3..6;
1✔
95
        let mask = selection.tree_row_mask(3, Some(range.clone())).slice(range);
1✔
96

97
        assert_eq!(
1✔
98
            mask.mask().collect::<VortexResult<Mask>>().unwrap(),
1✔
99
            Mask::from_indices(3, vec![0, 2])
1✔
100
        );
101
    }
1✔
102

103
    #[test]
104
    fn test_row_mask_exclusive() {
1✔
105
        let selection = Selection::IncludeByIndex(Buffer::from_iter(vec![1, 3, 5, 7]));
1✔
106
        let range = 3..5;
1✔
107
        let mask = selection.tree_row_mask(2, Some(range.clone())).slice(range);
1✔
108

109
        assert_eq!(
1✔
110
            mask.mask().collect::<VortexResult<Mask>>().unwrap(),
1✔
111
            Mask::from_indices(2, vec![0])
1✔
112
        );
113
    }
1✔
114

115
    #[test]
116
    fn test_row_mask_all_false() {
1✔
117
        let selection = Selection::IncludeByIndex(Buffer::from_iter(vec![1, 3, 5, 7]));
1✔
118
        let range = 8..10;
1✔
119
        let mask = selection.tree_row_mask(2, Some(range.clone())).slice(range);
1✔
120

121
        assert_eq!(
1✔
122
            mask.mask().collect::<VortexResult<Mask>>().unwrap(),
1✔
123
            Mask::AllFalse(2)
124
        );
125
    }
1✔
126

127
    #[test]
128
    fn test_row_mask_all_true() {
1✔
129
        let selection = Selection::IncludeByIndex(Buffer::from_iter(vec![1, 3, 4, 5, 6]));
1✔
130
        let range = 3..7;
1✔
131
        let mask = selection.tree_row_mask(4, Some(range.clone())).slice(range);
1✔
132

133
        assert_eq!(
1✔
134
            mask.mask().collect::<VortexResult<Mask>>().unwrap(),
1✔
135
            Mask::AllTrue(4)
136
        );
137
    }
1✔
138

139
    #[test]
140
    fn test_row_mask_zero() {
1✔
141
        let selection = Selection::IncludeByIndex(Buffer::from_iter(vec![0]));
1✔
142
        let range = 0..5;
1✔
143
        let mask = selection.tree_row_mask(5, Some(range.clone())).slice(range);
1✔
144

145
        assert_eq!(
1✔
146
            mask.mask().collect::<VortexResult<Mask>>().unwrap(),
1✔
147
            Mask::from_indices(5, vec![0])
1✔
148
        );
149
    }
1✔
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