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

vortex-data / vortex / 17045413678

18 Aug 2025 03:43PM UTC coverage: 86.065% (-1.8%) from 87.913%
17045413678

Pull #4215

github

web-flow
Merge 2657b4c8e into cb2220961
Pull Request #4215: Ji/vectors

136 of 1803 new or added lines in 42 files covered. (7.54%)

127 existing lines in 26 files now uncovered.

56918 of 66134 relevant lines covered (86.06%)

612050.14 hits per line

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

0.0
/vortex-vector/src/operators/constant.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::any::Any;
5
use std::hash::Hash;
6
use std::rc::Rc;
7
use std::task::Poll;
8

9
use vortex_dtype::{DType, NativePType, match_each_native_ptype};
10
use vortex_error::{VortexExpect, VortexResult};
11
use vortex_scalar::Scalar;
12

13
use crate::bits::BitView;
14
use crate::operators::{BindContext, Operator};
15
use crate::types::{Element, VType};
16
use crate::view::ViewMut;
17
use crate::{Kernel, KernelContext};
18

19
#[derive(Debug, Hash)]
20
pub struct ConstantOperator {
21
    pub(crate) scalar: Scalar,
22
}
23

24
impl ConstantOperator {
NEW
25
    pub fn maybe_new(scalar: Scalar) -> Option<Self> {
×
NEW
26
        if scalar.is_null() {
×
NEW
27
            None
×
28
        } else {
NEW
29
            Some(Self { scalar })
×
30
        }
NEW
31
    }
×
32

NEW
33
    pub fn new(scalar: Scalar) -> Self {
×
NEW
34
        Self::maybe_new(scalar).vortex_expect("scalar cannot be null")
×
NEW
35
    }
×
36
}
37

38
impl Operator for ConstantOperator {
NEW
39
    fn as_any(&self) -> &dyn Any {
×
NEW
40
        self
×
NEW
41
    }
×
42

NEW
43
    fn vtype(&self) -> VType {
×
NEW
44
        match self.scalar.dtype() {
×
NEW
45
            DType::Bool(_) => VType::Bool,
×
NEW
46
            DType::Primitive(p, _) => VType::Primitive(*p),
×
NEW
47
            DType::Binary(_) => VType::Binary,
×
NEW
48
            _ => todo!(),
×
49
        }
NEW
50
    }
×
51

NEW
52
    fn children(&self) -> &[Rc<dyn Operator>] {
×
NEW
53
        &[]
×
NEW
54
    }
×
55

NEW
56
    fn with_children(&self, children: Vec<Rc<dyn Operator>>) -> Rc<dyn Operator> {
×
NEW
57
        Rc::new(ConstantOperator::new(self.scalar.clone()))
×
NEW
58
    }
×
59

NEW
60
    fn bind(&self, ctx: &dyn BindContext) -> VortexResult<Box<dyn Kernel>> {
×
NEW
61
        Ok(match_each_native_ptype!(
×
NEW
62
            self.scalar.as_primitive().ptype(),
×
63
            |T| {
NEW
64
                Box::new(ConstantKernel::<T> {
×
NEW
65
                    value: self
×
NEW
66
                        .scalar
×
NEW
67
                        .as_primitive()
×
NEW
68
                        .typed_value::<T>()
×
NEW
69
                        .vortex_expect("scalar value not of type T"),
×
NEW
70
                })
×
71
            }
72
        ))
NEW
73
    }
×
74
}
75

76
pub struct ConstantKernel<T: NativePType> {
77
    value: T,
78
}
79

80
impl<T: Element + NativePType> Kernel for ConstantKernel<T> {
NEW
81
    fn seek(&mut self, chunk_idx: usize) -> VortexResult<()> {
×
NEW
82
        Ok(())
×
NEW
83
    }
×
84

NEW
85
    fn step(
×
NEW
86
        &mut self,
×
NEW
87
        ctx: &dyn KernelContext,
×
NEW
88
        selected: BitView,
×
NEW
89
        out: &mut ViewMut,
×
NEW
90
    ) -> Poll<VortexResult<()>> {
×
NEW
91
        let out_slice = out.as_slice_mut::<T>();
×
NEW
92
        for i in 0..selected.true_count() {
×
NEW
93
            out_slice[i] = self.value;
×
NEW
94
        }
×
NEW
95
        Poll::Ready(Ok(()))
×
NEW
96
    }
×
97
}
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