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
Support postgres CREATE FUNCTION
#722
Support postgres CREATE FUNCTION
#722
Conversation
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Pull Request Test Coverage Report for Build 3590787964
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the contribution @wangrunji0408
I had a question about the use of Vec<CreateFunctionBody>
but otherwise this PR is looking good. Thank you!
cc @AugustoFKL
cc @mobuchowski as you contributed the original CREATE FUNCTION
#496
src/ast/mod.rs
Outdated
using: Option<CreateFunctionUsing>, | ||
args: Option<Vec<CreateFunctionArg>>, | ||
return_type: Option<DataType>, | ||
bodies: Vec<CreateFunctionBody>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the Vec<CreateFunctionBody>
somewhat confusing as it implies that some of them can be repeated. For example, can there be two CreateFunctionBody::Returning
in this list? I don't think it is possible
Did you consider creating optional fields to encode this in the type system itself?
So instead of
CreateFunction {
or_replace: bool,
temporary: bool,
name: ObjectName,
args: Option<Vec<CreateFunctionArg>>,
return_type: Option<DataType>,
bodies: Vec<CreateFunctionBody>,
Something like
CreateFunction {
or_replace: bool,
temporary: bool,
name: ObjectName,
args: Option<Vec<CreateFunctionArg>>,
return_type: Option<DataType>,
as: Option<String>.
/// LANGUAGE lang_name
language: Option<Ident>,
...
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alamb @wangrunji0408 I have some time, but will not be able to review the whole PR RN, sorry.
-
The return type does not match the PostgreSQL syntax. @alamb, do you think it's reasonable to add something like a
SUPPORTED SYNTAX
field to the header of the structure? Here's an example that I'm implementing for myself. -
@wangrunji0408, for the body structure, it's a problem that we can repeat. You're creating a syntax that can be built wrong for a single dialect. Please let us know if you have a good reason (something like it being repeatable on Snowflake or something like that). However, @alamb, I think having all of them, as you showed, makes building it complex and moving it as well. Sometimes the upstream only wants to handle one or two scenarios, not the whole object. My suggestion is to have a structure that encapsulates them all:
CREATE FUNCTION {
...,
or_replace: bool,
temporary: bool,
name: ObjectName,
args: Option<Vec<CreateFunctionArg>>,
return_type: Option<DataType>,
opt_body: Option<FunctionBody>,
}
pub enum FunctionBody {
Language...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @AugustoFKL and @alamb regarding repeatable structures.
From my side, I can still express Hive's CREATE FUNCTION
syntax so it looks good for me - for me it's okay to change my code when bumping sqlparser-rs dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this catch. I didn't realize the problem with duplicate items. It has been changed to the way @AugustoFKL mentioned above.
src/ast/mod.rs
Outdated
using: Option<CreateFunctionUsing>, | ||
args: Option<Vec<CreateFunctionArg>>, | ||
return_type: Option<DataType>, | ||
bodies: Vec<CreateFunctionBody>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @AugustoFKL and @alamb regarding repeatable structures.
From my side, I can still express Hive's CREATE FUNCTION
syntax so it looks good for me - for me it's okay to change my code when bumping sqlparser-rs dependency.
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me -- thank you @wangrunji0408
pub behavior: Option<FunctionBehavior>, | ||
/// AS 'definition' | ||
/// | ||
/// Note that Hive's `AS class_name` is also parsed here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This PR adds some support for postgres
CREATE FUNCTION
based on:https://www.postgresql.org/docs/15/sql-createfunction.html
To live with the hive syntax introduced by #496, we move its field
class_name
andusing
into the newCreateFunctionBody
structure.