Skip to content

Commit

Permalink
feat: add more and more test
Browse files Browse the repository at this point in the history
Signed-off-by: Chojan Shang <[email protected]>
  • Loading branch information
PsiACE committed Feb 3, 2024
1 parent 58436ce commit a0dd18b
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/query/ast/tests/it/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@ fn test_statement() {
"GRANT OWNERSHIP ON d20_0014.t TO ROLE 'd20_0015_owner';",
"GRANT OWNERSHIP ON STAGE s1 TO ROLE 'd20_0015_owner';",
"GRANT OWNERSHIP ON UDF f1 TO ROLE 'd20_0015_owner';",
"CREATE FUNCTION IF NOT EXISTS isnotempty AS(p) -> not(is_null(p));",
"CREATE OR REPLACE FUNCTION isnotempty_test_replace AS(p) -> not(is_null(p)) DESC = 'This is a description';",
"CREATE FUNCTION binary_reverse (BINARY) RETURNS BINARY LANGUAGE python HANDLER = 'binary_reverse' ADDRESS = 'http://0.0.0.0:8815';",
"CREATE OR REPLACE FUNCTION binary_reverse (BINARY) RETURNS BINARY LANGUAGE python HANDLER = 'binary_reverse' ADDRESS = 'http://0.0.0.0:8815';",
"DROP FUNCTION binary_reverse;",
"DROP FUNCTION isnotempty;",
];

for case in cases {
Expand Down Expand Up @@ -651,6 +657,7 @@ fn test_statement_error() {
"REVOKE OWNERSHIP ON d20_0014.* FROM USER A;",
"REVOKE OWNERSHIP ON d20_0014.* FROM ROLE A;",
"GRANT OWNERSHIP ON *.* TO ROLE 'd20_0015_owner';",
"CREATE FUNCTION IF NOT EXISTS isnotempty AS(p) -> not(is_null(p)",
];

for case in cases {
Expand Down
15 changes: 15 additions & 0 deletions src/query/ast/tests/it/testdata/statement-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,18 @@ error:
| while parsing GRANT OWNERSHIP ON <privileges_level> TO ROLE <role_name>


---------- Input ----------
CREATE FUNCTION IF NOT EXISTS isnotempty AS(p) -> not(is_null(p)
---------- Output ---------
error:
--> SQL:1:65
|
1 | CREATE FUNCTION IF NOT EXISTS isnotempty AS(p) -> not(is_null(p)
| ------ -- ---- ^ unexpected end of line, expecting `)`, `OVER`, `(`, `IS`, `NOT`, `IN`, `EXISTS`, `BETWEEN`, `+`, `-`, `*`, `/`, `//`, `DIV`, `%`, `||`, `<->`, `>`, `<`, `>=`, `<=`, `=`, `<>`, `!=`, `^`, `AND`, `OR`, `XOR`, `LIKE`, `REGEXP`, `RLIKE`, `SOUNDS`, <BitWiseOr>, <BitWiseAnd>, <BitWiseXor>, <ShiftLeft>, <ShiftRight>, `->`, `->>`, `#>`, `#>>`, `?`, `?|`, `?&`, `@>`, `<@`, `@?`, `@@`, <Factorial>, <SquareRoot>, <BitWiseNot>, <CubeRoot>, <Abs>, `CAST`, `TRY_CAST`, `DATE_ADD`, `DATE_SUB`, `DATE_TRUNC`, `DATE`, `TIMESTAMP`, or 29 more ...
| | | | |
| | | | while parsing `(<expr> [, ...])`
| | | while parsing expression
| | while parsing AS (<parameter>, ...) -> <definition expr>
| while parsing `CREATE [OR REPLACE] FUNCTION [IF NOT EXISTS] <name> {AS (<parameter>, ...) -> <definition expr> | (<arg_type>, ...) RETURNS <return_type> LANGUAGE <language> HANDLER=<handler> ADDRESS=<udf_server_address>} [DESC = <description>]`


248 changes: 248 additions & 0 deletions src/query/ast/tests/it/testdata/statement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15109,3 +15109,251 @@ Grant(
)


---------- Input ----------
CREATE FUNCTION IF NOT EXISTS isnotempty AS(p) -> not(is_null(p));
---------- Output ---------
CREATE FUNCTION IF NOT EXISTS isnotempty AS (p) -> (NOT is_null(p))
---------- AST ------------
CreateUDF(
CreateUDFStmt {
create_option: CreateIfNotExists(
true,
),
udf_name: Identifier {
name: "isnotempty",
quote: None,
span: Some(
30..40,
),
},
description: None,
definition: LambdaUDF {
parameters: [
Identifier {
name: "p",
quote: None,
span: Some(
44..45,
),
},
],
definition: UnaryOp {
span: Some(
50..53,
),
op: Not,
expr: FunctionCall {
span: Some(
54..64,
),
distinct: false,
name: Identifier {
name: "is_null",
quote: None,
span: Some(
54..61,
),
},
args: [
ColumnRef {
span: Some(
62..63,
),
database: None,
table: None,
column: Name(
Identifier {
name: "p",
quote: None,
span: Some(
62..63,
),
},
),
},
],
params: [],
window: None,
lambda: None,
},
},
},
},
)


---------- Input ----------
CREATE OR REPLACE FUNCTION isnotempty_test_replace AS(p) -> not(is_null(p)) DESC = 'This is a description';
---------- Output ---------
CREATE OR REPLACE FUNCTION isnotempty_test_replace AS (p) -> (NOT is_null(p)) DESC = 'This is a description'
---------- AST ------------
CreateUDF(
CreateUDFStmt {
create_option: CreateOrReplace,
udf_name: Identifier {
name: "isnotempty_test_replace",
quote: None,
span: Some(
27..50,
),
},
description: Some(
"This is a description",
),
definition: LambdaUDF {
parameters: [
Identifier {
name: "p",
quote: None,
span: Some(
54..55,
),
},
],
definition: UnaryOp {
span: Some(
60..63,
),
op: Not,
expr: FunctionCall {
span: Some(
64..74,
),
distinct: false,
name: Identifier {
name: "is_null",
quote: None,
span: Some(
64..71,
),
},
args: [
ColumnRef {
span: Some(
72..73,
),
database: None,
table: None,
column: Name(
Identifier {
name: "p",
quote: None,
span: Some(
72..73,
),
},
),
},
],
params: [],
window: None,
lambda: None,
},
},
},
},
)


---------- Input ----------
CREATE FUNCTION binary_reverse (BINARY) RETURNS BINARY LANGUAGE python HANDLER = 'binary_reverse' ADDRESS = 'http://0.0.0.0:8815';
---------- Output ---------
CREATE FUNCTION binary_reverse (BINARY NULL) RETURNS BINARY NULL LANGUAGE python HANDLER = binary_reverse ADDRESS = http://0.0.0.0:8815
---------- AST ------------
CreateUDF(
CreateUDFStmt {
create_option: CreateIfNotExists(
false,
),
udf_name: Identifier {
name: "binary_reverse",
quote: None,
span: Some(
16..30,
),
},
description: None,
definition: UDFServer {
arg_types: [
Nullable(
Binary,
),
],
return_type: Nullable(
Binary,
),
address: "http://0.0.0.0:8815",
handler: "binary_reverse",
language: "python",
},
},
)


---------- Input ----------
CREATE OR REPLACE FUNCTION binary_reverse (BINARY) RETURNS BINARY LANGUAGE python HANDLER = 'binary_reverse' ADDRESS = 'http://0.0.0.0:8815';
---------- Output ---------
CREATE OR REPLACE FUNCTION binary_reverse (BINARY NULL) RETURNS BINARY NULL LANGUAGE python HANDLER = binary_reverse ADDRESS = http://0.0.0.0:8815
---------- AST ------------
CreateUDF(
CreateUDFStmt {
create_option: CreateOrReplace,
udf_name: Identifier {
name: "binary_reverse",
quote: None,
span: Some(
27..41,
),
},
description: None,
definition: UDFServer {
arg_types: [
Nullable(
Binary,
),
],
return_type: Nullable(
Binary,
),
address: "http://0.0.0.0:8815",
handler: "binary_reverse",
language: "python",
},
},
)


---------- Input ----------
DROP FUNCTION binary_reverse;
---------- Output ---------
DROP FUNCTION binary_reverse
---------- AST ------------
DropUDF {
if_exists: false,
udf_name: Identifier {
name: "binary_reverse",
quote: None,
span: Some(
14..28,
),
},
}


---------- Input ----------
DROP FUNCTION isnotempty;
---------- Output ---------
DROP FUNCTION isnotempty
---------- AST ------------
DropUDF {
if_exists: false,
udf_name: Identifier {
name: "isnotempty",
quote: None,
span: Some(
14..24,
),
},
}


15 changes: 15 additions & 0 deletions tests/sqllogictests/suites/base/05_ddl/05_0010_ddl_create_udf.test
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,18 @@ DROP FUNCTION isnotempty

statement ok
DROP FUNCTION isnotempty_with_desc

statement ok
DROP FUNCTION IF EXISTS 'isnotempty_test_replace';

statement error 1105
CREATE OR REPLACE FUNCTION IF NOT EXISTS isnotempty_test_replace AS(p) -> not(is_null(p));

statement ok
CREATE OR REPLACE FUNCTION isnotempty_test_replace AS(p) -> not(is_null(p));

statement ok
CREATE OR REPLACE FUNCTION isnotempty_test_replace AS(p) -> not(is_null(p)) DESC = 'This is a description';

statement ok
DROP FUNCTION IF EXISTS isnotempty_test_replace

0 comments on commit a0dd18b

Please sign in to comment.