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

vortex-data / vortex / 16979224669

14 Aug 2025 11:42PM UTC coverage: 23.728%. First build
16979224669

Pull #2456

github

web-flow
Merge 30049dfa7 into aaf3e36ad
Pull Request #2456: feat: basic BoolBuffer / BoolBufferMut

68 of 1065 new or added lines in 82 files covered. (6.38%)

8616 of 36312 relevant lines covered (23.73%)

146.37 hits per line

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

0.0
/vortex-array/src/arrow/compute/to_arrow/temporal.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::types::{
7
    Date32Type, Date64Type, Time32MillisecondType, Time32SecondType, Time64MicrosecondType,
8
    Time64NanosecondType, TimestampMicrosecondType, TimestampMillisecondType,
9
    TimestampNanosecondType, TimestampSecondType,
10
};
11
use arrow_array::{
12
    ArrayRef as ArrowArrayRef, ArrowPrimitiveType, PrimitiveArray as ArrowPrimitiveArray,
13
};
14
use arrow_schema::{DataType, TimeUnit as ArrowTimeUnit};
15
use vortex_dtype::datetime::{TemporalMetadata, TimeUnit, is_temporal_ext_type};
16
use vortex_dtype::{DType, NativePType};
17
use vortex_error::{VortexExpect, VortexResult, vortex_bail};
18

19
use crate::arrays::{ExtensionVTable, TemporalArray};
20
use crate::arrow::array::ArrowArray;
21
use crate::arrow::compute::to_arrow::ToArrowArgs;
22
use crate::arrow::compute::to_arrow::null_buffer::to_null_buffer;
23
use crate::compute::{InvocationArgs, Kernel, Output, cast};
24
use crate::{Array as _, IntoArray, ToCanonical};
25

26
/// Implementation of `ToArrow` kernel for canonical Vortex arrays.
27
#[derive(Debug)]
28
pub(super) struct ToArrowTemporal;
29

30
impl Kernel for ToArrowTemporal {
31
    fn invoke(&self, args: &InvocationArgs) -> VortexResult<Option<Output>> {
×
32
        let ToArrowArgs { array, arrow_type } = ToArrowArgs::try_from(args)?;
×
33

34
        if !array
×
35
            .as_opt::<ExtensionVTable>()
×
36
            .is_some_and(|ext| is_temporal_ext_type(ext.ext_dtype().id()))
×
37
        {
38
            // This kernel only handles temporal arrays.
39
            return Ok(None);
×
40
        }
×
41
        let array = TemporalArray::try_from(array.to_array())
×
42
            .vortex_expect("Checked above that array is a temporal ExtensionArray");
×
43

44
        // Figure out the target Arrow type, or use the canonical type
45
        let arrow_type = arrow_type
×
46
            .cloned()
×
47
            .map(Ok)
×
48
            .unwrap_or_else(|| array.dtype().to_arrow_dtype())?;
×
49

50
        let arrow_array: ArrowArrayRef = match (array.temporal_metadata(), &arrow_type) {
×
51
            (TemporalMetadata::Date(TimeUnit::D), DataType::Date32) => {
52
                to_arrow_temporal::<Date32Type>(&array)
×
53
            }
54
            (TemporalMetadata::Date(TimeUnit::Ms), DataType::Date64) => {
55
                to_arrow_temporal::<Date64Type>(&array)
×
56
            }
57
            (TemporalMetadata::Time(TimeUnit::S), DataType::Time32(ArrowTimeUnit::Second)) => {
58
                to_arrow_temporal::<Time32SecondType>(&array)
×
59
            }
60
            (
61
                TemporalMetadata::Time(TimeUnit::Ms),
62
                DataType::Time32(ArrowTimeUnit::Millisecond),
63
            ) => to_arrow_temporal::<Time32MillisecondType>(&array),
×
64
            (
65
                TemporalMetadata::Time(TimeUnit::Us),
66
                DataType::Time64(ArrowTimeUnit::Microsecond),
67
            ) => to_arrow_temporal::<Time64MicrosecondType>(&array),
×
68

69
            (TemporalMetadata::Time(TimeUnit::Ns), DataType::Time64(ArrowTimeUnit::Nanosecond)) => {
70
                to_arrow_temporal::<Time64NanosecondType>(&array)
×
71
            }
72
            (
73
                TemporalMetadata::Timestamp(TimeUnit::S, _),
74
                DataType::Timestamp(ArrowTimeUnit::Second, None),
75
            ) => to_arrow_temporal::<TimestampSecondType>(&array),
×
76
            (
77
                TemporalMetadata::Timestamp(TimeUnit::Ms, _),
78
                DataType::Timestamp(ArrowTimeUnit::Millisecond, None),
79
            ) => to_arrow_temporal::<TimestampMillisecondType>(&array),
×
80
            (
81
                TemporalMetadata::Timestamp(TimeUnit::Us, _),
82
                DataType::Timestamp(ArrowTimeUnit::Microsecond, None),
83
            ) => to_arrow_temporal::<TimestampMicrosecondType>(&array),
×
84
            (
85
                TemporalMetadata::Timestamp(TimeUnit::Ns, _),
86
                DataType::Timestamp(ArrowTimeUnit::Nanosecond, None),
87
            ) => to_arrow_temporal::<TimestampNanosecondType>(&array),
×
88
            _ => vortex_bail!(
×
89
                "Cannot convert {} array to Arrow type {}",
×
90
                array.dtype(),
×
91
                arrow_type,
92
            ),
93
        }?;
×
94

95
        Ok(Some(
×
96
            ArrowArray::new(arrow_array, array.dtype().nullability())
×
97
                .into_array()
×
98
                .into(),
×
99
        ))
×
100
    }
×
101
}
102

103
fn to_arrow_temporal<T: ArrowPrimitiveType>(array: &TemporalArray) -> VortexResult<ArrowArrayRef>
×
104
where
×
105
    T::Native: NativePType,
×
106
{
107
    let values_dtype = DType::Primitive(T::Native::PTYPE, array.dtype().nullability());
×
108
    let values = cast(array.temporal_values(), &values_dtype)?
×
109
        .to_primitive()?
×
110
        .into_buffer()
×
111
        .into_arrow_scalar_buffer();
×
NEW
112
    let nulls = to_null_buffer(array.temporal_values().validity_mask()?);
×
113

114
    Ok(Arc::new(ArrowPrimitiveArray::<T>::new(values, nulls)))
×
115
}
×
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