• 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

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

4
use std::sync::LazyLock;
5

6
use arcref::ArcRef;
7
use vortex_dtype::DType;
8
use vortex_error::{VortexError, VortexResult, vortex_bail, vortex_err, vortex_panic};
9

10
use crate::compute::{ComputeFn, ComputeFnVTable, InvocationArgs, Kernel, Output, UnaryArgs};
11
use crate::vtable::VTable;
12
use crate::{Array, ArrayRef, IntoArray, ToCanonical};
13

UNCOV
14
static INVERT_FN: LazyLock<ComputeFn> = LazyLock::new(|| {
×
UNCOV
15
    let compute = ComputeFn::new("invert".into(), ArcRef::new_ref(&Invert));
×
UNCOV
16
    for kernel in inventory::iter::<InvertKernelRef> {
×
UNCOV
17
        compute.register_kernel(kernel.0.clone());
×
UNCOV
18
    }
×
UNCOV
19
    compute
×
UNCOV
20
});
×
21

22
/// Logically invert a boolean array, preserving its validity.
UNCOV
23
pub fn invert(array: &dyn Array) -> VortexResult<ArrayRef> {
×
UNCOV
24
    INVERT_FN
×
UNCOV
25
        .invoke(&InvocationArgs {
×
UNCOV
26
            inputs: &[array.into()],
×
UNCOV
27
            options: &(),
×
UNCOV
28
        })?
×
UNCOV
29
        .unwrap_array()
×
UNCOV
30
}
×
31

32
struct Invert;
33

34
impl ComputeFnVTable for Invert {
UNCOV
35
    fn invoke(
×
UNCOV
36
        &self,
×
UNCOV
37
        args: &InvocationArgs,
×
UNCOV
38
        kernels: &[ArcRef<dyn Kernel>],
×
UNCOV
39
    ) -> VortexResult<Output> {
×
UNCOV
40
        let UnaryArgs { array, .. } = UnaryArgs::<()>::try_from(args)?;
×
41

UNCOV
42
        for kernel in kernels {
×
UNCOV
43
            if let Some(output) = kernel.invoke(args)? {
×
UNCOV
44
                return Ok(output);
×
UNCOV
45
            }
×
46
        }
UNCOV
47
        if let Some(output) = array.invoke(&INVERT_FN, args)? {
×
48
            return Ok(output);
×
UNCOV
49
        }
×
50

51
        // Otherwise, we canonicalize into a boolean array and invert.
UNCOV
52
        log::debug!(
×
53
            "No invert implementation found for encoding {}",
×
54
            array.encoding_id(),
×
55
        );
UNCOV
56
        if array.is_canonical() {
×
57
            vortex_panic!("Canonical bool array does not implement invert");
×
UNCOV
58
        }
×
UNCOV
59
        Ok(invert(&array.to_bool()?.into_array())?.into())
×
UNCOV
60
    }
×
61

UNCOV
62
    fn return_dtype(&self, args: &InvocationArgs) -> VortexResult<DType> {
×
UNCOV
63
        let UnaryArgs { array, .. } = UnaryArgs::<()>::try_from(args)?;
×
64

UNCOV
65
        if !matches!(array.dtype(), DType::Bool(..)) {
×
66
            vortex_bail!("Expected boolean array, got {}", array.dtype());
×
UNCOV
67
        }
×
UNCOV
68
        Ok(array.dtype().clone())
×
UNCOV
69
    }
×
70

UNCOV
71
    fn return_len(&self, args: &InvocationArgs) -> VortexResult<usize> {
×
UNCOV
72
        let UnaryArgs { array, .. } = UnaryArgs::<()>::try_from(args)?;
×
UNCOV
73
        Ok(array.len())
×
UNCOV
74
    }
×
75

UNCOV
76
    fn is_elementwise(&self) -> bool {
×
UNCOV
77
        true
×
UNCOV
78
    }
×
79
}
80

81
struct InvertArgs<'a> {
82
    array: &'a dyn Array,
83
}
84

85
impl<'a> TryFrom<&InvocationArgs<'a>> for InvertArgs<'a> {
86
    type Error = VortexError;
87

UNCOV
88
    fn try_from(value: &InvocationArgs<'a>) -> Result<Self, Self::Error> {
×
UNCOV
89
        if value.inputs.len() != 1 {
×
90
            vortex_bail!("Invert expects exactly one argument",);
×
UNCOV
91
        }
×
UNCOV
92
        let array = value.inputs[0]
×
UNCOV
93
            .array()
×
UNCOV
94
            .ok_or_else(|| vortex_err!("Invert expects an array argument"))?;
×
UNCOV
95
        Ok(InvertArgs { array })
×
UNCOV
96
    }
×
97
}
98

99
pub struct InvertKernelRef(ArcRef<dyn Kernel>);
100
inventory::collect!(InvertKernelRef);
101

102
pub trait InvertKernel: VTable {
103
    /// Logically invert a boolean array. Converts true -> false, false -> true, null -> null.
104
    fn invert(&self, array: &Self::Array) -> VortexResult<ArrayRef>;
105
}
106

107
#[derive(Debug)]
108
pub struct InvertKernelAdapter<V: VTable>(pub V);
109

110
impl<V: VTable + InvertKernel> InvertKernelAdapter<V> {
111
    pub const fn lift(&'static self) -> InvertKernelRef {
×
112
        InvertKernelRef(ArcRef::new_ref(self))
×
113
    }
×
114
}
115

116
impl<V: VTable + InvertKernel> Kernel for InvertKernelAdapter<V> {
UNCOV
117
    fn invoke(&self, args: &InvocationArgs) -> VortexResult<Option<Output>> {
×
UNCOV
118
        let args = InvertArgs::try_from(args)?;
×
UNCOV
119
        let Some(array) = args.array.as_opt::<V>() else {
×
UNCOV
120
            return Ok(None);
×
121
        };
UNCOV
122
        Ok(Some(V::invert(&self.0, array)?.into()))
×
UNCOV
123
    }
×
124
}
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