LucaCappelletti94 commented on code in PR #2594:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2594#discussion_r4252384326


##########
src/parser/mod.rs:
##########


Review Comment:
   You should keep every name part as its own `Ident` instead of joining the 
qualifiers into one. As written, `main.raw.source` and `` `main.raw`.source `` 
both give a `schema_name` whose `value` is `"main.raw"`, and `` `a 
b`.raw.source `` gives the `value` `` "`a b`.raw" `` with the backticks inside 
it, so consumers cannot recover the parts. This relies on the `Table` change in 
the global note.
   
   ```suggestion
           let max_parts = if 
self.dialect.supports_multipart_table_query_name() {
               usize::MAX
           } else {
               2
           };
           let mut parts = vec![self.parse_identifier()?];
           while parts.len() < max_parts && self.consume_token(&Token::Period) {
               parts.push(self.parse_identifier()?);
           }
           Ok(Table {
               name: Some(ObjectName::from(parts)),
           })
   ```



##########
tests/sqlparser_databricks.rs:
##########
@@ -769,3 +769,8 @@ fn parse_databricks_collated_data_types() {
         .parse_sql_statements("CREATE TABLE t (c ARRAY<STRING COLLATE 
UTF8_LCASE>)")
         .is_err());
 }
+
+#[test]
+fn parse_databricks_multipart_table_query() {
+    databricks().verified_stmt("CREATE VIEW copy AS TABLE main.raw.source");

Review Comment:
   You should assert the parsed parts, because `verified_stmt` only checks the 
round trip and the joined `Ident` passes it.
   
   ```suggestion
       let Statement::CreateView(view) =
           databricks().verified_stmt("CREATE VIEW copy AS TABLE 
main.raw.source")
       else {
           unreachable!()
       };
       assert_eq!(
           *view.query.body,
           SetExpr::Table(Box::new(Table {
               name: Some(ObjectName::from(vec![
                   Ident::new("main"),
                   Ident::new("raw"),
                   Ident::new("source"),
               ])),
           }))
       );
   ```



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