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

vortex-data / vortex / 16728097825

04 Aug 2025 04:00PM UTC coverage: 48.355% (-35.1%) from 83.429%
16728097825

Pull #4108

github

web-flow
Merge 1b2d27fd8 into 649ba9576
Pull Request #4108: perf[vortex-array]: use all_valid instead of `invalid_count() == 0`

1 of 1 new or added line in 1 file covered. (100.0%)

11596 existing lines in 378 files now uncovered.

18635 of 38538 relevant lines covered (48.35%)

151786.4 hits per line

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

75.0
/vortex-duckdb/src/duckdb/table_function/init.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::ffi::c_void;
5
use std::fmt::{Debug, Formatter};
6
use std::ptr;
7

8
use vortex::error::{VortexExpect, VortexResult, vortex_bail};
9

10
use crate::cpp;
11
use crate::duckdb::data::Data;
12
use crate::duckdb::{ClientContext, TableFilterSet, TableFunction};
13

14
/// Native callback for the global initialization of a table function.
15
pub(crate) unsafe extern "C-unwind" fn init_global_callback<T: TableFunction>(
172✔
16
    init_input: *const cpp::duckdb_vx_tfunc_init_input,
172✔
17
    error_out: *mut cpp::duckdb_vx_error,
172✔
18
) -> cpp::duckdb_vx_data {
172✔
19
    let init_input = TableInitInput::new(
172✔
20
        unsafe { init_input.as_ref() }.vortex_expect("init_input null pointer"),
172✔
21
    );
22

23
    match T::init_global(&init_input) {
172✔
24
        Ok(init_data) => Data::from(Box::new(init_data)).as_ptr(),
172✔
25
        Err(e) => {
×
26
            // Set the error in the error output.
27
            let msg = e.to_string();
×
28
            unsafe { error_out.write(cpp::duckdb_vx_error_create(msg.as_ptr().cast(), msg.len())) };
×
29
            ptr::null_mut::<cpp::duckdb_vx_data_>().cast()
×
30
        }
31
    }
32
}
172✔
33

34
/// Native callback for the local initialization of a table function.
35
#[allow(deref_nullptr)]
36
pub(crate) unsafe extern "C-unwind" fn init_local_callback<T: TableFunction>(
1,376✔
37
    init_input: *const cpp::duckdb_vx_tfunc_init_input,
1,376✔
38
    global_init_data: *mut c_void,
1,376✔
39
    error_out: *mut cpp::duckdb_vx_error,
1,376✔
40
) -> cpp::duckdb_vx_data {
1,376✔
41
    let init_input = TableInitInput::new(
1,376✔
42
        unsafe { init_input.as_ref() }.vortex_expect("init_input null pointer"),
1,376✔
43
    );
44

45
    let global_init_data = unsafe { global_init_data.cast::<T::GlobalState>().as_mut() }
1,376✔
46
        .vortex_expect("global_init_data null pointer");
1,376✔
47

48
    match T::init_local(&init_input, global_init_data) {
1,376✔
49
        Ok(init_data) => Data::from(Box::new(init_data)).as_ptr(),
1,376✔
50
        Err(e) => {
×
51
            // Set the error in the error output.
52
            let msg = e.to_string();
×
53
            unsafe { error_out.write(cpp::duckdb_vx_error_create(msg.as_ptr().cast(), msg.len())) };
×
54
            ptr::null_mut::<cpp::duckdb_vx_data_>().cast()
×
55
        }
56
    }
57
}
1,376✔
58

59
/// A typed wrapper for the input to a table function's initialization.
60
pub struct TableInitInput<'a, T: TableFunction> {
61
    input: &'a cpp::duckdb_vx_tfunc_init_input,
62
    phantom: std::marker::PhantomData<T>,
63
}
64

65
impl<T: TableFunction> Debug for TableInitInput<'_, T> {
66
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
×
67
        f.debug_struct("TableInitInput")
×
68
            .field("table_function", &std::any::type_name::<T>())
×
69
            .field("column_ids", &self.column_ids())
×
70
            .field("projection_ids", &self.projection_ids())
×
71
            // .field("table_filter_set", &self.table_filter_set())
72
            .finish()
×
73
    }
×
74
}
75

76
impl<'a, T: TableFunction> TableInitInput<'a, T> {
77
    fn new(input: &'a cpp::duckdb_vx_tfunc_init_input) -> Self {
1,548✔
78
        Self {
1,548✔
79
            input,
1,548✔
80
            phantom: std::marker::PhantomData,
1,548✔
81
        }
1,548✔
82
    }
1,548✔
83

84
    /// Returns the bind data for the table function.
85
    pub fn bind_data(&self) -> &T::BindData {
1,012✔
86
        unsafe { &*self.input.bind_data.cast::<T::BindData>() }
1,012✔
87
    }
1,012✔
88

89
    /// Returns the column_ids for the table function.
90
    pub fn column_ids(&self) -> &[u64] {
344✔
91
        unsafe { std::slice::from_raw_parts(self.input.column_ids, self.input.column_ids_count) }
344✔
92
    }
344✔
93

94
    /// Returns the projection_ids for the table function.
95
    pub fn projection_ids(&self) -> Option<&[u64]> {
172✔
96
        if self.input.projection_ids.is_null() {
172✔
UNCOV
97
            return None;
×
98
        }
172✔
99
        Some(unsafe {
172✔
100
            std::slice::from_raw_parts(self.input.projection_ids, self.input.projection_ids_count)
172✔
101
        })
172✔
102
    }
172✔
103

104
    /// Returns the table filter set for the table function.
105
    pub fn table_filter_set(&self) -> Option<TableFilterSet> {
172✔
106
        let ptr = self.input.filters;
172✔
107
        if ptr.is_null() {
172✔
108
            None
76✔
109
        } else {
110
            Some(unsafe { TableFilterSet::borrow(ptr) })
96✔
111
        }
112
    }
172✔
113

114
    /// Returns the object cache from the client context for the table function.
115
    pub fn client_context(&self) -> VortexResult<ClientContext> {
172✔
116
        unsafe {
117
            if self.input.client_context.is_null() {
172✔
118
                vortex_bail!("Client context is null");
×
119
            }
172✔
120
            Ok(ClientContext::borrow(self.input.client_context))
172✔
121
        }
122
    }
172✔
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc