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

vortex-data / vortex / 16593958537

29 Jul 2025 10:48AM UTC coverage: 82.285% (+0.5%) from 81.796%
16593958537

Pull #4036

github

web-flow
Merge 04147cb0f into 348079fc3
Pull Request #4036: varbinview builder buffer deduplication

146 of 154 new or added lines in 2 files covered. (94.81%)

348 existing lines in 26 files now uncovered.

44470 of 54044 relevant lines covered (82.28%)

169522.95 hits per line

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

81.01
/vortex-array/src/compute/fill_null.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};
9
use vortex_scalar::Scalar;
10

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

15
static FILL_NULL_FN: LazyLock<ComputeFn> = LazyLock::new(|| {
1,161✔
16
    let compute = ComputeFn::new("fill_null".into(), ArcRef::new_ref(&FillNull));
1,161✔
17
    for kernel in inventory::iter::<FillNullKernelRef> {
6,168✔
18
        compute.register_kernel(kernel.0.clone());
5,007✔
19
    }
5,007✔
20
    compute
1,161✔
21
});
1,161✔
22

23
pub fn fill_null(array: &dyn Array, fill_value: &Scalar) -> VortexResult<ArrayRef> {
5,971✔
24
    FILL_NULL_FN
5,971✔
25
        .invoke(&InvocationArgs {
5,971✔
26
            inputs: &[array.into(), fill_value.into()],
5,971✔
27
            options: &(),
5,971✔
28
        })?
5,971✔
29
        .unwrap_array()
5,971✔
30
}
5,971✔
31

32
pub trait FillNullKernel: VTable {
33
    fn fill_null(&self, array: &Self::Array, fill_value: &Scalar) -> VortexResult<ArrayRef>;
34
}
35

36
pub struct FillNullKernelRef(ArcRef<dyn Kernel>);
37
inventory::collect!(FillNullKernelRef);
38

39
#[derive(Debug)]
40
pub struct FillNullKernelAdapter<V: VTable>(pub V);
41

42
impl<V: VTable + FillNullKernel> FillNullKernelAdapter<V> {
UNCOV
43
    pub const fn lift(&'static self) -> FillNullKernelRef {
×
UNCOV
44
        FillNullKernelRef(ArcRef::new_ref(self))
×
UNCOV
45
    }
×
46
}
47

48
impl<V: VTable + FillNullKernel> Kernel for FillNullKernelAdapter<V> {
49
    fn invoke(&self, args: &InvocationArgs) -> VortexResult<Option<Output>> {
1,243✔
50
        let inputs = FillNullArgs::try_from(args)?;
1,243✔
51
        let Some(array) = inputs.array.as_opt::<V>() else {
1,243✔
52
            return Ok(None);
733✔
53
        };
54
        Ok(Some(
55
            V::fill_null(&self.0, array, inputs.fill_value)?.into(),
510✔
56
        ))
57
    }
1,243✔
58
}
59

60
struct FillNull;
61

62
impl ComputeFnVTable for FillNull {
63
    fn invoke(
5,971✔
64
        &self,
5,971✔
65
        args: &InvocationArgs,
5,971✔
66
        kernels: &[ArcRef<dyn Kernel>],
5,971✔
67
    ) -> VortexResult<Output> {
5,971✔
68
        let FillNullArgs { array, fill_value } = FillNullArgs::try_from(args)?;
5,971✔
69

70
        if !array.dtype().is_nullable() {
5,971✔
71
            return Ok(array.to_array().into());
935✔
72
        }
5,036✔
73

74
        if array.invalid_count()? == 0 {
5,036✔
75
            return Ok(cast(array, fill_value.dtype())?.into());
4,489✔
76
        }
547✔
77

78
        if fill_value.is_null() {
547✔
79
            vortex_bail!("Cannot fill_null with a null value")
×
80
        }
547✔
81

82
        for kernel in kernels {
1,280✔
83
            if let Some(output) = kernel.invoke(args)? {
1,280✔
84
                return Ok(output);
547✔
85
            }
733✔
86
        }
87
        if let Some(output) = array.invoke(&FILL_NULL_FN, args)? {
×
88
            return Ok(output);
×
89
        }
×
90

91
        log::debug!("FillNullFn not implemented for {}", array.encoding_id());
×
92
        if !array.is_canonical() {
×
93
            let canonical_arr = array.to_canonical()?.into_array();
×
94
            return Ok(fill_null(canonical_arr.as_ref(), fill_value)?.into());
×
95
        }
×
96

97
        vortex_bail!("fill null not implemented for DType {}", array.dtype())
×
98
    }
5,971✔
99

100
    fn return_dtype(&self, args: &InvocationArgs) -> VortexResult<DType> {
5,971✔
101
        let FillNullArgs { array, fill_value } = FillNullArgs::try_from(args)?;
5,971✔
102
        if !array.dtype().eq_ignore_nullability(fill_value.dtype()) {
5,971✔
103
            vortex_bail!("FillNull value must match array type (ignoring nullability)");
×
104
        }
5,971✔
105
        Ok(fill_value.dtype().clone())
5,971✔
106
    }
5,971✔
107

108
    fn return_len(&self, args: &InvocationArgs) -> VortexResult<usize> {
5,971✔
109
        let FillNullArgs { array, .. } = FillNullArgs::try_from(args)?;
5,971✔
110
        Ok(array.len())
5,971✔
111
    }
5,971✔
112

113
    fn is_elementwise(&self) -> bool {
5,971✔
114
        true
5,971✔
115
    }
5,971✔
116
}
117

118
struct FillNullArgs<'a> {
119
    array: &'a dyn Array,
120
    fill_value: &'a Scalar,
121
}
122

123
impl<'a> TryFrom<&InvocationArgs<'a>> for FillNullArgs<'a> {
124
    type Error = VortexError;
125

126
    fn try_from(value: &InvocationArgs<'a>) -> Result<Self, Self::Error> {
19,193✔
127
        if value.inputs.len() != 2 {
19,193✔
128
            vortex_bail!("FillNull requires 2 arguments");
×
129
        }
19,193✔
130

131
        let array = value.inputs[0]
19,193✔
132
            .array()
19,193✔
133
            .ok_or_else(|| vortex_err!("FillNull requires an array"))?;
19,193✔
134
        let fill_value = value.inputs[1]
19,193✔
135
            .scalar()
19,193✔
136
            .ok_or_else(|| vortex_err!("FillNull requires a scalar"))?;
19,193✔
137

138
        Ok(FillNullArgs { array, fill_value })
19,193✔
139
    }
19,193✔
140
}
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