yuyang-ok commented on issue #1356:
URL:
https://github.com/apache/datafusion-sqlparser-rs/issues/1356#issuecomment-2510540712
I am trying to parse function body But I am getting a error.
~~~
#[cfg(test)]
mod tests {
#[test]
fn test_sql_statement() {
let sql = r#"
DECLARE
result INT := 1;
BEGIN
IF n < 0 THEN
RETURN NULL; -- 负数的阶乘未定义
ELSIF n = 0 THEN
RETURN 1; -- 0 的阶乘为 1
ELSE
FOR i IN 1..n LOOP
result := result * i;
END LOOP;
RETURN result;
END IF;
END;
"#;
let dialect = sqlparser::dialect::PostgreSqlDialect {};
let p = sqlparser::parser::Parser::new(&dialect);
let mut p = p.try_with_sql(sql).unwrap();
let statement = p.parse_statement().unwrap();
// let s = serde_json::to_string(match &statement {
// Statement::Delete(x) => &x.from,
// _ => {
// unreachable!()
// }
// })
// .unwrap();
let s = serde_json::to_string(&statement).unwrap();
println!("{}", s);
}
}
~~~
~~~
running 1 test
thread 'sqlparser_completion::tests::test_sql_statement' panicked at
dbnexus-db/src/sqlparser_completion.rs:954:45:
called `Result::unwrap()` on an `Err` value: ParserError("Expected: CURSOR,
found: INT at Line: 4, Column: 12")
stack backtrace:
0: rust_begin_unwind
at
/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:662:5
1: core::panicking::panic_fmt
at
/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panicking.rs:74:14
2: core::result::unwrap_failed
at
/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/result.rs:1677:5
3: core::result::Result<T,E>::unwrap
at
/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/result.rs:1102:23
4: dbnexus_db::sqlparser_completion::tests::test_sql_statement
at ./src/sqlparser_completion.rs:954:25
5:
dbnexus_db::sqlparser_completion::tests::test_sql_statement::{{closure}}
at ./src/sqlparser_completion.rs:931:28
6: core::ops::function::FnOnce::call_once
at
/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
7: core::ops::function::FnOnce::call_once
at
/rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose
backtrace.
test sqlparser_completion::tests::test_sql_statement ... FAILED
successes:
successes:
failures:
failures:
sqlparser_completion::tests::test_sql_statement
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 129 filtered
out; finished in 0.16s
error: test failed, to rerun pass `-p dbnexus-db --lib`
~~~
Is this because of postgres syntax is not fully supported?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]