Snowflake: Fix COPY INTO transformation parsing for cast expressions#2328
Open
97nitt wants to merge 3 commits intoapache:mainfrom
Open
Snowflake: Fix COPY INTO transformation parsing for cast expressions#232897nitt wants to merge 3 commits intoapache:mainfrom
97nitt wants to merge 3 commits intoapache:mainfrom
Conversation
…NTO transformation
iffyio
reviewed
Apr 29, 2026
Comment on lines
+2452
to
+2461
| // 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.
Suggested change
| // 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`. |
Comment on lines
+1549
to
+1551
| // `$1:"col"::NUMBER(38,0)`), not a stage-load-select-item. Bail so | ||
| // `maybe_parse` rewinds and the caller falls through to | ||
| // `parse_select_item`, which handles the cast correctly. |
Contributor
There was a problem hiding this comment.
Suggested change
| // `$1:"col"::NUMBER(38,0)`), not a stage-load-select-item. Bail so | |
| // `maybe_parse` rewinds and the caller falls through to | |
| // `parse_select_item`, which handles the cast correctly. | |
| // `$1:"col"::NUMBER(38,0)`), not a stage-load-select-item. |
Comment on lines
+2479
to
+2480
| // 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.
Suggested change
| // Mix with an ordinary stage-load-select-item in the same list, | |
| // so we don't over-correct and break the existing shape. |
iffyio
reviewed
Apr 29, 2026
| ), | ||
| ]; | ||
| for sql in variants { | ||
| snowflake().parse_sql_statements(sql).unwrap_or_else(|e| { |
Contributor
There was a problem hiding this comment.
these should use verified_stmt?
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.
Summary
Snowflake
COPY INTO ... FROM (SELECT ...)transformation lists support castexpressions like
$1:"col"::TYPEand$1::TYPE, e.g.:Today the Snowflake-specific stage-load-select-item parser successfully
consumes
$1:"A"as a stage-load-select-item, leaves::NUMBER(38, 0)inthe token stream, and the surrounding
COPY INTObody then fails withExpected: FROM, found: ::.Changes
parse_select_item_for_data_load: bail (somaybe_parserewinds and thecaller falls through to the generic
parse_select_item) when the nexttoken is
::. The generic path already handles cast operators on$<n>references correctly.
$1:"col"::TYPE,$1::TYPE,$1:SEQUENCE::TYPE, multi-column lists, and a mixed list combining aplain stage-load-select-item with a cast item — verifying we don't
over-correct and break the existing shape.
Test plan
cargo testcargo fmt --checkcargo clippy --all-targets --all-features -- -D warnings