LucaCappelletti94 commented on code in PR #2515:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2515#discussion_r4103828378
##########
src/ast/spans.rs:
##########
@@ -3167,6 +3168,20 @@ WHERE id = 1
);
}
+ #[test]
+ fn test_create_foreign_table_span_includes_quoted_option_value() {
+ let dialect = &crate::dialect::PostgreSqlDialect {};
+ let sql = "CREATE FOREIGN TABLE ft (a INT) SERVER s OPTIONS
(schema_name 'public')";
+ let mut test = SpanTest::new(dialect, sql);
+
+ // Span reaches through the quoted value but not the closing paren.
+ let stmt = test.0.parse_statement().unwrap();
+ assert_eq!(
+ test.get_source(stmt.span()),
+ "ft (a INT) SERVER s OPTIONS (schema_name 'public'"
+ );
+ }
Review Comment:
You should assert the option spans directly instead of the statement span.
The statement span still leaves out `CREATE FOREIGN TABLE` and the closing `)`,
so this test pins known-wrong behaviour again. The version below fails if
`parse_identifier` drops the span of a quoted identifier.
```suggestion
#[test]
fn test_create_foreign_table_option_spans() {
let dialect = &crate::dialect::PostgreSqlDialect {};
let sql = r#"CREATE FOREIGN TABLE ft (a INT) SERVER s OPTIONS
("schema_name" 'public')"#;
let mut test = SpanTest::new(dialect, sql);
let options = match test.0.parse_statement().unwrap() {
Statement::CreateForeignTable(stmt) => stmt.options.unwrap(),
stmt => panic!("expected CREATE FOREIGN TABLE, got {stmt:?}"),
};
assert_eq!(test.get_source(options[0].key.span), r#""schema_name""#);
assert_eq!(test.get_source(options[0].value.span), "'public'");
}
```
--
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]