• 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

11.54
/vortex-ffi/src/struct_fields.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::ops::Deref;
5
use std::sync::Arc;
6

7
use vortex::dtype::{DType, StructFields};
8
use vortex::error::{VortexExpect, vortex_panic};
9

10
use crate::dtype::vx_dtype;
11
use crate::string::vx_string;
12
use crate::{arc_wrapper, box_wrapper};
13

14
arc_wrapper!(
15
    /// Represents a Vortex struct data type, without top-level nullability.
16
    StructFields,
17
    vx_struct_fields
18
);
19

20
/// Return the number of fields in the struct dtype.
21
#[unsafe(no_mangle)]
22
pub unsafe extern "C-unwind" fn vx_struct_fields_nfields(dtype: *const vx_struct_fields) -> u64 {
2✔
23
    unsafe { dtype.as_ref() }
2✔
24
        .vortex_expect("null ptr")
2✔
25
        .0
2✔
26
        .nfields() as u64
2✔
27
}
2✔
28

29
/// Return a borrowed reference to the name of the field at the given index.
30
#[unsafe(no_mangle)]
UNCOV
31
pub unsafe extern "C-unwind" fn vx_struct_fields_field_name(
×
UNCOV
32
    dtype: *const vx_struct_fields,
×
UNCOV
33
    idx: usize,
×
UNCOV
34
) -> *const vx_string {
×
UNCOV
35
    let ptr = unsafe { dtype.as_ref() }.vortex_expect("null ptr");
×
UNCOV
36
    let struct_dtype = &ptr.0;
×
UNCOV
37
    if idx >= struct_dtype.nfields() {
×
38
        vortex_panic!("Field index out of bounds");
×
UNCOV
39
    }
×
UNCOV
40
    vx_string::new_ref(&struct_dtype.names()[idx])
×
UNCOV
41
}
×
42

43
/// Returns an *owned* reference to the dtype of the field at the given index.
44
///
45
/// The return type is owned since struct dtypes can be lazily parsed from a binary format, in
46
/// which case it's not possible to return a borrowed reference to the field dtype.
47
// TODO(ngates): should StructDType cache owned fields internally?
48
// TODO(ngates): should this output a vx_error?
49
#[unsafe(no_mangle)]
UNCOV
50
pub unsafe extern "C-unwind" fn vx_struct_fields_field_dtype(
×
UNCOV
51
    dtype: *const vx_struct_fields,
×
UNCOV
52
    idx: u64,
×
UNCOV
53
) -> *const vx_dtype {
×
UNCOV
54
    let ptr = unsafe { dtype.as_ref() }.vortex_expect("null ptr");
×
UNCOV
55
    let struct_dtype = &ptr.0;
×
UNCOV
56
    vx_dtype::new(Arc::new(
×
UNCOV
57
        struct_dtype
×
UNCOV
58
            .field_by_index(usize::try_from(idx).vortex_expect("Unsupported cast"))
×
UNCOV
59
            .vortex_expect("Failed to parse lazy field dtype"),
×
60
    ))
UNCOV
61
}
×
62

63
pub(crate) struct StructDTypeBuilder {
64
    names: Vec<Arc<str>>,
65
    fields: Vec<DType>,
66
}
67

68
box_wrapper!(
69
    /// Builder for creating a [`vx_struct_fields`].
70
    StructDTypeBuilder,
71
    vx_struct_fields_builder
72
);
73

74
/// Create a new struct dtype builder.
75
#[unsafe(no_mangle)]
UNCOV
76
pub unsafe extern "C-unwind" fn vx_struct_fields_builder_new() -> *mut vx_struct_fields_builder {
×
UNCOV
77
    vx_struct_fields_builder::new(Box::new(StructDTypeBuilder {
×
UNCOV
78
        names: Vec::new(),
×
UNCOV
79
        fields: Vec::new(),
×
UNCOV
80
    }))
×
UNCOV
81
}
×
82

83
/// Add a field to the struct dtype builder.
84
///
85
/// Takes ownership of both the `name` and `dtype` pointers.
86
/// Must either free or finalize the builder.
87
#[unsafe(no_mangle)]
UNCOV
88
pub unsafe extern "C-unwind" fn vx_struct_fields_builder_add_field(
×
UNCOV
89
    builder: *mut vx_struct_fields_builder,
×
UNCOV
90
    name: *const vx_string,
×
UNCOV
91
    dtype: *const vx_dtype,
×
UNCOV
92
) {
×
UNCOV
93
    let builder = vx_struct_fields_builder::as_mut(builder);
×
UNCOV
94
    builder.names.push(vx_string::into_arc(name));
×
UNCOV
95
    builder
×
UNCOV
96
        .fields
×
UNCOV
97
        .push(vx_dtype::into_arc(dtype).deref().clone());
×
UNCOV
98
}
×
99

100
/// Finalize the struct dtype builder, returning a new `vx_struct_fields`.
101
///
102
/// Takes ownership of the `builder`.
103
#[unsafe(no_mangle)]
UNCOV
104
pub unsafe extern "C-unwind" fn vx_struct_fields_builder_finalize(
×
UNCOV
105
    builder: *mut vx_struct_fields_builder,
×
UNCOV
106
) -> *const vx_struct_fields {
×
UNCOV
107
    let builder = vx_struct_fields_builder::into_box(builder);
×
UNCOV
108
    let struct_dtype = StructFields::new(builder.names.into(), builder.fields);
×
UNCOV
109
    vx_struct_fields::new(Arc::new(struct_dtype))
×
UNCOV
110
}
×
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