Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugable handler for CREATE FUNCTION #9332

Closed
milenkovicm opened this issue Feb 24, 2024 · 2 comments · Fixed by #9333
Closed

Plugable handler for CREATE FUNCTION #9332

milenkovicm opened this issue Feb 24, 2024 · 2 comments · Fixed by #9333
Labels
enhancement New feature or request

Comments

@milenkovicm
Copy link
Contributor

milenkovicm commented Feb 24, 2024

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, without bringing them to core library.

Describe the solution you'd like

A solution would allow users to declare functions like:

CREATE FUNCTION iris(FLOAT[])
RETURNS FLOAT[]
LANGUAGE TORCH
AS 'models:/iris@champion'

or

CREATE FUNCTION add(BIGINT, BIGINT)
RETURNS BIGINT
LANGUAGE SQL
RETURN $1 + $2

CREATE FUNCTION handler would be configured at the SessionContext configuration phase:

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))
    // we configure a torch function factory
    // to handle CREATE (and DROP) FUNCTION requests
    .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

@alamb
Copy link
Contributor

alamb commented Feb 28, 2024

This would be quite cool (for example, it could potentially be used to support WASM udfs #9326).

@alamb alamb mentioned this issue Feb 28, 2024
@milenkovicm
Copy link
Contributor Author

yes, that would be third good use case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants