fmguerreiro commented on code in PR #2317:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2317#discussion_r4114434544
##########
src/parser/mod.rs:
##########
@@ -5400,6 +5400,8 @@ impl<'a> Parser<'a> {
);
}
self.parse_create_foreign_table().map(Into::into)
+ } else if self.parse_keywords(&[Keyword::FOREIGN, Keyword::DATA,
Keyword::WRAPPER]) {
+ self.parse_create_foreign_data_wrapper().map(Into::into)
Review Comment:
fixed in ee0ded70.
##########
src/parser/mod.rs:
##########
Review Comment:
done in ee0ded70, both foreign arms share it now.
##########
src/parser/mod.rs:
##########
@@ -5400,6 +5400,8 @@ impl<'a> Parser<'a> {
);
}
Review Comment:
fixed in ee0ded70.
##########
tests/sqlparser_postgres.rs:
##########
@@ -10138,3 +10138,99 @@ fn parse_bitstring_literal_escaping() {
pg_and_generic().verified_stmt("SELECT B''''");
pg_and_generic().verified_stmt("SELECT B'it''s'");
}
+
+#[test]
+fn parse_create_foreign_data_wrapper() {
+ let sql = "CREATE FOREIGN DATA WRAPPER myfdw";
+ let Statement::CreateForeignDataWrapper(stmt) =
pg_and_generic().verified_stmt(sql) else {
+ unreachable!()
+ };
+ assert_eq!(stmt.name.to_string(), "myfdw");
+ assert!(stmt.handler.is_none());
+ assert!(stmt.validator.is_none());
+ assert!(stmt.options.is_none());
+
+ let sql = "CREATE FOREIGN DATA WRAPPER myfdw HANDLER myhandler";
+ let Statement::CreateForeignDataWrapper(stmt) =
pg_and_generic().verified_stmt(sql) else {
+ unreachable!()
+ };
+ assert_eq!(
+ stmt.handler,
+ Some(ForeignDataWrapperRoutineClause::Function(ObjectName::from(
+ vec!["myhandler".into()]
+ )))
+ );
+
+ let sql = "CREATE FOREIGN DATA WRAPPER myfdw NO HANDLER";
+ let Statement::CreateForeignDataWrapper(stmt) =
pg_and_generic().verified_stmt(sql) else {
+ unreachable!()
+ };
+ assert_eq!(stmt.handler, Some(ForeignDataWrapperRoutineClause::Absent));
+
+ let sql = "CREATE FOREIGN DATA WRAPPER myfdw NO VALIDATOR";
+ let Statement::CreateForeignDataWrapper(stmt) =
pg_and_generic().verified_stmt(sql) else {
+ unreachable!()
+ };
+ assert_eq!(
+ stmt.validator,
+ Some(ForeignDataWrapperRoutineClause::Absent)
+ );
+
+ let sql = "CREATE FOREIGN DATA WRAPPER myfdw HANDLER myhandler VALIDATOR
myvalidator OPTIONS (debug 'true')";
+ let Statement::CreateForeignDataWrapper(stmt) =
pg_and_generic().verified_stmt(sql) else {
+ unreachable!()
+ };
+ assert_eq!(
+ stmt.options,
+ Some(vec![CreateServerOption {
+ key: "debug".into(),
+ value: Ident {
+ value: "true".to_string(),
+ quote_style: Some('\''),
+ span: Span::empty(),
+ },
+ }])
+ );
+
+ let sql = "CREATE FOREIGN DATA WRAPPER myfdw NO HANDLER NO VALIDATOR";
+ let Statement::CreateForeignDataWrapper(stmt) =
pg_and_generic().verified_stmt(sql) else {
+ unreachable!()
+ };
+ assert_eq!(stmt.handler, Some(ForeignDataWrapperRoutineClause::Absent));
+ assert_eq!(
+ stmt.validator,
+ Some(ForeignDataWrapperRoutineClause::Absent)
+ );
+
+ // A schema-qualified name is not valid: FDW names are bare identifiers.
+ assert!(matches!(
+ pg_and_generic().parse_sql_statements("CREATE FOREIGN DATA WRAPPER
myschema.myfdw"),
+ Err(ParserError::ParserError(_))
+ ));
Review Comment:
done in ee0ded70.
--
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]