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


##########
tests/sqlparser_databricks.rs:
##########
@@ -757,3 +757,10 @@ fn parse_databricks_query_entry_points() {
     databricks()
         .verified_stmt("CREATE VIEW filtered AS FROM main.raw.source |> WHERE 
id > 0 |> SELECT id");
 }
+
+#[test]
+fn parse_databricks_collated_data_types() {
+    databricks().verified_stmt(
+        "CREATE TABLE t (name STRING COLLATE UTF8_BINARY, values ARRAY<STRING 
COLLATE UTF8_LCASE>, attrs MAP<STRING COLLATE UTF8_BINARY, STRING COLLATE 
UTF8_LCASE>)",
+    );

Review Comment:
   Adding a red test relative to the other note.
   
   ```suggestion
       );
       databricks().verified_stmt("CREATE TABLE t (s STRUCT<a STRING COLLATE 
UTF8_LCASE>)");
       databricks().verified_stmt("CREATE TABLE t (c ARRAY<ARRAY<STRING>> 
COLLATE UTF8_LCASE)");
       assert!(TestedDialects::new(vec![Box::new(GenericDialect {})])
           .parse_sql_statements("CREATE TABLE t (c ARRAY<STRING COLLATE 
UTF8_LCASE>)")
           .is_err());
   ```



##########
src/parser/mod.rs:
##########
@@ -13266,6 +13275,16 @@ impl<'a> Parser<'a> {
         Ok((data, trailing_bracket))
     }
 
+    fn parse_data_type_with_optional_collation(
+        &mut self,
+    ) -> Result<(DataType, MatchedTrailingBracket), ParserError> {
+        let (mut data_type, trailing_bracket) = self.parse_data_type_helper()?;
+        if self.dialect.supports_data_type_collation() && 
self.parse_keyword(Keyword::COLLATE) {

Review Comment:
   You should skip `COLLATE` when the inner type closed with `>>`, because that 
`>>` also closed the parent and the keyword belongs to an outer level. 
Databricks currently turns `c ARRAY<ARRAY<STRING>> COLLATE UTF8_LCASE` into `c 
ARRAY<ARRAY<STRING> COLLATE UTF8_LCASE>`, moving the column collation inside 
the array.
   
   ```suggestion
           if !trailing_bracket.0
               && self.dialect.supports_data_type_collation()
               && self.parse_keyword(Keyword::COLLATE)
           {
   ```



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