Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,18 @@ fn parse_select_item_for_data_load(
}
}

// A simple staged field has a dedicated compact AST node. More complex
// paths and casts must fall back to the standard expression parser so it
// can preserve the complete `JsonAccess` / `Cast` expression instead of
// leaving trailing tokens for the enclosing COPY parser.
if matches!(
parser.peek_token_ref().token,
Token::Colon | Token::Period | Token::LBracket | Token::DoubleColon
) {
let token = parser.next_token();
return parser.expected("end of simple staged field", token);
}

// as
if parser.parse_keyword(Keyword::AS) {
item_as = Some(match parser.next_token().token {
Expand Down
23 changes: 23 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2668,6 +2668,29 @@ fn test_copy_into_with_transformations() {
snowflake().parse_sql_statements(sql1).unwrap();
}

#[test]
fn test_copy_into_with_nested_transformation_path() {
let sql = concat!(
"COPY INTO cities FROM ",
"(SELECT $1:continent::VARCHAR, $1:country:name::VARCHAR ",
"FROM @sf_tut_stage/cities.parquet)"
);

let statement = snowflake().verified_stmt(sql);
assert_eq!(statement.to_string(), sql);
let Statement::CopyIntoSnowflake {
from_transformations: Some(transformations),
..
} = statement
else {
panic!("expected COPY transformations");
};
assert!(transformations.iter().all(|item| matches!(
item,
StageLoadSelectItemKind::SelectItem(SelectItem::UnnamedExpr(Expr::Cast { .. }))
)));
}

#[test]
fn test_copy_into_file_format() {
let sql = concat!(
Expand Down
Loading