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
6 changes: 6 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,12 @@ fn parse_stage_params(parser: &mut Parser) -> Result<StageParamsObject, ParserEr
}?)
}

// STORAGE_INTEGRATION may follow ENDPOINT, but a duplicate stays unconsumed.
if storage_integration.is_none() && parser.parse_keyword(Keyword::STORAGE_INTEGRATION) {
parser.expect_token(&Token::Eq)?;
storage_integration = Some(parser.next_token().token.to_string());
}

// CREDENTIALS
if parser.parse_keyword(Keyword::CREDENTIALS) {
parser.expect_token(&Token::Eq)?;
Expand Down
55 changes: 55 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6283,3 +6283,58 @@ fn snowflake_bound_stage_prefix_is_data_and_display_remains_one_operand() {
};
assert_eq!(reparsed, bound);
}

#[test]
fn snowflake_create_stage_storage_integration_can_follow_endpoint() {
let canonical = concat!(
"CREATE STAGE reference_stage ",
"URL='s3://example-bucket/raw%40path/' ",
"STORAGE_INTEGRATION=LOCAL_REFERENCE ",
"ENDPOINT='https://example.invalid/raw%3Fpath/' ",
"FILE_FORMAT=(TYPE=CSV FIELD_DELIMITER='|') COMMENT='metadata only'"
);
let endpoint_first = concat!(
"CREATE STAGE reference_stage ",
"URL='s3://example-bucket/raw%40path/' ",
"ENDPOINT='https://example.invalid/raw%3Fpath/' ",
"STORAGE_INTEGRATION=LOCAL_REFERENCE ",
"FILE_FORMAT=(TYPE=CSV FIELD_DELIMITER='|') COMMENT='metadata only'"
);
let expected = snowflake().verified_stmt(canonical);
let observed = snowflake().one_statement_parses_to(endpoint_first, canonical);
let (
Statement::CreateStage {
stage_params: expected,
..
},
Statement::CreateStage {
stage_params: observed,
..
},
) = (expected, observed)
else {
panic!("expected CREATE STAGE");
};
assert_eq!(observed, expected);
assert_eq!(
observed.storage_integration.as_deref(),
Some("LOCAL_REFERENCE")
);
assert_eq!(
observed.endpoint.as_deref(),
Some("https://example.invalid/raw%3Fpath/")
);
}

#[test]
fn snowflake_create_stage_duplicate_integration_or_endpoint_stays_unsupported() {
for parameters in [
"STORAGE_INTEGRATION=first ENDPOINT='https://example.invalid/' STORAGE_INTEGRATION=second",
"ENDPOINT='https://example.invalid/' STORAGE_INTEGRATION=first STORAGE_INTEGRATION=second",
"STORAGE_INTEGRATION=first STORAGE_INTEGRATION=second ENDPOINT='https://example.invalid/'",
"ENDPOINT='https://first.invalid/' STORAGE_INTEGRATION=first ENDPOINT='https://second.invalid/'",
] {
let sql = format!("CREATE STAGE reference_stage URL='s3://example-bucket/' {parameters}");
assert!(snowflake().parse_sql_statements(&sql).is_err(), "{sql}");
}
}
Loading