Support postgres CREATE FUNCTION (#722)

* support basic pg CREATE FUNCTION

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* support function argument

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* fix display and use verify in test

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* support OR REPLACE

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* fix compile error in bigdecimal

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* unify all `CreateFunctionBody` to a structure

Signed-off-by: Runji Wang <wangrunji0408@163.com>

Signed-off-by: Runji Wang <wangrunji0408@163.com>
This commit is contained in:
Runji Wang 2022-12-02 05:08:49 +08:00 committed by GitHub
parent f621142f89
commit 5b53df97c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 331 additions and 29 deletions

View file

@ -16,8 +16,8 @@
//! is also tested (on the inputs it can handle).
use sqlparser::ast::{
CreateFunctionUsing, Expr, Function, Ident, ObjectName, SelectItem, Statement, TableFactor,
UnaryOperator, Value,
CreateFunctionBody, CreateFunctionUsing, Expr, Function, Ident, ObjectName, SelectItem,
Statement, TableFactor, UnaryOperator, Value,
};
use sqlparser::dialect::{GenericDialect, HiveDialect};
use sqlparser::parser::ParserError;
@ -244,17 +244,20 @@ fn parse_create_function() {
Statement::CreateFunction {
temporary,
name,
class_name,
using,
params,
..
} => {
assert!(temporary);
assert_eq!("mydb.myfunc", name.to_string());
assert_eq!("org.random.class.Name", class_name);
assert_eq!(name.to_string(), "mydb.myfunc");
assert_eq!(
using,
Some(CreateFunctionUsing::Jar(
"hdfs://somewhere.com:8020/very/far".to_string()
))
params,
CreateFunctionBody {
as_: Some("org.random.class.Name".to_string()),
using: Some(CreateFunctionUsing::Jar(
"hdfs://somewhere.com:8020/very/far".to_string()
)),
..Default::default()
}
)
}
_ => unreachable!(),