Skip to content

Commit b96eda5

Browse files
committed
Reverted public API breaking changes
1 parent 3bc637a commit b96eda5

File tree

3 files changed

+36
-43
lines changed

3 files changed

+36
-43
lines changed

crates/duckdb/src/r2d2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl DuckdbConnectionManager {
9292
#[cfg(feature = "vscalar")]
9393
pub fn register_scalar_function<S: VScalar>(&self, name: &str) -> Result<()>
9494
where
95-
S::ExtraInfo: Debug + Default,
95+
S::State: Debug + Default,
9696
{
9797
let conn = self.connection.lock().unwrap();
9898
conn.register_scalar_function::<S>(name)

crates/duckdb/src/vscalar/arrow.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ impl ArrowFunctionSignature {
7373

7474
/// A trait for scalar functions that accept and return arrow types that can be registered with DuckDB
7575
pub trait VArrowScalar: Sized {
76-
/// Extra info set at registration time. Persists for the lifetime of the catalog entry.
76+
/// State set at registration time. Persists for the lifetime of the catalog entry.
7777
/// Shared across worker threads and invocations — must not be modified during execution.
7878
/// Must be `'static` as it is stored in DuckDB and may outlive the current stack frame.
79-
type ExtraInfo: Default + Sized + Send + Sync + 'static;
79+
type State: Default + Sized + Send + Sync + 'static;
8080

8181
/// The actual function that is called by DuckDB
82-
fn invoke(extra_info: &Self::ExtraInfo, input: RecordBatch) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>>;
82+
fn invoke(state: &Self::State, input: RecordBatch) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>>;
8383

8484
/// The possible signatures of the scalar function. These will result in DuckDB scalar function overloads.
8585
/// The invoke method should be able to handle all of these signatures.
@@ -90,14 +90,14 @@ impl<T> VScalar for T
9090
where
9191
T: VArrowScalar,
9292
{
93-
type ExtraInfo = T::ExtraInfo;
93+
type State = T::State;
9494

9595
unsafe fn invoke(
96-
extra_info: &Self::ExtraInfo,
96+
state: &Self::State,
9797
input: &mut DataChunkHandle,
9898
out: &mut dyn WritableVector,
9999
) -> Result<(), Box<dyn std::error::Error>> {
100-
let array = T::invoke(extra_info, data_chunk_to_arrow(input)?)?;
100+
let array = T::invoke(state, data_chunk_to_arrow(input)?)?;
101101
write_arrow_array_to_vector(&array, out)
102102
}
103103

@@ -129,9 +129,9 @@ mod test {
129129
struct HelloScalarArrow {}
130130

131131
impl VArrowScalar for HelloScalarArrow {
132-
type ExtraInfo = ();
132+
type State = ();
133133

134-
fn invoke(_: &Self::ExtraInfo, input: RecordBatch) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>> {
134+
fn invoke(_: &Self::State, input: RecordBatch) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>> {
135135
let name = input.column(0).as_any().downcast_ref::<StringArray>().unwrap();
136136
let result = name.iter().map(|v| format!("Hello {}", v.unwrap())).collect::<Vec<_>>();
137137
Ok(Arc::new(StringArray::from(result)))
@@ -164,9 +164,9 @@ mod test {
164164
struct ArrowMultiplyScalar {}
165165

166166
impl VArrowScalar for ArrowMultiplyScalar {
167-
type ExtraInfo = MockState;
167+
type State = MockState;
168168

169-
fn invoke(_: &Self::ExtraInfo, input: RecordBatch) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>> {
169+
fn invoke(_: &Self::State, input: RecordBatch) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>> {
170170
let a = input
171171
.column(0)
172172
.as_any()
@@ -199,13 +199,10 @@ mod test {
199199
struct ArrowOverloaded {}
200200

201201
impl VArrowScalar for ArrowOverloaded {
202-
type ExtraInfo = MockState;
202+
type State = MockState;
203203

204-
fn invoke(
205-
extra_info: &Self::ExtraInfo,
206-
input: RecordBatch,
207-
) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>> {
208-
assert_eq!("some meta", extra_info.info);
204+
fn invoke(state: &Self::State, input: RecordBatch) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>> {
205+
assert_eq!("some meta", state.info);
209206

210207
let a = input.column(0);
211208
let b = input.column(1);
@@ -339,9 +336,9 @@ mod test {
339336
struct SplitFunction {}
340337

341338
impl VArrowScalar for SplitFunction {
342-
type ExtraInfo = ();
339+
type State = ();
343340

344-
fn invoke(_: &Self::ExtraInfo, input: RecordBatch) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>> {
341+
fn invoke(_: &Self::State, input: RecordBatch) -> Result<Arc<dyn Array>, Box<dyn std::error::Error>> {
345342
let strings = input.column(0).as_any().downcast_ref::<StringArray>().unwrap();
346343

347344
let mut builder = arrow::array::ListBuilder::new(arrow::array::StringBuilder::with_capacity(

crates/duckdb/src/vscalar/mod.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ pub use arrow::{ArrowFunctionSignature, ArrowScalarParams, VArrowScalar};
2323

2424
/// Duckdb scalar function trait
2525
pub trait VScalar: Sized {
26-
/// Extra info set at registration time. Persists for the lifetime of the catalog entry.
26+
/// State set at registration time. Persists for the lifetime of the catalog entry.
2727
/// Shared across worker threads and invocations — must not be modified during execution.
2828
/// Must be `'static` as it is stored in DuckDB and may outlive the current stack frame.
29-
type ExtraInfo: Sized + Send + Sync + 'static;
29+
type State: Sized + Send + Sync + 'static;
3030
/// The actual function
3131
///
3232
/// # Safety
@@ -36,7 +36,7 @@ pub trait VScalar: Sized {
3636
/// - Dereferences multiple raw pointers (`func`).
3737
///
3838
unsafe fn invoke(
39-
extra_info: &Self::ExtraInfo,
39+
state: &Self::State,
4040
input: &mut DataChunkHandle,
4141
output: &mut dyn WritableVector,
4242
) -> Result<(), Box<dyn std::error::Error>>;
@@ -133,41 +133,37 @@ where
133133
}
134134

135135
impl Connection {
136-
/// Register the given ScalarFunction with default extra info.
136+
/// Register the given ScalarFunction with default state.
137137
#[inline]
138138
pub fn register_scalar_function<S: VScalar>(&self, name: &str) -> crate::Result<()>
139139
where
140-
S::ExtraInfo: Default,
140+
S::State: Default,
141141
{
142142
let set = ScalarFunctionSet::new(name);
143143
for signature in S::signatures() {
144144
let scalar_function = ScalarFunction::new(name)?;
145145
signature.register_with_scalar(&scalar_function);
146146
scalar_function.set_function(Some(scalar_func::<S>));
147-
scalar_function.set_extra_info(S::ExtraInfo::default());
147+
scalar_function.set_extra_info(S::State::default());
148148
set.add_function(scalar_function)?;
149149
}
150150
self.db.borrow_mut().register_scalar_function_set(set)
151151
}
152152

153-
/// Register the given ScalarFunction with custom extra info.
153+
/// Register the given ScalarFunction with custom state.
154154
///
155-
/// The extra info is cloned once per function signature (overload) and stored in DuckDB's catalog.
155+
/// The state is cloned once per function signature (overload) and stored in DuckDB's catalog.
156156
#[inline]
157-
pub fn register_scalar_function_with_extra_info<S: VScalar>(
158-
&self,
159-
name: &str,
160-
extra_info: &S::ExtraInfo,
161-
) -> crate::Result<()>
157+
pub fn register_scalar_function_with_state<S: VScalar>(&self, name: &str, state: &S::State) -> crate::Result<()>
162158
where
163-
S::ExtraInfo: Clone,
159+
S::State: Clone,
164160
{
165161
let set = ScalarFunctionSet::new(name);
166162
for signature in S::signatures() {
167163
let scalar_function = ScalarFunction::new(name)?;
168164
signature.register_with_scalar(&scalar_function);
169165
scalar_function.set_function(Some(scalar_func::<S>));
170-
scalar_function.set_extra_info(extra_info.clone());
166+
scalar_function.set_extra_info(state.clone());
171167
set.add_function(scalar_function)?;
172168
}
173169
self.db.borrow_mut().register_scalar_function_set(set)
@@ -200,10 +196,10 @@ mod test {
200196
struct ErrorScalar {}
201197

202198
impl VScalar for ErrorScalar {
203-
type ExtraInfo = ();
199+
type State = ();
204200

205201
unsafe fn invoke(
206-
_: &Self::ExtraInfo,
202+
_: &Self::State,
207203
input: &mut DataChunkHandle,
208204
_: &mut dyn WritableVector,
209205
) -> Result<(), Box<dyn std::error::Error>> {
@@ -238,10 +234,10 @@ mod test {
238234
struct EchoScalar {}
239235

240236
impl VScalar for EchoScalar {
241-
type ExtraInfo = TestState;
237+
type State = TestState;
242238

243239
unsafe fn invoke(
244-
extra_info: &Self::ExtraInfo,
240+
state: &Self::State,
245241
input: &mut DataChunkHandle,
246242
output: &mut dyn WritableVector,
247243
) -> Result<(), Box<dyn std::error::Error>> {
@@ -254,7 +250,7 @@ mod test {
254250
let output = output.flat_vector();
255251

256252
for s in strings {
257-
let res = format!("{}: {}", extra_info.prefix, s.repeat(extra_info.multiplier));
253+
let res = format!("{}: {}", state.prefix, s.repeat(state.multiplier));
258254
output.insert(0, res.as_str());
259255
}
260256
Ok(())
@@ -271,10 +267,10 @@ mod test {
271267
struct Repeat {}
272268

273269
impl VScalar for Repeat {
274-
type ExtraInfo = ();
270+
type State = ();
275271

276272
unsafe fn invoke(
277-
_: &Self::ExtraInfo,
273+
_: &Self::State,
278274
input: &mut DataChunkHandle,
279275
output: &mut dyn WritableVector,
280276
) -> Result<(), Box<dyn std::error::Error>> {
@@ -321,9 +317,9 @@ mod test {
321317
}
322318
}
323319

324-
// Test with custom extra info
320+
// Test with custom state
325321
{
326-
conn.register_scalar_function_with_extra_info::<EchoScalar>(
322+
conn.register_scalar_function_with_state::<EchoScalar>(
327323
"echo2",
328324
&TestState {
329325
multiplier: 5,

0 commit comments

Comments
 (0)