Repository navigation
Snowflake: Parse structured OBJECT types #2489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e011296
1146c42
3877539
fd46552
0b8892f
c1256da
4c48bdb
2a788d0
67c962b
c0790dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4954,6 +4954,77 @@ fn test_structured_array_type() { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_structured_object_type() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're missing a test case for how the PR handles plain
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an explicit |
||
| snowflake_and_generic().verified_stmt( | ||
| "SELECT payload::OBJECT(address OBJECT(city VARCHAR NOT NULL), zip NUMBER) FROM t", | ||
| ); | ||
| snowflake().one_statement_parses_to( | ||
| "SELECT payload::OBJECT(tags ARRAY, labels MAP(VARCHAR, VARCHAR)) FROM t", | ||
| "SELECT payload::OBJECT(tags ARRAY, labels Map(VARCHAR, VARCHAR)) FROM t", | ||
| ); | ||
| let select = snowflake().verified_only_select( | ||
| "SELECT payload::OBJECT(items ARRAY(NUMBER NOT NULL), meta MAP(VARCHAR, OBJECT(k NUMBER) NOT NULL)) FROM t", | ||
| ); | ||
| let Expr::Cast { data_type, .. } = expr_from_projection(only(&select.projection)) else { | ||
| unreachable!(); | ||
| }; | ||
| let DataType::Object(fields) = data_type else { | ||
| unreachable!(); | ||
| }; | ||
| assert!(matches!( | ||
| &fields[0].data_type, | ||
| DataType::Array(ArrayElemTypeDef::ParenthesisNotNull(_)) | ||
| )); | ||
| let DataType::Map(_, value, MapBracketKind::ParenthesesNotNull) = &fields[1].data_type else { | ||
| unreachable!(); | ||
| }; | ||
| assert!(matches!(**value, DataType::Object(_))); | ||
|
|
||
| snowflake().one_statement_parses_to( | ||
| "SELECT payload::ARRAY(NUMBER) FROM t", | ||
| "SELECT payload::Array(NUMBER) FROM t", | ||
| ); | ||
| snowflake().one_statement_parses_to( | ||
| "SELECT payload::MAP(VARCHAR, OBJECT(k NUMBER)) FROM t", | ||
| "SELECT payload::Map(VARCHAR, OBJECT(k NUMBER)) FROM t", | ||
| ); | ||
| snowflake().verified_stmt("SELECT payload::ARRAY(NUMBER NOT NULL) FROM t"); | ||
| snowflake().verified_stmt("SELECT payload::MAP(VARCHAR, NUMBER NOT NULL) FROM t"); | ||
| snowflake_and_generic().verified_stmt("CREATE TABLE t (o OBJECT())"); | ||
|
|
||
| let select = snowflake().verified_only_select( | ||
| "SELECT CAST(payload AS OBJECT(city VARCHAR, zip NUMBER NOT NULL)) FROM t", | ||
| ); | ||
| let Expr::Cast { data_type, .. } = expr_from_projection(only(&select.projection)) else { | ||
| unreachable!(); | ||
| }; | ||
| let DataType::Object(fields) = data_type else { | ||
| unreachable!(); | ||
| }; | ||
| assert_eq!(fields.len(), 2); | ||
| assert_eq!(fields[0].name, Ident::new("city")); | ||
| assert!(fields[0].options.is_empty()); | ||
| assert_eq!(fields[1].name, Ident::new("zip")); | ||
| assert_eq!(fields[1].options.len(), 1); | ||
| assert_eq!(fields[1].options[0].option, ColumnOption::NotNull); | ||
|
|
||
| assert!(snowflake() | ||
| .parse_sql_statements("CREATE TABLE t (o OBJECT(city VARCHAR)") | ||
| .is_err()); | ||
|
|
||
| let Statement::CreateTable(CreateTable { columns, .. }) = | ||
| snowflake_and_generic().verified_stmt("CREATE TABLE t (o OBJECT)") | ||
| else { | ||
| unreachable!(); | ||
| }; | ||
|
|
||
| assert_eq!( | ||
| columns[0].data_type, | ||
| DataType::Custom(ObjectName::from(vec![Ident::new("OBJECT")]), vec![]) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_snowflake_stage_name_with_escaped_quotes() { | ||
| snowflake().verified_stmt("REMOVE @````"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the missing blank line before the test in 0d58c18.