-
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -1273,6 +1273,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), | ||
|
|
@@ -1898,6 +1903,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. | ||
| _ => match self.parse_subexpr(self.dialect.prec_value(Precedence::Period))? { | ||
| // If we get back a compound field access or identifier, | ||
|
|
@@ -15103,6 +15115,11 @@ impl<'a> Parser<'a> { | |
| && self.peek_keyword_with_tokens(Keyword::SEMANTIC_VIEW, &[Token::LParen]) | ||
| { | ||
| self.parse_semantic_view_table_factor() | ||
| } else if dialect_of!(self is SnowflakeDialect) | ||
| && self.peek_token_ref().token == Token::AtSign | ||
| { | ||
| // Snowflake stage reference: @mystage or @namespace.stage | ||
| self.parse_snowflake_stage_table_factor() | ||
| } else { | ||
| let name = self.parse_object_name(true)?; | ||
|
|
||
|
|
@@ -15199,6 +15216,35 @@ impl<'a> Parser<'a> { | |
| } | ||
| } | ||
|
|
||
| /// Parse a Snowflake stage reference as a table factor. | ||
| /// Handles syntax like: `@mystage1 (file_format => 'myformat', pattern => '...')` | ||
|
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 link to the documentation that supports this syntax? |
||
| 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 | ||
|
|
||
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.
If we need a guard for this I think we would instead use a method on the dialect trait (we're moving away from the dialect_of macro for new code). But I think the guard shouldn't be needed in the first place? so that if we see a
SELECT * FROM @foo Twe can always accept it regardless of dialect?