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

vortex-data / vortex / 16992591828

15 Aug 2025 02:51PM UTC coverage: 87.203% (-0.5%) from 87.72%
16992591828

Pull #2456

github

web-flow
Merge fe7e226a7 into 4a23f65b3
Pull Request #2456: feat: basic BoolBuffer / BoolBufferMut

476 of 1230 new or added lines in 107 files covered. (38.7%)

74 existing lines in 19 files now uncovered.

56525 of 64820 relevant lines covered (87.2%)

623751.88 hits per line

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

86.67
/vortex-array/src/arrow/compute/to_arrow/varbin.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::sync::Arc;
5

6
use arrow_array::{
7
    ArrayRef as ArrowArrayRef, GenericBinaryArray, GenericStringArray, OffsetSizeTrait,
8
};
9
use arrow_schema::DataType;
10
use vortex_dtype::{DType, NativePType, Nullability, PType};
11
use vortex_error::{VortexResult, vortex_bail};
12

13
use crate::arrays::{VarBinArray, VarBinVTable};
14
use crate::arrow::compute::{ToArrowKernel, ToArrowKernelAdapter};
15
use crate::compute::cast;
16
use crate::{Array, ToCanonical, register_kernel};
17

18
impl ToArrowKernel for VarBinVTable {
19
    fn to_arrow(
2,836✔
20
        &self,
2,836✔
21
        array: &VarBinArray,
2,836✔
22
        arrow_type: Option<&DataType>,
2,836✔
23
    ) -> VortexResult<Option<ArrowArrayRef>> {
2,836✔
24
        let offsets_ptype = PType::try_from(array.offsets().dtype())?;
2,836✔
25

26
        match arrow_type {
27
            // Emit out preferred Arrow VarBin array.
28
            None => match array.dtype() {
2,718✔
29
                DType::Binary(_) => match offsets_ptype {
924✔
UNCOV
30
                    PType::I64 | PType::U64 => to_arrow::<i64>(array),
×
31
                    _ => to_arrow::<i32>(array),
924✔
32
                },
33
                DType::Utf8(_) => match offsets_ptype {
1,794✔
UNCOV
34
                    PType::I64 | PType::U64 => to_arrow::<i64>(array),
×
35
                    _ => to_arrow::<i32>(array),
1,794✔
36
                },
37
                _ => unreachable!("Unsupported DType"),
38
            },
39
            // Emit the requested Arrow array.
40
            Some(DataType::Binary) if array.dtype().is_binary() => to_arrow::<i32>(array),
41
            Some(DataType::LargeBinary) if array.dtype().is_binary() => to_arrow::<i64>(array),
×
42
            Some(DataType::Utf8) if array.dtype().is_utf8() => to_arrow::<i32>(array),
40✔
UNCOV
43
            Some(DataType::LargeUtf8) if array.dtype().is_utf8() => to_arrow::<i64>(array),
×
44
            // Allow fallback to canonicalize to a VarBinView and try again.
45
            Some(DataType::BinaryView) | Some(DataType::Utf8View) => {
46
                return Ok(None);
78✔
47
            }
48
            // Any other type is not supported.
49
            Some(_) => {
50
                vortex_bail!("Cannot convert VarBin to Arrow type {arrow_type:?}");
51
            }
52
        }
53
        .map(Some)
2,758✔
54
    }
2,836✔
55
}
56

57
register_kernel!(ToArrowKernelAdapter(VarBinVTable).lift());
58

59
fn to_arrow<O: NativePType + OffsetSizeTrait>(array: &VarBinArray) -> VortexResult<ArrowArrayRef> {
2,758✔
60
    let offsets = cast(
2,758✔
61
        array.offsets(),
2,758✔
62
        &DType::Primitive(O::PTYPE, Nullability::NonNullable),
2,758✔
UNCOV
63
    )?
×
64
    .to_primitive()
2,758✔
65
    .map_err(|err| err.with_context("Failed to canonicalize offsets"))?;
2,758✔
66

67
    let nulls = array.validity_mask()?.to_null_buffer();
2,758✔
68
    let data = array.bytes().clone();
2,758✔
69

70
    // Switch on DType.
71
    Ok(match array.dtype() {
2,758✔
72
        DType::Binary(_) => Arc::new(unsafe {
924✔
73
            GenericBinaryArray::new_unchecked(
924✔
74
                offsets.buffer::<O>().into_arrow_offset_buffer(),
924✔
75
                data.into_arrow_buffer(),
924✔
76
                nulls,
924✔
77
            )
924✔
78
        }),
924✔
79
        DType::Utf8(_) => Arc::new(unsafe {
1,834✔
80
            GenericStringArray::new_unchecked(
1,834✔
81
                offsets.buffer::<O>().into_arrow_offset_buffer(),
1,834✔
82
                data.into_arrow_buffer(),
1,834✔
83
                nulls,
1,834✔
84
            )
1,834✔
85
        }),
1,834✔
UNCOV
86
        _ => unreachable!("expected utf8 or binary instead of {}", array.dtype()),
×
87
    })
88
}
2,758✔
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