Skip to content

Commit 660bbea

Browse files
committed
Revert "Change to register_table_function_with_options"
This reverts commit e3d2c66.
1 parent cc3efce commit 660bbea

File tree

2 files changed

+12
-37
lines changed

2 files changed

+12
-37
lines changed

crates/duckdb/src/vtab/function.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ impl BindInfo {
5151
/// Sets the user-provided bind data in the bind object. This object can be retrieved again during execution.
5252
///
5353
/// # Arguments
54-
/// * `data`: The bind data object.
55-
/// * `free_function`: The callback that will be called to destroy the bind data (if any)
56-
///
57-
/// # Safety
58-
/// `data` must be a valid pointer, and `free_function` must properly free it.
54+
/// * `extra_data`: The bind data object.
55+
/// * `destroy`: The callback that will be called to destroy the bind data (if any)
5956
pub unsafe fn set_bind_data(&self, data: *mut c_void, free_function: Option<unsafe extern "C" fn(*mut c_void)>) {
6057
duckdb_bind_set_bind_data(self.ptr, data, free_function);
6158
}

crates/duckdb/src/vtab/mod.rs

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,6 @@ mod excel;
2323
pub use function::{BindInfo, InitInfo, TableFunction, TableFunctionInfo};
2424
pub use value::Value;
2525

26-
/// Options for registering a table function.
27-
pub struct TableFunctionOptions<E> {
28-
/// Extra info passed to the function at runtime.
29-
/// Accessible via `BindInfo::get_extra_info`, `InitInfo::get_extra_info`,
30-
/// or `TableFunctionInfo::get_extra_info`.
31-
pub extra_info: Option<E>,
32-
}
33-
34-
impl<E> Default for TableFunctionOptions<E> {
35-
fn default() -> Self {
36-
Self { extra_info: None }
37-
}
38-
}
39-
4026
use crate::core::{DataChunkHandle, LogicalTypeHandle};
4127
use ffi::{duckdb_bind_info, duckdb_data_chunk, duckdb_function_info, duckdb_init_info};
4228

@@ -165,26 +151,23 @@ impl Connection {
165151
self.db.borrow_mut().register_table_function(table_function)
166152
}
167153

168-
/// Register the given TableFunction with options.
154+
/// Register the given TableFunction with custom extra info.
155+
///
156+
/// This allows you to pass extra info that can be accessed during bind, init, and execution
157+
/// via `BindInfo::get_extra_info`, `InitInfo::get_extra_info`, or `TableFunctionInfo::get_extra_info`.
169158
#[inline]
170-
pub fn register_table_function_with_options<T: VTab, E>(
171-
&self,
172-
name: &str,
173-
options: TableFunctionOptions<E>,
174-
) -> Result<()>
159+
pub fn register_table_function_with_extra_info<T: VTab, E>(&self, name: &str, extra_info: &E) -> Result<()>
175160
where
176-
E: Send + Sync + 'static,
161+
E: Clone + Send + Sync + 'static,
177162
{
178163
let table_function = TableFunction::default();
179164
table_function
180165
.set_name(name)
181166
.supports_pushdown(T::supports_pushdown())
182167
.set_bind(Some(bind::<T>))
183168
.set_init(Some(init::<T>))
184-
.set_function(Some(func::<T>));
185-
if let Some(extra_info) = options.extra_info {
186-
table_function.with_extra_info(extra_info);
187-
}
169+
.set_function(Some(func::<T>))
170+
.with_extra_info(extra_info.clone());
188171
for ty in T::parameters().unwrap_or_default() {
189172
table_function.add_parameter(&ty);
190173
}
@@ -371,14 +354,9 @@ mod test {
371354
}
372355

373356
#[test]
374-
fn test_table_function_with_options() -> Result<(), Box<dyn Error>> {
357+
fn test_table_function_with_extra_info() -> Result<(), Box<dyn Error>> {
375358
let conn = Connection::open_in_memory()?;
376-
conn.register_table_function_with_options::<PrefixVTab, _>(
377-
"greet",
378-
TableFunctionOptions {
379-
extra_info: Some("Howdy".to_string()),
380-
},
381-
)?;
359+
conn.register_table_function_with_extra_info::<PrefixVTab, _>("greet", &"Howdy".to_string())?;
382360

383361
let val = conn.query_row("select * from greet('partner')", [], |row| <(String,)>::try_from(row))?;
384362
assert_eq!(val, ("Howdy partner".to_string(),));

0 commit comments

Comments
 (0)