Added support for parsing nested object in query for Snowflake - #2359
Added support for parsing nested object in query for Snowflake#2359kfirSatori wants to merge 6 commits into
Conversation
|
@iffyio Can you please help resolve the PR? |
| let fields = self.parse_union_type_def()?; | ||
| Ok(DataType::Union(fields)) | ||
| } | ||
| Keyword::OBJECT if dialect_is!(dialect is SnowflakeDialect | GenericDialect) => { |
There was a problem hiding this comment.
can we change this to use a dialect method?
There was a problem hiding this comment.
Hi @iffyio, i dont understand what do you mean.
i did it the same way done as UNION and NULLABLE
| 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)?; |
There was a problem hiding this comment.
can we move this to its own parse_object_data_type() or similar helper method?
| field VARCHAR | ||
| )));"#; | ||
|
|
||
| snowflake().parse_sql_statements(sql).unwrap(); |
There was a problem hiding this comment.
can we use verified_stmt? also if we can include test cases for mulltiple struct fields, zero struct fields, OBJECT() and OBJECT
| /// Object type, see [Snowflake]. | ||
| /// | ||
| /// [Snowflake]: https://docs.snowflake.com/en/sql-reference/data-types-semistructured#object | ||
| Object(Vec<StructField>), |
There was a problem hiding this 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)
Queries parsing like:
SELECT TRY_CAST(PARSE_JSON('{"obj_field":{"field":"value",}}') AS OBJECT(obj_field OBJECT( field VARCHAR)));in Snowflake are failing since nested object are not supported.
I have added support for it.