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

vortex-data / vortex / 16935267080

13 Aug 2025 11:00AM UTC coverage: 24.312% (-63.3%) from 87.658%
16935267080

Pull #4226

github

web-flow
Merge 81b48c7fb into baa6ea202
Pull Request #4226: Support converting TimestampTZ to and from duckdb

0 of 2 new or added lines in 1 file covered. (0.0%)

20666 existing lines in 469 files now uncovered.

8726 of 35892 relevant lines covered (24.31%)

147.74 hits per line

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

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

4
use arrow_buffer::{ArrowNativeType, OffsetBuffer};
5
use bytes::Bytes;
6
use vortex_error::vortex_panic;
7

8
use crate::{Alignment, Buffer, ByteBuffer};
9

10
impl<T: ArrowNativeType> Buffer<T> {
11
    /// Converts the buffer zero-copy into a `arrow_buffer::Buffer`.
UNCOV
12
    pub fn into_arrow_scalar_buffer(self) -> arrow_buffer::ScalarBuffer<T> {
×
UNCOV
13
        let buffer = arrow_buffer::Buffer::from(self.into_inner());
×
UNCOV
14
        arrow_buffer::ScalarBuffer::from(buffer)
×
UNCOV
15
    }
×
16

17
    /// Convert an Arrow scalar buffer into a Vortex scalar buffer.
18
    ///
19
    /// ## Panics
20
    ///
21
    /// Panics if the Arrow buffer is not aligned to the requested alignment, or if the requested
22
    /// alignment is not sufficient for type T.
UNCOV
23
    pub fn from_arrow_scalar_buffer(arrow: arrow_buffer::ScalarBuffer<T>) -> Self {
×
UNCOV
24
        let length = arrow.len();
×
UNCOV
25
        let bytes = Bytes::from_owner(ArrowWrapper(arrow.into_inner()));
×
26

UNCOV
27
        let alignment = Alignment::of::<T>();
×
UNCOV
28
        if bytes.as_ptr().align_offset(*alignment) != 0 {
×
29
            vortex_panic!(
×
30
                "Arrow buffer is not aligned to the requested alignment: {}",
×
31
                alignment
32
            );
UNCOV
33
        }
×
34

UNCOV
35
        Self {
×
UNCOV
36
            bytes,
×
UNCOV
37
            length,
×
UNCOV
38
            alignment,
×
UNCOV
39
            _marker: Default::default(),
×
UNCOV
40
        }
×
UNCOV
41
    }
×
42

43
    /// Converts the buffer zero-copy into a `arrow_buffer::OffsetBuffer`.
44
    ///
45
    /// SAFETY: The caller should ensure that the buffer contains monotonically increasing values
46
    /// greater than or equal to zero.
UNCOV
47
    pub fn into_arrow_offset_buffer(self) -> OffsetBuffer<T> {
×
UNCOV
48
        unsafe { OffsetBuffer::new_unchecked(self.into_arrow_scalar_buffer()) }
×
UNCOV
49
    }
×
50
}
51

52
impl ByteBuffer {
53
    /// Converts the buffer zero-copy into a `arrow_buffer::Buffer`.
UNCOV
54
    pub fn into_arrow_buffer(self) -> arrow_buffer::Buffer {
×
UNCOV
55
        arrow_buffer::Buffer::from(self.into_inner())
×
UNCOV
56
    }
×
57

58
    /// Convert an Arrow scalar buffer into a Vortex scalar buffer.
59
    ///
60
    /// ## Panics
61
    ///
62
    /// Panics if the Arrow buffer is not sufficiently aligned.
63
    pub fn from_arrow_buffer(arrow: arrow_buffer::Buffer, alignment: Alignment) -> Self {
24✔
64
        let length = arrow.len();
24✔
65

66
        let bytes = Bytes::from_owner(ArrowWrapper(arrow));
24✔
67
        if bytes.as_ptr().align_offset(*alignment) != 0 {
24✔
68
            vortex_panic!(
×
69
                "Arrow buffer is not aligned to the requested alignment: {}",
×
70
                alignment
71
            );
72
        }
24✔
73

74
        Self {
24✔
75
            bytes,
24✔
76
            length,
24✔
77
            alignment,
24✔
78
            _marker: Default::default(),
24✔
79
        }
24✔
80
    }
24✔
81
}
82

83
/// A wrapper struct to allow `arrow_buffer::Buffer` to implement `AsRef<[u8]>` for
84
/// `Bytes::from_owner`.
85
struct ArrowWrapper(arrow_buffer::Buffer);
86

87
impl AsRef<[u8]> for ArrowWrapper {
88
    fn as_ref(&self) -> &[u8] {
24✔
89
        self.0.as_slice()
24✔
90
    }
24✔
91
}
92

93
#[cfg(test)]
94
mod test {
95
    use arrow_buffer::{Buffer as ArrowBuffer, ScalarBuffer};
96

97
    use crate::{Alignment, Buffer, buffer};
98

99
    #[test]
100
    fn into_arrow_buffer() {
101
        let buf = buffer![0u8, 1, 2];
102
        let arrow: ArrowBuffer = buf.clone().into_arrow_buffer();
103
        assert_eq!(arrow.as_ref(), buf.as_slice(), "Buffer values differ");
104
        assert_eq!(arrow.as_ptr(), buf.as_ptr(), "Conversion not zero-copy")
105
    }
106

107
    #[test]
108
    fn into_arrow_scalar_buffer() {
109
        let buf = buffer![0i32, 1, 2];
110
        let scalar: ScalarBuffer<i32> = buf.clone().into_arrow_scalar_buffer();
111
        assert_eq!(scalar.as_ref(), buf.as_slice(), "Buffer values differ");
112
        assert_eq!(scalar.as_ptr(), buf.as_ptr(), "Conversion not zero-copy")
113
    }
114

115
    #[test]
116
    fn from_arrow_buffer() {
117
        let arrow = ArrowBuffer::from_vec(vec![0i32, 1, 2]);
118
        let buf = Buffer::from_arrow_buffer(arrow.clone(), Alignment::of::<i32>());
119
        assert_eq!(arrow.as_ref(), buf.as_slice(), "Buffer values differ");
120
        assert_eq!(arrow.as_ptr(), buf.as_ptr(), "Conversion not zero-copy");
121
    }
122
}
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