fmguerreiro commented on code in PR #2317:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2317#discussion_r4104409327


##########
src/ast/spans.rs:
##########
@@ -3163,4 +3164,19 @@ WHERE id = 1
             Span::new(Location::new(2, 8), Location::new(4, 52))
         );
     }
+
+    #[test]
+    fn test_create_foreign_data_wrapper_span_includes_option_keys() {
+        let dialect = &crate::dialect::PostgreSqlDialect {};
+        let sql = "CREATE FOREIGN DATA WRAPPER myfdw HANDLER myhandler OPTIONS 
(debug 'true')";
+        let mut test = SpanTest::new(dialect, sql);
+
+        // Ends at the option key, not the statement: a quoted option value is 
an
+        // Ident with an empty span, so it contributes nothing to the union.
+        let stmt = test.0.parse_statement().unwrap();
+        assert_eq!(
+            test.get_source(stmt.span()),
+            "myfdw HANDLER myhandler OPTIONS (debug"
+        );
+    }

Review Comment:
   dropped in 59608c62.



##########
tests/sqlparser_postgres.rs:
##########
@@ -9652,6 +9652,105 @@ fn parse_lock_table() {
     }
 }
 
+#[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(),
+            },
+        }])
+    );
+
+    // A single hardcoded Display label would render this as `NO HANDLER NO 
HANDLER`.
+    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(_))
+    ));
+}
+
+#[test]
+fn parse_create_foreign_data_wrapper_clause_order() {
+    // PostgreSQL takes these in either order; Display normalizes to HANDLER 
first.
+    let canonical = "CREATE FOREIGN DATA WRAPPER myfdw HANDLER myhandler 
VALIDATOR myvalidator";
+    pg_and_generic().one_statement_parses_to(
+        "CREATE FOREIGN DATA WRAPPER myfdw VALIDATOR myvalidator HANDLER 
myhandler",
+        canonical,
+    );
+    pg_and_generic().one_statement_parses_to(
+        "CREATE FOREIGN DATA WRAPPER myfdw NO VALIDATOR NO HANDLER",
+        "CREATE FOREIGN DATA WRAPPER myfdw NO HANDLER NO VALIDATOR",
+    );
+
+    // Pinning the message keeps this from passing on the old positional 
parser,
+    // which also errored here but on the trailing tokens instead.

Review Comment:
   removed in 59608c62.



##########
tests/sqlparser_postgres.rs:
##########
@@ -9652,6 +9652,105 @@ fn parse_lock_table() {
     }
 }
 
+#[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(),
+            },
+        }])
+    );
+
+    // A single hardcoded Display label would render this as `NO HANDLER NO 
HANDLER`.

Review Comment:
   removed in 59608c62.



-- 
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]

Reply via email to