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

vortex-data / vortex / 17075133033

19 Aug 2025 04:01PM UTC coverage: 87.949% (+0.09%) from 87.856%
17075133033

push

github

web-flow
feat: ArrayOperations infallible, eager validation + new_unchecked (#4177)

ArrayOperations currently return VortexResult<>, but they really should
just be infallible. A failed array op is generally indicative of
programmer or encoding error. There's really nothing interesting we can
do to handle an out-of-bounds slice() or scalar_at.

There's a lot that falls out of this, like fixing a bunch of tests,
tweaking our scalar value casting to return Option instead of Result,
etc.

---------

Signed-off-by: Andrew Duffy <andrew@a10y.dev>

1744 of 1985 new or added lines in 195 files covered. (87.86%)

36 existing lines in 27 files now uncovered.

56745 of 64520 relevant lines covered (87.95%)

624082.56 hits per line

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

61.29
/vortex-array/src/arrow/datum.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use arrow_array::{Array as ArrowArray, ArrayRef as ArrowArrayRef, Datum as ArrowDatum};
5
use arrow_schema::DataType;
6
use vortex_error::{VortexResult, vortex_panic};
7

8
use crate::arrays::ConstantArray;
9
use crate::arrow::{FromArrowArray, IntoArrowArray};
10
use crate::{Array, ArrayRef, IntoArray};
11

12
/// A wrapper around a generic Arrow array that can be used as a Datum in Arrow compute.
13
#[derive(Debug)]
14
pub struct Datum {
15
    array: ArrowArrayRef,
16
    is_scalar: bool,
17
}
18

19
impl Datum {
20
    /// Create a new [`Datum`] from an [`ArrayRef`], which can then be passed to Arrow compute.
21
    pub fn try_new(array: &dyn Array) -> VortexResult<Self> {
266,954✔
22
        if array.is_constant() {
266,954✔
23
            Ok(Self {
24
                array: array.slice(0, 1).into_arrow_preferred()?,
132,672✔
25
                is_scalar: true,
26
            })
27
        } else {
28
            Ok(Self {
29
                array: array.to_array().into_arrow_preferred()?,
134,282✔
30
                is_scalar: false,
31
            })
32
        }
33
    }
266,954✔
34

35
    pub fn with_target_datatype(
×
36
        array: &dyn Array,
×
37
        target_datatype: &DataType,
×
38
    ) -> VortexResult<Self> {
×
39
        if array.is_constant() {
×
40
            Ok(Self {
NEW
41
                array: array.slice(0, 1).into_arrow(target_datatype)?,
×
42
                is_scalar: true,
43
            })
44
        } else {
45
            Ok(Self {
46
                array: array.to_array().into_arrow(target_datatype)?,
×
47
                is_scalar: false,
48
            })
49
        }
50
    }
×
51
}
52

53
impl ArrowDatum for Datum {
54
    fn get(&self) -> (&dyn ArrowArray, bool) {
266,954✔
55
        (&self.array, self.is_scalar)
266,954✔
56
    }
266,954✔
57
}
58

59
/// Convert an Arrow array to an Array with a specific length.
60
/// This is useful for compute functions that delegate to Arrow using [Datum],
61
/// which will return a scalar (length 1 Arrow array) if the input array is constant.
62
///
63
/// # Error
64
///
65
/// The provided array must have length
66
pub fn from_arrow_array_with_len<A>(array: A, len: usize, nullable: bool) -> ArrayRef
124,397✔
67
where
124,397✔
68
    ArrayRef: FromArrowArray<A>,
124,397✔
69
{
70
    let array = ArrayRef::from_arrow(array, nullable);
124,397✔
71
    if array.len() == len {
124,397✔
72
        return array;
124,396✔
73
    }
1✔
74

75
    if array.len() != 1 {
1✔
76
        vortex_panic!(
×
77
            "Array length mismatch, expected {} got {} for encoding {}",
×
78
            len,
79
            array.len(),
×
80
            array.encoding_id()
×
81
        );
82
    }
1✔
83

84
    ConstantArray::new(array.scalar_at(0), len).into_array()
1✔
85
}
124,397✔
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