-
Notifications
You must be signed in to change notification settings - Fork 713
Snowflake: Fix COPY INTO transformation parsing for cast expressions #2328
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2447,6 +2447,49 @@ fn test_copy_into_with_transformations() { | |||||||||||||||||||||
| snowflake().parse_sql_statements(sql1).unwrap(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||
| fn test_copy_into_with_cast_transformation() { | ||||||||||||||||||||||
| // Snowflake `COPY INTO` transformation lists support casts like | ||||||||||||||||||||||
| // `$1:"col"::TYPE` and `$1::TYPE`. These are distinct from the bare | ||||||||||||||||||||||
| // `$<n>[.<col>][:<elem>]` stage-load-select-item shape, so the parser | ||||||||||||||||||||||
| // must fall through to the generic select-item parser to handle the | ||||||||||||||||||||||
| // `::` cast operator. | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // Regression: the Snowflake-specific parser used to successfully | ||||||||||||||||||||||
| // consume `$1:"col"` as a stage-load-select-item, leaving `::TYPE` | ||||||||||||||||||||||
| // behind and causing "Expected: FROM, found: ::" once the COPY INTO | ||||||||||||||||||||||
| // body tried to expect `FROM`. | ||||||||||||||||||||||
|
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.
Suggested change
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. Done. |
||||||||||||||||||||||
| let variants = [ | ||||||||||||||||||||||
| concat!( | ||||||||||||||||||||||
| "COPY INTO my_company.emp_basic (a) FROM ", | ||||||||||||||||||||||
| r#"(SELECT $1:"A"::NUMBER(38, 0) FROM @stg)"#, | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| concat!( | ||||||||||||||||||||||
| "COPY INTO my_company.emp_basic (a) FROM ", | ||||||||||||||||||||||
| "(SELECT $1::NUMBER(38, 0) FROM @stg)", | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| concat!( | ||||||||||||||||||||||
| "COPY INTO my_company.emp_basic (a) FROM ", | ||||||||||||||||||||||
| "(SELECT $1:SEQUENCE::NUMBER(38, 0) FROM @stg)", | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| concat!( | ||||||||||||||||||||||
| "COPY INTO my_company.emp_basic (a, b) FROM ", | ||||||||||||||||||||||
| r#"(SELECT $1:"A"::VARIANT, $1:"B"::TEXT FROM @stg)"#, | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| // Mix with an ordinary stage-load-select-item in the same list, | ||||||||||||||||||||||
| // so we don't over-correct and break the existing shape. | ||||||||||||||||||||||
|
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.
Suggested change
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. Done. |
||||||||||||||||||||||
| concat!( | ||||||||||||||||||||||
| "COPY INTO my_company.emp_basic (a, b) FROM ", | ||||||||||||||||||||||
| r#"(SELECT t.$1:plain AS plain, $1:"B"::TEXT FROM @stg AS t)"#, | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| ]; | ||||||||||||||||||||||
| for sql in variants { | ||||||||||||||||||||||
| snowflake().parse_sql_statements(sql).unwrap_or_else(|e| { | ||||||||||||||||||||||
|
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. these should use verified_stmt?
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. Done. |
||||||||||||||||||||||
| panic!("expected {sql:?} to parse, got {e}"); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||
| fn test_copy_into_file_format() { | ||||||||||||||||||||||
| let sql = concat!( | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
Done.