|
19 | 19 | use crate::alloc::string::ToString; |
20 | 20 | use crate::ast::helpers::stmt_create_table::CreateTableBuilder; |
21 | 21 | use crate::ast::helpers::stmt_data_loading::{ |
22 | | - DataLoadingOption, DataLoadingOptionType, DataLoadingOptions, StageLoadSelectItem, |
23 | | - StageParamsObject, |
| 22 | + DataLoadingOption, DataLoadingOptionType, DataLoadingOptions, FileStagingCommand, |
| 23 | + StageLoadSelectItem, StageParamsObject, |
24 | 24 | }; |
25 | 25 | use crate::ast::{ |
26 | 26 | ColumnOption, ColumnPolicy, ColumnPolicyProperty, Ident, IdentityParameters, IdentityProperty, |
@@ -165,6 +165,15 @@ impl Dialect for SnowflakeDialect { |
165 | 165 | return Some(parse_copy_into(parser)); |
166 | 166 | } |
167 | 167 |
|
| 168 | + if let Some(kw) = parser.parse_one_of_keywords(&[ |
| 169 | + Keyword::LIST, |
| 170 | + Keyword::LS, |
| 171 | + Keyword::REMOVE, |
| 172 | + Keyword::RM, |
| 173 | + ]) { |
| 174 | + return Some(parse_file_staging_command(kw, parser)); |
| 175 | + } |
| 176 | + |
168 | 177 | None |
169 | 178 | } |
170 | 179 |
|
@@ -240,6 +249,26 @@ impl Dialect for SnowflakeDialect { |
240 | 249 | } |
241 | 250 | } |
242 | 251 |
|
| 252 | +fn parse_file_staging_command(kw: Keyword, parser: &mut Parser) -> Result<Statement, ParserError> { |
| 253 | + let stage = parse_snowflake_stage_name(parser)?; |
| 254 | + let pattern = if parser.parse_keyword(Keyword::PATTERN) { |
| 255 | + parser.expect_token(&Token::Eq)?; |
| 256 | + Some(parser.parse_literal_string()?) |
| 257 | + } else { |
| 258 | + None |
| 259 | + }; |
| 260 | + |
| 261 | + match kw { |
| 262 | + Keyword::LIST | Keyword::LS => Ok(Statement::List(FileStagingCommand { stage, pattern })), |
| 263 | + Keyword::REMOVE | Keyword::RM => { |
| 264 | + Ok(Statement::Remove(FileStagingCommand { stage, pattern })) |
| 265 | + } |
| 266 | + _ => Err(ParserError::ParserError( |
| 267 | + "unexpected stage command, expecting LIST, LS, REMOVE or RM".to_string(), |
| 268 | + )), |
| 269 | + } |
| 270 | +} |
| 271 | + |
243 | 272 | /// Parse snowflake create table statement. |
244 | 273 | /// <https://docs.snowflake.com/en/sql-reference/sql/create-table> |
245 | 274 | pub fn parse_create_table( |
@@ -501,7 +530,7 @@ pub fn parse_stage_name_identifier(parser: &mut Parser) -> Result<Ident, ParserE |
501 | 530 | Token::Tilde => ident.push('~'), |
502 | 531 | Token::Mod => ident.push('%'), |
503 | 532 | Token::Div => ident.push('/'), |
504 | | - Token::Word(w) => ident.push_str(&w.value), |
| 533 | + Token::Word(w) => ident.push_str(&w.to_string()), |
505 | 534 | _ => return parser.expected("stage name identifier", parser.peek_token()), |
506 | 535 | } |
507 | 536 | } |
|
0 commit comments