Added support for parsing nested object in query for Snowflake#2359
Open
kfirSatori wants to merge 2 commits into
Open
Added support for parsing nested object in query for Snowflake#2359kfirSatori wants to merge 2 commits into
kfirSatori wants to merge 2 commits into
Conversation
Author
|
@iffyio Can you please help resolve the PR? |
iffyio
reviewed
Jul 16, 2026
| let fields = self.parse_union_type_def()?; | ||
| Ok(DataType::Union(fields)) | ||
| } | ||
| Keyword::OBJECT if dialect_is!(dialect is SnowflakeDialect | GenericDialect) => { |
Contributor
There was a problem hiding this comment.
can we change this to use a dialect method?
Comment on lines
+13041
to
+13060
| 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)?; |
Contributor
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(); |
Contributor
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>), |
Contributor
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.