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

vortex-data / vortex / 16991469020

15 Aug 2025 01:54PM UTC coverage: 86.018% (-1.8%) from 87.855%
16991469020

Pull #4215

github

web-flow
Merge 58201b202 into 62e231a41
Pull Request #4215: Ji/vectors

90 of 1746 new or added lines in 40 files covered. (5.15%)

117 existing lines in 25 files now uncovered.

56661 of 65871 relevant lines covered (86.02%)

614266.74 hits per line

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

0.0
/vortex-array/src/pipeline/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, Hasher};
6
use std::sync::Arc;
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::pipeline::bits::BitView;
14
use crate::pipeline::operators::{BindContext, Operator};
15
use crate::pipeline::types::{Element, VType};
16
use crate::pipeline::view::ViewMut;
17
use crate::pipeline::{Kernel, KernelContext};
18

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

24
impl ConstantOperator {
NEW
25
    pub fn new(scalar: Scalar) -> Self {
×
NEW
26
        Self { scalar }
×
NEW
27
    }
×
28
}
29

30
impl Hash for ConstantOperator {
NEW
31
    fn hash<H: Hasher>(&self, state: &mut H) {
×
NEW
32
        self.scalar.as_ref().hash(state);
×
NEW
33
    }
×
34
}
35

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

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

NEW
50
    fn children(&self) -> &[Arc<dyn Operator>] {
×
NEW
51
        &[]
×
NEW
52
    }
×
53

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

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

74
pub struct ConstantKernel<T: NativePType> {
75
    value: T,
76
}
77

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

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