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

#[udf] macro for simple functions #53

Open
tgross35 opened this issue Mar 31, 2023 · 1 comment
Open

#[udf] macro for simple functions #53

tgross35 opened this issue Mar 31, 2023 · 1 comment

Comments

@tgross35
Copy link
Contributor

tgross35 commented Mar 31, 2023

It would be nice to provide a simplified interface for the most common needs:

#[udf]
fn my_udf(a: Option<&str>, b: f64, c: &str) -> Option<i32> {
}

#[udf]
fn my_udf2(cache: &mut Vec<u8>, a: Option<&str>, b: f64, c: &str) -> Result<&[u8], String> {
}

// If init is not specified, default to Default
#[udf(init = MyStruct::new())]
fn my_udf3(cache: &mut MyStruct, a: Option<&str>, b: f64, c: &str) -> &[u8] {
}

// desugars to something like
mod my_udf_mod {
    struct MyUdf(Vec<u8>);

    #[register]
    impl BasicUdf for MyUdf {
        returning = Option<i32>;
        fn init(...) { /* autogenerated, verify types */ }
        fn process(&mut self...) {
            // generate user defined types
            let arg1 = args.get(0).as_str();
            my_udf(self.0, arg1, arg2, arg3)
        }
    }
    
    fn my_udf(a: Option<&str>, b: f64, c: &str) -> Option<i32> {
    }
}

The work would be entirely in the proc macro and would just desugar to our current traits. Some way to define >1 function signature would also be cool, but I don't quite know how to combine them together without having them in the same block

@tgross35
Copy link
Contributor Author

Actually... it may be easiest to add a derive argument for arg types

#[derive(SqlArgs)]
struct Args <'a>{
    a: u64,
    b: &'a str,
    c: Option<Vec<f64>>
}

#[udf]
fn foo( {a, b, c}: Args) -> String {
    todo!()
}

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

No branches or pull requests

1 participant