mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 23:14:07 +00:00
Extend exception handling (#1884)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run
This commit is contained in:
parent
185a490218
commit
204d3b484d
8 changed files with 178 additions and 67 deletions
|
@ -4082,3 +4082,67 @@ fn parse_connect_by_root_operator() {
|
|||
"sql parser error: Expected an expression, found: FROM"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_begin_exception_end() {
|
||||
for sql in [
|
||||
"BEGIN SELECT 1; EXCEPTION WHEN OTHER THEN SELECT 2; RAISE; END",
|
||||
"BEGIN SELECT 1; EXCEPTION WHEN OTHER THEN SELECT 2; RAISE EX_1; END",
|
||||
"BEGIN SELECT 1; EXCEPTION WHEN FOO THEN SELECT 2; WHEN OTHER THEN SELECT 3; RAISE; END",
|
||||
"BEGIN BEGIN SELECT 1; EXCEPTION WHEN OTHER THEN SELECT 2; RAISE; END; END",
|
||||
] {
|
||||
snowflake().verified_stmt(sql);
|
||||
}
|
||||
|
||||
let sql = r#"
|
||||
DECLARE
|
||||
EXCEPTION_1 EXCEPTION (-20001, 'I caught the expected exception.');
|
||||
EXCEPTION_2 EXCEPTION (-20002, 'Not the expected exception!');
|
||||
EXCEPTION_3 EXCEPTION (-20003, 'The worst exception...');
|
||||
BEGIN
|
||||
BEGIN
|
||||
SELECT 1;
|
||||
EXCEPTION
|
||||
WHEN EXCEPTION_1 THEN
|
||||
SELECT 1;
|
||||
WHEN EXCEPTION_2 OR EXCEPTION_3 THEN
|
||||
SELECT 2;
|
||||
SELECT 3;
|
||||
WHEN OTHER THEN
|
||||
SELECT 4;
|
||||
RAISE;
|
||||
END;
|
||||
END
|
||||
"#;
|
||||
|
||||
// Outer `BEGIN` of the two nested `BEGIN` statements.
|
||||
let Statement::StartTransaction { mut statements, .. } = snowflake()
|
||||
.parse_sql_statements(sql)
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap()
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
// Inner `BEGIN` of the two nested `BEGIN` statements.
|
||||
let Statement::StartTransaction {
|
||||
statements,
|
||||
exception,
|
||||
has_end_keyword,
|
||||
..
|
||||
} = statements.pop().unwrap()
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
assert_eq!(1, statements.len());
|
||||
assert!(has_end_keyword);
|
||||
|
||||
let exception = exception.unwrap();
|
||||
assert_eq!(3, exception.len());
|
||||
assert_eq!(1, exception[0].idents.len());
|
||||
assert_eq!(1, exception[0].statements.len());
|
||||
assert_eq!(2, exception[1].idents.len());
|
||||
assert_eq!(2, exception[1].statements.len());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue