-
Notifications
You must be signed in to change notification settings - Fork 691
Fixed select dollar column from stage for snowflake #2165
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
Merged
iffyio
merged 2 commits into
apache:main
from
romanoff:fix_select_dollar_column_from_stage
Feb 14, 2026
+62
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1284,6 +1284,11 @@ impl<'a> Parser<'a> { | |
| // SQLite has single-quoted identifiers | ||
| id_parts.push(Ident::with_quote('\'', s)) | ||
| } | ||
| Token::Placeholder(s) => { | ||
| // Snowflake uses $1, $2, etc. for positional column references | ||
| // in staged data queries like: SELECT t.$1 FROM @stage t | ||
| id_parts.push(Ident::new(s)) | ||
| } | ||
| Token::Mul => { | ||
| return Ok(Expr::QualifiedWildcard( | ||
| ObjectName::from(id_parts), | ||
|
|
@@ -1946,6 +1951,13 @@ impl<'a> Parser<'a> { | |
| chain.push(AccessExpr::Dot(expr)); | ||
| self.advance_token(); // The consumed string | ||
| } | ||
| Token::Placeholder(s) => { | ||
| // Snowflake uses $1, $2, etc. for positional column references | ||
| // in staged data queries like: SELECT t.$1 FROM @stage t | ||
| let expr = Expr::Identifier(Ident::with_span(next_token.span, s)); | ||
| chain.push(AccessExpr::Dot(expr)); | ||
| self.advance_token(); // The consumed placeholder | ||
| } | ||
| // Fallback to parsing an arbitrary expression, but restrict to expression | ||
| // types that are valid after the dot operator. This ensures that e.g. | ||
| // `T.interval` is parsed as a compound identifier, not as an interval | ||
|
|
@@ -15435,6 +15447,9 @@ impl<'a> Parser<'a> { | |
| && self.peek_keyword_with_tokens(Keyword::SEMANTIC_VIEW, &[Token::LParen]) | ||
| { | ||
| self.parse_semantic_view_table_factor() | ||
| } else if self.peek_token_ref().token == Token::AtSign { | ||
| // Stage reference: @mystage or @namespace.stage (e.g. Snowflake) | ||
| self.parse_snowflake_stage_table_factor() | ||
| } else { | ||
| let name = self.parse_object_name(true)?; | ||
|
|
||
|
|
@@ -15531,6 +15546,37 @@ impl<'a> Parser<'a> { | |
| } | ||
| } | ||
|
|
||
| /// Parse a Snowflake stage reference as a table factor. | ||
| /// Handles syntax like: `@mystage1 (file_format => 'myformat', pattern => '...')` | ||
| /// | ||
| /// See: <https://docs.snowflake.com/en/user-guide/querying-stage> | ||
| fn parse_snowflake_stage_table_factor(&mut self) -> Result<TableFactor, ParserError> { | ||
| // Parse the stage name starting with @ | ||
| let name = crate::dialect::parse_snowflake_stage_name(self)?; | ||
|
|
||
| // Parse optional stage options like (file_format => 'myformat', pattern => '...') | ||
| let args = if self.consume_token(&Token::LParen) { | ||
| Some(self.parse_table_function_args()?) | ||
| } else { | ||
| None | ||
|
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. can we add a test case that doesn't include table function args? |
||
| }; | ||
|
|
||
| let alias = self.maybe_parse_table_alias()?; | ||
|
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. can we add a test case that doesn't include an alias? |
||
|
|
||
| Ok(TableFactor::Table { | ||
| name, | ||
| alias, | ||
| args, | ||
| with_hints: vec![], | ||
| version: None, | ||
| partitions: vec![], | ||
| with_ordinality: false, | ||
| json_path: None, | ||
| sample: None, | ||
| index_hints: vec![], | ||
| }) | ||
| } | ||
|
|
||
| fn maybe_parse_table_sample(&mut self) -> Result<Option<Box<TableSample>>, ParserError> { | ||
| let modifier = if self.parse_keyword(Keyword::TABLESAMPLE) { | ||
| TableSampleModifier::TableSample | ||
|
|
||
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
Oops, something went wrong.
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.
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.
Can we link to the documentation that supports this syntax?