milenkovicm opened a new issue, #9332:
URL: https://github.com/apache/arrow-datafusion/issues/9332

   ### Is your feature request related to a problem or challenge?
   
   At the moment datafusion does not support `CREATE FUNCTION`, it only exposes 
programatic api for UDF declaration. 
   Programatic approach does not support declarative `UDF`, and would not work 
with `SQL` only interaction.
    
   I believe that we could expose a pluggable interface like `FunctionFactory`  
(part of `SessionState`) where user can plug their own  `CREATE FUNCTION` 
handler, and plug their own declarative `UDFs`
   
   ### Describe the solution you'd like
   
   A solution would allow users to declare functions like:
   
   ```sql
   CREATE FUNCTION iris(FLOAT)
   RETURNS FLOAT
   LANGUAGE TORCH
   AS '/models/iris.pt'
   ```
   
   or 
   
   ```sql
   CREATE FUNCTION add(BIGINT, BIGINT)
   RETURNS BIGINT
   LANGUAGE SQL
   RETURN $1 + $2
   ```
   
   `CREATE FUNCTION` handler would be configured at the `SessionContext` 
configuration phase:
   
   
   ```rust
   let runtime_config = RuntimeConfig::new();
   let runtime_environment = RuntimeEnv::new(runtime_config).unwrap();
   let session_config =
       SessionConfig::new().set_str("datafusion.sql_parser.dialect", 
"PostgreSQL");
   let state = SessionState::new_with_config_rt(session_config, 
Arc::new(runtime_environment))
       .with_function_factory(Arc::new(TorchFunctionFactory {}));
   
   let ctx = SessionContext::new_with_state(state);
   ```
   
   in this example we define `TorchFunctionFactory`,
   
   full example can be found at https://github.com/milenkovicm/torchfusion
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to