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

vortex-data / vortex / 16992684502

15 Aug 2025 02:56PM UTC coverage: 87.875% (+0.2%) from 87.72%
16992684502

Pull #2456

github

web-flow
Merge 2d540e578 into 4a23f65b3
Pull Request #2456: feat: basic BoolBuffer / BoolBufferMut

1275 of 1428 new or added lines in 110 files covered. (89.29%)

334 existing lines in 31 files now uncovered.

57169 of 65057 relevant lines covered (87.88%)

658056.52 hits per line

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

86.84
/vortex-duckdb/src/e2e_test/object_cache_test.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
//! Test table function that demonstrates object cache usage
5

6
use std::ffi::CString;
7

8
use vortex::error::{VortexResult, vortex_err};
9

10
use crate::cpp::DUCKDB_TYPE;
11
use crate::duckdb::{
12
    BindInput, BindResult, ClientContext, DataChunk, LogicalType, TableFunction, TableInitInput,
13
};
14

15
#[derive(Debug, Clone)]
16
pub struct TestTableFunction;
17

18
#[derive(Debug, Clone)]
19
pub struct TestBindData {
20
    cache_key: String,
21
}
22

23
#[derive(Debug)]
24
pub struct TestGlobalState;
25

26
#[derive(Debug)]
27
pub struct TestLocalState;
28

29
#[derive(Debug, PartialEq)]
30
struct CachedData {
31
    message: String,
32
    count: i32,
33
}
34

35
impl TableFunction for TestTableFunction {
36
    type BindData = TestBindData;
37
    type GlobalState = TestGlobalState;
38
    type LocalState = TestLocalState;
39

40
    fn bind(
1✔
41
        client_context: &ClientContext,
1✔
42
        _input: &BindInput,
1✔
43
        result: &mut BindResult,
1✔
44
    ) -> VortexResult<Self::BindData> {
1✔
45
        let logical_type = LogicalType::new(DUCKDB_TYPE::DUCKDB_TYPE_BIGINT);
1✔
46
        result.add_result_column("test_value", &logical_type);
1✔
47

48
        let cache = client_context.object_cache();
1✔
49
        let cached_data = CachedData {
1✔
50
            message: "Hello from bind phase cache!".to_string(),
1✔
51
            count: 123,
1✔
52
        };
1✔
53

54
        // Store data in cache during bind
55
        cache.put("bind_phase_data", cached_data);
1✔
56

57
        Ok(TestBindData {
1✔
58
            cache_key: "test_table_function_data".to_string(),
1✔
59
        })
1✔
60
    }
1✔
61

62
    fn scan(
8✔
63
        _client_context: &ClientContext,
8✔
64
        _bind_data: &Self::BindData,
8✔
65
        _local_state: &mut Self::LocalState,
8✔
66
        _global_state: &mut Self::GlobalState,
8✔
67
        chunk: &mut DataChunk,
8✔
68
    ) -> VortexResult<()> {
8✔
69
        chunk.set_len(0);
8✔
70

71
        Ok(())
8✔
72
    }
8✔
73

74
    fn init_global(input: &TableInitInput<Self>) -> VortexResult<Self::GlobalState> {
1✔
75
        if let Ok(ctx) = input.client_context() {
1✔
76
            let cached_data = CachedData {
1✔
77
                message: "Hello from table function cache!".to_string(),
1✔
78
                count: 42,
1✔
79
            };
1✔
80
            let cache = ctx.object_cache();
1✔
81

1✔
82
            cache.put(&input.bind_data().cache_key, cached_data);
1✔
83
        }
1✔
84

85
        Ok(TestGlobalState)
1✔
86
    }
1✔
87

88
    fn init_local(
8✔
89
        _init: &TableInitInput<Self>,
8✔
90
        _global: &mut Self::GlobalState,
8✔
91
    ) -> VortexResult<Self::LocalState> {
8✔
92
        Ok(TestLocalState)
8✔
93
    }
8✔
94

95
    fn partition_data(
×
96
        _bind_data: &Self::BindData,
×
97
        _global_init_data: &mut Self::GlobalState,
×
98
        _local_init_data: &mut Self::LocalState,
×
99
    ) -> VortexResult<u64> {
×
100
        Ok(0)
×
101
    }
×
102
}
103

104
use crate::duckdb::Database;
105

106
#[test]
107
fn test_table_function_with_object_cache() -> VortexResult<()> {
1✔
108
    let db = Database::open_in_memory()?;
1✔
109
    let conn = db.connect()?;
1✔
110

111
    // Register our test table function
112
    let name = CString::new("test_cache_func").map_err(|e| vortex_err!("CString error: {}", e))?;
1✔
113
    conn.register_table_function::<TestTableFunction>(&name)?;
1✔
114

115
    // Call the table function - this should store data in the cache during init_global
116
    let _result = conn.query("SELECT * FROM test_cache_func()")?;
1✔
117

118
    // Try to verify that we can access the cached data from outside the table function
119
    // This part is optional since we're not sure if the object cache access is working yet
120
    let ctx = conn.client_context();
1✔
121
    if let Ok(ctx) = ctx {
1✔
122
        let cache = ctx.object_cache();
1✔
123
        // Check data from bind phase
124
        let bind_cached_data = cache.get::<CachedData>("bind_phase_data");
1✔
125
        if let Some(data) = bind_cached_data {
1✔
126
            assert_eq!(data.message, "Hello from bind phase cache!");
1✔
127
            assert_eq!(data.count, 123);
1✔
128
            println!("Successfully retrieved bind phase cached data!");
1✔
UNCOV
129
        }
×
130

131
        // Check data from init_global phase
132
        let cached_data = cache.get::<CachedData>("test_table_function_data");
1✔
133
        if let Some(data) = cached_data {
1✔
134
            assert_eq!(data.message, "Hello from table function cache!");
1✔
135
            assert_eq!(data.count, 42);
1✔
136
            println!("Successfully retrieved init_global phase cached data!");
1✔
UNCOV
137
        }
×
UNCOV
138
    }
×
139

140
    Ok(())
1✔
141
}
1✔
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