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

vortex-data / vortex / 16594026488

29 Jul 2025 10:52AM UTC coverage: 82.149% (-0.1%) from 82.255%
16594026488

push

github

web-flow
fix: Forbid SequenceScheme for String and Float dictionary codes as well as Integer (#4048)

Signed-off-by: Robert Kruszewski <github@robertk.io>

2 of 2 new or added lines in 2 files covered. (100.0%)

57 existing lines in 10 files now uncovered.

44285 of 53908 relevant lines covered (82.15%)

168409.11 hits per line

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

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

4
use std::any::Any;
5
use std::sync::LazyLock;
6

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

11
use crate::arrow::{Datum, from_arrow_array_with_len};
12
use crate::compute::{ComputeFn, ComputeFnVTable, InvocationArgs, Kernel, Options, Output};
13
use crate::vtable::VTable;
14
use crate::{Array, ArrayRef};
15

16
static LIKE_FN: LazyLock<ComputeFn> = LazyLock::new(|| {
40✔
17
    let compute = ComputeFn::new("like".into(), ArcRef::new_ref(&Like));
40✔
18
    for kernel in inventory::iter::<LikeKernelRef> {
80✔
19
        compute.register_kernel(kernel.0.clone());
40✔
20
    }
40✔
21
    compute
40✔
22
});
40✔
23

24
/// Perform SQL left LIKE right
25
///
26
/// There are two wildcards supported with the LIKE operator:
27
/// - %: matches zero or more characters
28
/// - _: matches exactly one character
29
pub fn like(
94✔
30
    array: &dyn Array,
94✔
31
    pattern: &dyn Array,
94✔
32
    options: LikeOptions,
94✔
33
) -> VortexResult<ArrayRef> {
94✔
34
    LIKE_FN
94✔
35
        .invoke(&InvocationArgs {
94✔
36
            inputs: &[array.into(), pattern.into()],
94✔
37
            options: &options,
94✔
38
        })?
94✔
39
        .unwrap_array()
94✔
40
}
94✔
41

42
pub struct LikeKernelRef(ArcRef<dyn Kernel>);
43
inventory::collect!(LikeKernelRef);
44

45
pub trait LikeKernel: VTable {
46
    fn like(
47
        &self,
48
        array: &Self::Array,
49
        pattern: &dyn Array,
50
        options: LikeOptions,
51
    ) -> VortexResult<Option<ArrayRef>>;
52
}
53

54
#[derive(Debug)]
55
pub struct LikeKernelAdapter<V: VTable>(pub V);
56

57
impl<V: VTable + LikeKernel> LikeKernelAdapter<V> {
58
    pub const fn lift(&'static self) -> LikeKernelRef {
×
59
        LikeKernelRef(ArcRef::new_ref(self))
×
60
    }
×
61
}
62

63
impl<V: VTable + LikeKernel> Kernel for LikeKernelAdapter<V> {
64
    fn invoke(&self, args: &InvocationArgs) -> VortexResult<Option<Output>> {
79✔
65
        let inputs = LikeArgs::try_from(args)?;
79✔
66
        let Some(array) = inputs.array.as_opt::<V>() else {
79✔
67
            return Ok(None);
79✔
68
        };
UNCOV
69
        Ok(V::like(&self.0, array, inputs.pattern, inputs.options)?.map(|array| array.into()))
×
70
    }
79✔
71
}
72

73
struct Like;
74

75
impl ComputeFnVTable for Like {
76
    fn invoke(
94✔
77
        &self,
94✔
78
        args: &InvocationArgs,
94✔
79
        kernels: &[ArcRef<dyn Kernel>],
94✔
80
    ) -> VortexResult<Output> {
94✔
81
        let LikeArgs {
82
            array,
94✔
83
            pattern,
94✔
84
            options,
94✔
85
        } = LikeArgs::try_from(args)?;
94✔
86

87
        for kernel in kernels {
188✔
88
            if let Some(output) = kernel.invoke(args)? {
94✔
UNCOV
89
                return Ok(output);
×
90
            }
94✔
91
        }
92
        if let Some(output) = array.invoke(&LIKE_FN, args)? {
94✔
93
            return Ok(output);
×
94
        }
94✔
95

96
        // Otherwise, we fall back to the Arrow implementation
97
        Ok(arrow_like(array, pattern, options)?.into())
94✔
98
    }
94✔
99

100
    fn return_dtype(&self, args: &InvocationArgs) -> VortexResult<DType> {
94✔
101
        let LikeArgs { array, pattern, .. } = LikeArgs::try_from(args)?;
94✔
102
        if !matches!(array.dtype(), DType::Utf8(..)) {
94✔
103
            vortex_bail!("Expected utf8 array, got {}", array.dtype());
×
104
        }
94✔
105
        if !matches!(pattern.dtype(), DType::Utf8(..)) {
94✔
106
            vortex_bail!("Expected utf8 pattern, got {}", array.dtype());
×
107
        }
94✔
108
        let nullability = array.dtype().is_nullable() || pattern.dtype().is_nullable();
94✔
109
        Ok(DType::Bool(nullability.into()))
94✔
110
    }
94✔
111

112
    fn return_len(&self, args: &InvocationArgs) -> VortexResult<usize> {
94✔
113
        let LikeArgs { array, pattern, .. } = LikeArgs::try_from(args)?;
94✔
114
        if array.len() != pattern.len() {
94✔
115
            vortex_bail!(
×
116
                "Length mismatch lhs len {} ({}) != rhs len {} ({})",
×
117
                array.len(),
×
118
                array.encoding_id(),
×
119
                pattern.len(),
×
120
                pattern.encoding_id()
×
121
            );
122
        }
94✔
123
        Ok(array.len())
94✔
124
    }
94✔
125

126
    fn is_elementwise(&self) -> bool {
94✔
127
        true
94✔
128
    }
94✔
129
}
130

131
/// Options for SQL LIKE function
132
#[derive(Default, Debug, Clone, Copy)]
133
pub struct LikeOptions {
134
    pub negated: bool,
135
    pub case_insensitive: bool,
136
}
137

138
impl Options for LikeOptions {
139
    fn as_any(&self) -> &dyn Any {
376✔
140
        self
376✔
141
    }
376✔
142
}
143

144
struct LikeArgs<'a> {
145
    array: &'a dyn Array,
146
    pattern: &'a dyn Array,
147
    options: LikeOptions,
148
}
149

150
impl<'a> TryFrom<&InvocationArgs<'a>> for LikeArgs<'a> {
151
    type Error = VortexError;
152

153
    fn try_from(value: &InvocationArgs<'a>) -> Result<Self, Self::Error> {
376✔
154
        if value.inputs.len() != 2 {
376✔
155
            vortex_bail!("Expected 2 inputs, found {}", value.inputs.len());
×
156
        }
376✔
157
        let array = value.inputs[0]
376✔
158
            .array()
376✔
159
            .ok_or_else(|| vortex_err!("Expected first input to be an array"))?;
376✔
160
        let pattern = value.inputs[1]
376✔
161
            .array()
376✔
162
            .ok_or_else(|| vortex_err!("Expected second input to be an array"))?;
376✔
163
        let options = *value
376✔
164
            .options
376✔
165
            .as_any()
376✔
166
            .downcast_ref::<LikeOptions>()
376✔
167
            .vortex_expect("Expected options to be LikeOptions");
376✔
168

169
        Ok(LikeArgs {
376✔
170
            array,
376✔
171
            pattern,
376✔
172
            options,
376✔
173
        })
376✔
174
    }
376✔
175
}
176

177
/// Implementation of `LikeFn` using the Arrow crate.
178
pub(crate) fn arrow_like(
94✔
179
    array: &dyn Array,
94✔
180
    pattern: &dyn Array,
94✔
181
    options: LikeOptions,
94✔
182
) -> VortexResult<ArrayRef> {
94✔
183
    let nullable = array.dtype().is_nullable() | pattern.dtype().is_nullable();
94✔
184
    let len = array.len();
94✔
185
    assert_eq!(
94✔
186
        array.len(),
94✔
187
        pattern.len(),
94✔
188
        "Arrow Like: length mismatch for {}",
×
189
        array.encoding_id()
×
190
    );
191
    let lhs = Datum::try_new(array)?;
94✔
192
    let rhs = Datum::try_new(pattern)?;
94✔
193

194
    let result = match (options.negated, options.case_insensitive) {
94✔
195
        (false, false) => arrow_string::like::like(&lhs, &rhs)?,
54✔
196
        (true, false) => arrow_string::like::nlike(&lhs, &rhs)?,
40✔
197
        (false, true) => arrow_string::like::ilike(&lhs, &rhs)?,
×
198
        (true, true) => arrow_string::like::nilike(&lhs, &rhs)?,
×
199
    };
200

201
    from_arrow_array_with_len(&result, len, nullable)
94✔
202
}
94✔
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