iffyio commented on code in PR #1542:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1542#discussion_r1855088307


##########
src/parser/mod.rs:
##########
@@ -2328,19 +2327,25 @@ impl<'a> Parser<'a> {
         }
     }
 
-    /// Bigquery specific: Parse a struct literal
     /// Syntax
     /// ```sql
-    /// -- typed
+    /// -- typed, specific to bigquery
     /// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
     /// -- typeless
     /// STRUCT( expr1 [AS field_name] [, ... ])
     /// ```
-    fn parse_bigquery_struct_literal(&mut self) -> Result<Expr, ParserError> {
-        let (fields, trailing_bracket) =
-            self.parse_struct_type_def(Self::parse_struct_field_def)?;
-        if trailing_bracket.0 {
-            return parser_err!("unmatched > in STRUCT literal", 
self.peek_token().location);
+    fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
+        let mut fields = vec![];
+        // Typed struct syntax is only supported by BigQuery
+        // 
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax

Review Comment:
   ```suggestion
   ```



##########
src/parser/mod.rs:
##########
@@ -2328,19 +2327,25 @@ impl<'a> Parser<'a> {
         }
     }
 
-    /// Bigquery specific: Parse a struct literal
     /// Syntax
     /// ```sql
-    /// -- typed
+    /// -- typed, specific to bigquery

Review Comment:
   ```suggestion
       /// -- typed
   ```
   for the comments mentioning bigquery specific I think we can skip since the 
definition is now encoded in the dialect method. Otherwise it'll be easier to 
go out of sync if other dialects support it



##########
src/ast/mod.rs:
##########
@@ -853,16 +853,16 @@ pub enum Expr {
     Rollup(Vec<Vec<Expr>>),
     /// ROW / TUPLE a single value, such as `SELECT (1, 2)`
     Tuple(Vec<Expr>),
-    /// `BigQuery` specific `Struct` literal expression [1]
+    /// `Struct` literal expression
     /// Syntax:
     /// ```sql
     /// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
     /// ```
-    /// [1]: 
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type
     Struct {
         /// Struct values.
         values: Vec<Expr>,
-        /// Struct field definitions.
+        /// BigQuery specific: Struct field definitions.
+        /// see 
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type

Review Comment:
   I think the link can continue to live on the struct definition instead, we 
can change it to?
   ```
   
[BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type)
   ```



##########
tests/sqlparser_databricks.rs:
##########
@@ -277,3 +277,48 @@ fn parse_use() {
         );
     }
 }
+
+#[test]
+fn parse_databricks_struct_function() {
+    assert_eq!(
+        databricks()

Review Comment:
   ```suggestion
           databricks_and_generic()
   ```
   thinking since generic accepts the same syntax? (same for the others)



##########
src/parser/mod.rs:
##########
@@ -2328,19 +2327,25 @@ impl<'a> Parser<'a> {
         }
     }
 
-    /// Bigquery specific: Parse a struct literal
     /// Syntax
     /// ```sql
-    /// -- typed
+    /// -- typed, specific to bigquery
     /// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
     /// -- typeless
     /// STRUCT( expr1 [AS field_name] [, ... ])
     /// ```
-    fn parse_bigquery_struct_literal(&mut self) -> Result<Expr, ParserError> {
-        let (fields, trailing_bracket) =
-            self.parse_struct_type_def(Self::parse_struct_field_def)?;
-        if trailing_bracket.0 {
-            return parser_err!("unmatched > in STRUCT literal", 
self.peek_token().location);
+    fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
+        let mut fields = vec![];
+        // Typed struct syntax is only supported by BigQuery
+        // 
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax
+        if self.dialect.supports_typed_struct_syntax() {

Review Comment:
   Oh actually I'm not sure i follow the changes entirely, it seems Bigquery 
struct syntax is a superset of databricks struct? If so I'm thinking we ideally 
wouldnt need the extra `self.dialect.supports_typed_struct_syntax()` method, 
only guarding on `supports_struct_literal` should be enough?
   
   It would technically mean that the typed syntax gets accepted by the 
databricks dialect but thats fine for the parser behavior



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to