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


##########
src/ast/data_type.rs:
##########
@@ -465,6 +465,10 @@ pub enum DataType {
     ///
     /// [DuckDB]: https://duckdb.org/docs/sql/data_types/union.html
     Union(Vec<UnionField>),
+    /// Object type, see [Snowflake].
+    ///
+    /// [Snowflake]: 
https://docs.snowflake.com/en/sql-reference/data-types-semistructured#object
+    Object(Vec<StructField>),

Review Comment:
   Can we turn this into a `Object { xxx: Option<Vec<StructField>> }`? the 
named field syntax makes it possible to extend later on (like attaching spans) 
and the option iiuc is needed if we're to properly support `OBJECT` syntax 
(unclear since the behavior suggests it but the tests don't cover it)



##########
src/parser/mod.rs:
##########
@@ -13036,6 +13036,31 @@ impl<'a> Parser<'a> {
                     let fields = self.parse_union_type_def()?;
                     Ok(DataType::Union(fields))
                 }
+                Keyword::OBJECT if dialect_is!(dialect is SnowflakeDialect | 
GenericDialect) => {

Review Comment:
   can we change this to use a dialect method?



##########
tests/sqlparser_snowflake.rs:
##########
@@ -4914,3 +4914,12 @@ fn test_select_dollar_column_from_stage() {
     // With table function args, without alias
     snowflake().verified_stmt("SELECT $1, $2 FROM @mystage1(file_format => 
'myformat')");
 }
+
+#[test]
+fn parse_nested_object() {
+    let sql = r#"SELECT 
TRY_CAST(PARSE_JSON('{"obj_field":{"field":"value",}}') AS OBJECT(obj_field 
OBJECT(
+        field VARCHAR
+)));"#;
+
+    snowflake().parse_sql_statements(sql).unwrap();

Review Comment:
   can we use verified_stmt? also if we can include test cases for mulltiple 
struct fields, zero struct fields, `OBJECT()` and `OBJECT`



##########
src/parser/mod.rs:
##########
@@ -13036,6 +13036,31 @@ impl<'a> Parser<'a> {
                     let fields = self.parse_union_type_def()?;
                     Ok(DataType::Union(fields))
                 }
+                Keyword::OBJECT if dialect_is!(dialect is SnowflakeDialect | 
GenericDialect) => {
+                    self.prev_token();
+                    self.expect_keyword_is(Keyword::OBJECT)?;
+                    // Object type may have no fields: OBJECT or OBJECT()
+                    if !self.peek_token_ref().token.eq(&Token::LParen) {
+                        Ok(DataType::Object(vec![]))
+                    } else {
+                        self.expect_token(&Token::LParen)?;
+                        let fields = if self.peek_token_ref().token == 
Token::RParen {
+                            vec![]
+                        } else {
+                            self.parse_comma_separated(|parser| {
+                                let field_name = parser.parse_identifier()?;
+                                let field_type = parser.parse_data_type()?;
+                                Ok(StructField {
+                                    field_name: Some(field_name),
+                                    field_type,
+                                    options: None,
+                                })
+                            })?
+                        };
+                        self.expect_token(&Token::RParen)?;

Review Comment:
   can we move this to its own parse_object_data_type() or similar helper 
method?



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