@@ -73,12 +73,13 @@ impl ArrowFunctionSignature {
7373
7474/// A trait for scalar functions that accept and return arrow types that can be registered with DuckDB
7575pub trait VArrowScalar : Sized {
76- /// State that persists across invocations of the scalar function (the lifetime of the connection)
77- /// The state can be accessed by multiple threads, so it must be `Send + Sync`.
78- type State : Default + Sized + Send + Sync ;
76+ /// State set at registration time. Persists for the lifetime of the catalog entry.
77+ /// Shared across worker threads and invocations — must not be modified during execution.
78+ /// Must be `'static` as it is stored in DuckDB and may outlive the current stack frame.
79+ type State : Default + Sized + Send + Sync + ' static ;
7980
8081 /// The actual function that is called by DuckDB
81- fn invoke ( info : & Self :: State , 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 > > ;
8283
8384 /// The possible signatures of the scalar function. These will result in DuckDB scalar function overloads.
8485 /// The invoke method should be able to handle all of these signatures.
@@ -92,11 +93,11 @@ where
9293 type State = T :: State ;
9394
9495 unsafe fn invoke (
95- info : & Self :: State ,
96+ state : & Self :: State ,
9697 input : & mut DataChunkHandle ,
9798 out : & mut dyn WritableVector ,
9899 ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
99- let array = T :: invoke ( info , data_chunk_to_arrow ( input) ?) ?;
100+ let array = T :: invoke ( state , data_chunk_to_arrow ( input) ?) ?;
100101 write_arrow_array_to_vector ( & array, out)
101102 }
102103
@@ -200,8 +201,8 @@ mod test {
200201 impl VArrowScalar for ArrowOverloaded {
201202 type State = MockState ;
202203
203- fn invoke ( s : & Self :: State , input : RecordBatch ) -> Result < Arc < dyn Array > , Box < dyn std:: error:: Error > > {
204- assert_eq ! ( "some meta" , s . 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) ;
205206
206207 let a = input. column ( 0 ) ;
207208 let b = input. column ( 1 ) ;
0 commit comments