• 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

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

4
use std::fmt::Display;
5
use std::sync::Arc;
6

7
use itertools::Itertools;
8
use parking_lot::RwLock;
9
use vortex_error::{VortexExpect, VortexResult, vortex_err};
10
use vortex_utils::aliases::hash_map::HashMap;
11

12
use crate::EncodingRef;
13
use crate::arrays::{
14
    BoolEncoding, ChunkedEncoding, ConstantEncoding, DecimalEncoding, ExtensionEncoding,
15
    ListEncoding, NullEncoding, PrimitiveEncoding, StructEncoding, VarBinEncoding,
16
    VarBinViewEncoding,
17
};
18

19
/// A collection of array encodings.
20
// TODO(ngates): it feels weird that this has interior mutability. I think maybe it shouldn't.
21
pub type ArrayContext = VTableContext<EncodingRef>;
22
pub type ArrayRegistry = VTableRegistry<EncodingRef>;
23

24
impl ArrayRegistry {
25
    pub fn canonical_only() -> Self {
2✔
26
        let mut this = Self::empty();
2✔
27

28
        // Register the canonical encodings
29
        this.register_many([
2✔
30
            EncodingRef::new_ref(NullEncoding.as_ref()) as EncodingRef,
2✔
31
            EncodingRef::new_ref(BoolEncoding.as_ref()),
2✔
32
            EncodingRef::new_ref(PrimitiveEncoding.as_ref()),
2✔
33
            EncodingRef::new_ref(DecimalEncoding.as_ref()),
2✔
34
            EncodingRef::new_ref(StructEncoding.as_ref()),
2✔
35
            EncodingRef::new_ref(ListEncoding.as_ref()),
2✔
36
            EncodingRef::new_ref(VarBinEncoding.as_ref()),
2✔
37
            EncodingRef::new_ref(VarBinViewEncoding.as_ref()),
2✔
38
            EncodingRef::new_ref(ExtensionEncoding.as_ref()),
2✔
39
        ]);
2✔
40

41
        // Register the utility encodings
42
        this.register_many([
2✔
43
            EncodingRef::new_ref(ConstantEncoding.as_ref()) as EncodingRef,
2✔
44
            EncodingRef::new_ref(ChunkedEncoding.as_ref()),
2✔
45
        ]);
2✔
46

47
        this
2✔
48
    }
2✔
49
}
50

51
/// A collection of encodings that can be addressed by a u16 positional index.
52
/// This is used to map array encodings and layout encodings when reading from a file.
53
#[derive(Debug, Clone)]
54
pub struct VTableContext<T>(Arc<RwLock<Vec<T>>>);
55

56
impl<T: Clone + Eq> VTableContext<T> {
57
    pub fn empty() -> Self {
8✔
58
        Self(Arc::new(RwLock::new(Vec::new())))
8✔
59
    }
8✔
60

61
    pub fn with(self, encoding: T) -> Self {
18✔
62
        {
63
            let mut write = self.0.write();
18✔
64
            if write.iter().all(|e| e != &encoding) {
36✔
65
                write.push(encoding);
18✔
66
            }
18✔
67
        }
68
        self
18✔
69
    }
18✔
70

71
    pub fn with_many<E: IntoIterator<Item = T>>(self, items: E) -> Self {
×
72
        items.into_iter().fold(self, |ctx, e| ctx.with(e))
×
73
    }
×
74

75
    pub fn encodings(&self) -> Vec<T> {
4✔
76
        self.0.read().clone()
4✔
77
    }
4✔
78

79
    /// Returns the index of the encoding in the context, or adds it if it doesn't exist.
80
    pub fn encoding_idx(&self, encoding: &T) -> u16 {
54✔
81
        let mut write = self.0.write();
54✔
82
        if let Some(idx) = write.iter().position(|e| e == encoding) {
172✔
83
            return u16::try_from(idx).vortex_expect("Cannot have more than u16::MAX encodings");
36✔
84
        }
18✔
85
        assert!(
18✔
86
            write.len() < u16::MAX as usize,
18✔
87
            "Cannot have more than u16::MAX encodings"
×
88
        );
89
        write.push(encoding.clone());
18✔
90
        u16::try_from(write.len() - 1).vortex_expect("checked already")
18✔
91
    }
54✔
92

93
    /// Find an encoding by its position.
94
    pub fn lookup_encoding(&self, idx: u16) -> Option<T> {
24✔
95
        self.0.read().get(idx as usize).cloned()
24✔
96
    }
24✔
97
}
98

99
/// A registry of encodings that can be used to construct a context for serde.
100
///
101
/// In the future, we will support loading encodings from shared libraries or even from within
102
/// the Vortex file itself. This registry will be used to manage the available encodings.
103
#[derive(Clone, Debug)]
104
pub struct VTableRegistry<T>(HashMap<String, T>);
105

106
// TODO(ngates): define a trait for `T` that requires an `id` method returning a `Arc<str>` and
107
//  auto-implement `Display` and `Eq` for it.
108
impl<T: Clone + Display + Eq> VTableRegistry<T> {
109
    pub fn empty() -> Self {
4✔
110
        Self(Default::default())
4✔
111
    }
4✔
112

113
    /// Create a new [`VTableContext`] with the provided encodings.
114
    pub fn new_context<'a>(
4✔
115
        &self,
4✔
116
        encoding_ids: impl Iterator<Item = &'a str>,
4✔
117
    ) -> VortexResult<VTableContext<T>> {
4✔
118
        let mut ctx = VTableContext::<T>::empty();
4✔
119
        for id in encoding_ids {
22✔
120
            let encoding = self.0.get(id).ok_or_else(|| {
18✔
121
                vortex_err!(
×
122
                    "Array encoding {} not found in registry {}",
×
123
                    id,
124
                    self.0.values().join(", ")
×
125
                )
126
            })?;
×
127
            ctx = ctx.with(encoding.clone());
18✔
128
        }
129
        Ok(ctx)
4✔
130
    }
4✔
131

132
    /// List the vtables in the registry.
133
    pub fn vtables(&self) -> impl Iterator<Item = &T> + '_ {
×
134
        self.0.values()
×
135
    }
×
136

137
    /// Find the encoding with the given ID.
UNCOV
138
    pub fn get(&self, id: &str) -> Option<&T> {
×
UNCOV
139
        self.0.get(id)
×
UNCOV
140
    }
×
141

142
    /// Register a new encoding, replacing any existing encoding with the same ID.
UNCOV
143
    pub fn register(&mut self, encoding: T) {
×
UNCOV
144
        self.0.insert(encoding.to_string(), encoding);
×
UNCOV
145
    }
×
146

147
    /// Register a new encoding, replacing any existing encoding with the same ID.
148
    pub fn register_many<I: IntoIterator<Item = T>>(&mut self, encodings: I) {
8✔
149
        self.0
8✔
150
            .extend(encodings.into_iter().map(|e| (e.to_string(), e)));
64✔
151
    }
8✔
152
}
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