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

vortex-data / vortex / 16725361413

04 Aug 2025 02:03PM UTC coverage: 83.426%. First build
16725361413

push

github

web-flow
perf[duckdb]: add file footer caching (#4104)

Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>

---------

Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>

188 of 206 new or added lines in 9 files covered. (91.26%)

46429 of 55653 relevant lines covered (83.43%)

450757.25 hits per line

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

76.47
/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>(
184✔
16
    init_input: *const cpp::duckdb_vx_tfunc_init_input,
184✔
17
    error_out: *mut cpp::duckdb_vx_error,
184✔
18
) -> cpp::duckdb_vx_data {
184✔
19
    let init_input = TableInitInput::new(
184✔
20
        unsafe { init_input.as_ref() }.vortex_expect("init_input null pointer"),
184✔
21
    );
22

23
    match T::init_global(&init_input) {
184✔
24
        Ok(init_data) => Data::from(Box::new(init_data)).as_ptr(),
184✔
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
}
184✔
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,465✔
37
    init_input: *const cpp::duckdb_vx_tfunc_init_input,
1,465✔
38
    global_init_data: *mut c_void,
1,465✔
39
    error_out: *mut cpp::duckdb_vx_error,
1,465✔
40
) -> cpp::duckdb_vx_data {
1,465✔
41
    let init_input = TableInitInput::new(
1,465✔
42
        unsafe { init_input.as_ref() }.vortex_expect("init_input null pointer"),
1,465✔
43
    );
44

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

48
    match T::init_local(&init_input, global_init_data) {
1,465✔
49
        Ok(init_data) => Data::from(Box::new(init_data)).as_ptr(),
1,465✔
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,465✔
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,649✔
78
        Self {
1,649✔
79
            input,
1,649✔
80
            phantom: std::marker::PhantomData,
1,649✔
81
        }
1,649✔
82
    }
1,649✔
83

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

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

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

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

114
    /// Returns the object cache from the client context for the table function.
115
    pub fn client_context(&self) -> VortexResult<ClientContext> {
184✔
116
        unsafe {
117
            if self.input.client_context.is_null() {
184✔
NEW
118
                vortex_bail!("Client context is null");
×
119
            }
184✔
120
            Ok(ClientContext::borrow(self.input.client_context))
184✔
121
        }
122
    }
184✔
123
}
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