mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Implement SnowFlake ALTER SESSION (#1712)
This commit is contained in:
parent
28736da235
commit
3ace97c0ef
8 changed files with 335 additions and 197 deletions
|
@ -19,9 +19,8 @@
|
|||
//! Test SQL syntax specific to Snowflake. The parser based on the
|
||||
//! generic dialect is also tested (on the inputs it can handle).
|
||||
|
||||
use sqlparser::ast::helpers::stmt_data_loading::{
|
||||
DataLoadingOption, DataLoadingOptionType, StageLoadSelectItem,
|
||||
};
|
||||
use sqlparser::ast::helpers::key_value_options::{KeyValueOption, KeyValueOptionType};
|
||||
use sqlparser::ast::helpers::stmt_data_loading::StageLoadSelectItem;
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{Dialect, GenericDialect, SnowflakeDialect};
|
||||
use sqlparser::parser::{ParserError, ParserOptions};
|
||||
|
@ -1914,38 +1913,26 @@ fn test_create_stage_with_stage_params() {
|
|||
"<s3_api_compatible_endpoint>",
|
||||
stage_params.endpoint.unwrap()
|
||||
);
|
||||
assert!(stage_params
|
||||
.credentials
|
||||
.options
|
||||
.contains(&DataLoadingOption {
|
||||
option_name: "AWS_KEY_ID".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
value: "1a2b3c".to_string()
|
||||
}));
|
||||
assert!(stage_params
|
||||
.credentials
|
||||
.options
|
||||
.contains(&DataLoadingOption {
|
||||
option_name: "AWS_SECRET_KEY".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
value: "4x5y6z".to_string()
|
||||
}));
|
||||
assert!(stage_params
|
||||
.encryption
|
||||
.options
|
||||
.contains(&DataLoadingOption {
|
||||
option_name: "MASTER_KEY".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
value: "key".to_string()
|
||||
}));
|
||||
assert!(stage_params
|
||||
.encryption
|
||||
.options
|
||||
.contains(&DataLoadingOption {
|
||||
option_name: "TYPE".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
value: "AWS_SSE_KMS".to_string()
|
||||
}));
|
||||
assert!(stage_params.credentials.options.contains(&KeyValueOption {
|
||||
option_name: "AWS_KEY_ID".to_string(),
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: "1a2b3c".to_string()
|
||||
}));
|
||||
assert!(stage_params.credentials.options.contains(&KeyValueOption {
|
||||
option_name: "AWS_SECRET_KEY".to_string(),
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: "4x5y6z".to_string()
|
||||
}));
|
||||
assert!(stage_params.encryption.options.contains(&KeyValueOption {
|
||||
option_name: "MASTER_KEY".to_string(),
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: "key".to_string()
|
||||
}));
|
||||
assert!(stage_params.encryption.options.contains(&KeyValueOption {
|
||||
option_name: "TYPE".to_string(),
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: "AWS_SSE_KMS".to_string()
|
||||
}));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
@ -1966,19 +1953,19 @@ fn test_create_stage_with_directory_table_params() {
|
|||
directory_table_params,
|
||||
..
|
||||
} => {
|
||||
assert!(directory_table_params.options.contains(&DataLoadingOption {
|
||||
assert!(directory_table_params.options.contains(&KeyValueOption {
|
||||
option_name: "ENABLE".to_string(),
|
||||
option_type: DataLoadingOptionType::BOOLEAN,
|
||||
option_type: KeyValueOptionType::BOOLEAN,
|
||||
value: "TRUE".to_string()
|
||||
}));
|
||||
assert!(directory_table_params.options.contains(&DataLoadingOption {
|
||||
assert!(directory_table_params.options.contains(&KeyValueOption {
|
||||
option_name: "REFRESH_ON_CREATE".to_string(),
|
||||
option_type: DataLoadingOptionType::BOOLEAN,
|
||||
option_type: KeyValueOptionType::BOOLEAN,
|
||||
value: "FALSE".to_string()
|
||||
}));
|
||||
assert!(directory_table_params.options.contains(&DataLoadingOption {
|
||||
assert!(directory_table_params.options.contains(&KeyValueOption {
|
||||
option_name: "NOTIFICATION_INTEGRATION".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: "some-string".to_string()
|
||||
}));
|
||||
}
|
||||
|
@ -1997,19 +1984,19 @@ fn test_create_stage_with_file_format() {
|
|||
|
||||
match snowflake_without_unescape().verified_stmt(sql) {
|
||||
Statement::CreateStage { file_format, .. } => {
|
||||
assert!(file_format.options.contains(&DataLoadingOption {
|
||||
assert!(file_format.options.contains(&KeyValueOption {
|
||||
option_name: "COMPRESSION".to_string(),
|
||||
option_type: DataLoadingOptionType::ENUM,
|
||||
option_type: KeyValueOptionType::ENUM,
|
||||
value: "AUTO".to_string()
|
||||
}));
|
||||
assert!(file_format.options.contains(&DataLoadingOption {
|
||||
assert!(file_format.options.contains(&KeyValueOption {
|
||||
option_name: "BINARY_FORMAT".to_string(),
|
||||
option_type: DataLoadingOptionType::ENUM,
|
||||
option_type: KeyValueOptionType::ENUM,
|
||||
value: "HEX".to_string()
|
||||
}));
|
||||
assert!(file_format.options.contains(&DataLoadingOption {
|
||||
assert!(file_format.options.contains(&KeyValueOption {
|
||||
option_name: "ESCAPE".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: r#"\\"#.to_string()
|
||||
}));
|
||||
}
|
||||
|
@ -2030,14 +2017,14 @@ fn test_create_stage_with_copy_options() {
|
|||
);
|
||||
match snowflake().verified_stmt(sql) {
|
||||
Statement::CreateStage { copy_options, .. } => {
|
||||
assert!(copy_options.options.contains(&DataLoadingOption {
|
||||
assert!(copy_options.options.contains(&KeyValueOption {
|
||||
option_name: "ON_ERROR".to_string(),
|
||||
option_type: DataLoadingOptionType::ENUM,
|
||||
option_type: KeyValueOptionType::ENUM,
|
||||
value: "CONTINUE".to_string()
|
||||
}));
|
||||
assert!(copy_options.options.contains(&DataLoadingOption {
|
||||
assert!(copy_options.options.contains(&KeyValueOption {
|
||||
option_name: "FORCE".to_string(),
|
||||
option_type: DataLoadingOptionType::BOOLEAN,
|
||||
option_type: KeyValueOptionType::BOOLEAN,
|
||||
value: "TRUE".to_string()
|
||||
}));
|
||||
}
|
||||
|
@ -2167,38 +2154,26 @@ fn test_copy_into_with_stage_params() {
|
|||
"<s3_api_compatible_endpoint>",
|
||||
stage_params.endpoint.unwrap()
|
||||
);
|
||||
assert!(stage_params
|
||||
.credentials
|
||||
.options
|
||||
.contains(&DataLoadingOption {
|
||||
option_name: "AWS_KEY_ID".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
value: "1a2b3c".to_string()
|
||||
}));
|
||||
assert!(stage_params
|
||||
.credentials
|
||||
.options
|
||||
.contains(&DataLoadingOption {
|
||||
option_name: "AWS_SECRET_KEY".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
value: "4x5y6z".to_string()
|
||||
}));
|
||||
assert!(stage_params
|
||||
.encryption
|
||||
.options
|
||||
.contains(&DataLoadingOption {
|
||||
option_name: "MASTER_KEY".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
value: "key".to_string()
|
||||
}));
|
||||
assert!(stage_params
|
||||
.encryption
|
||||
.options
|
||||
.contains(&DataLoadingOption {
|
||||
option_name: "TYPE".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
value: "AWS_SSE_KMS".to_string()
|
||||
}));
|
||||
assert!(stage_params.credentials.options.contains(&KeyValueOption {
|
||||
option_name: "AWS_KEY_ID".to_string(),
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: "1a2b3c".to_string()
|
||||
}));
|
||||
assert!(stage_params.credentials.options.contains(&KeyValueOption {
|
||||
option_name: "AWS_SECRET_KEY".to_string(),
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: "4x5y6z".to_string()
|
||||
}));
|
||||
assert!(stage_params.encryption.options.contains(&KeyValueOption {
|
||||
option_name: "MASTER_KEY".to_string(),
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: "key".to_string()
|
||||
}));
|
||||
assert!(stage_params.encryption.options.contains(&KeyValueOption {
|
||||
option_name: "TYPE".to_string(),
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: "AWS_SSE_KMS".to_string()
|
||||
}));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
@ -2326,19 +2301,19 @@ fn test_copy_into_file_format() {
|
|||
|
||||
match snowflake_without_unescape().verified_stmt(sql) {
|
||||
Statement::CopyIntoSnowflake { file_format, .. } => {
|
||||
assert!(file_format.options.contains(&DataLoadingOption {
|
||||
assert!(file_format.options.contains(&KeyValueOption {
|
||||
option_name: "COMPRESSION".to_string(),
|
||||
option_type: DataLoadingOptionType::ENUM,
|
||||
option_type: KeyValueOptionType::ENUM,
|
||||
value: "AUTO".to_string()
|
||||
}));
|
||||
assert!(file_format.options.contains(&DataLoadingOption {
|
||||
assert!(file_format.options.contains(&KeyValueOption {
|
||||
option_name: "BINARY_FORMAT".to_string(),
|
||||
option_type: DataLoadingOptionType::ENUM,
|
||||
option_type: KeyValueOptionType::ENUM,
|
||||
value: "HEX".to_string()
|
||||
}));
|
||||
assert!(file_format.options.contains(&DataLoadingOption {
|
||||
assert!(file_format.options.contains(&KeyValueOption {
|
||||
option_name: "ESCAPE".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: r#"\\"#.to_string()
|
||||
}));
|
||||
}
|
||||
|
@ -2365,19 +2340,19 @@ fn test_copy_into_file_format() {
|
|||
.unwrap()
|
||||
{
|
||||
Statement::CopyIntoSnowflake { file_format, .. } => {
|
||||
assert!(file_format.options.contains(&DataLoadingOption {
|
||||
assert!(file_format.options.contains(&KeyValueOption {
|
||||
option_name: "COMPRESSION".to_string(),
|
||||
option_type: DataLoadingOptionType::ENUM,
|
||||
option_type: KeyValueOptionType::ENUM,
|
||||
value: "AUTO".to_string()
|
||||
}));
|
||||
assert!(file_format.options.contains(&DataLoadingOption {
|
||||
assert!(file_format.options.contains(&KeyValueOption {
|
||||
option_name: "BINARY_FORMAT".to_string(),
|
||||
option_type: DataLoadingOptionType::ENUM,
|
||||
option_type: KeyValueOptionType::ENUM,
|
||||
value: "HEX".to_string()
|
||||
}));
|
||||
assert!(file_format.options.contains(&DataLoadingOption {
|
||||
assert!(file_format.options.contains(&KeyValueOption {
|
||||
option_name: "ESCAPE".to_string(),
|
||||
option_type: DataLoadingOptionType::STRING,
|
||||
option_type: KeyValueOptionType::STRING,
|
||||
value: r#"\\"#.to_string()
|
||||
}));
|
||||
}
|
||||
|
@ -2397,14 +2372,14 @@ fn test_copy_into_copy_options() {
|
|||
|
||||
match snowflake().verified_stmt(sql) {
|
||||
Statement::CopyIntoSnowflake { copy_options, .. } => {
|
||||
assert!(copy_options.options.contains(&DataLoadingOption {
|
||||
assert!(copy_options.options.contains(&KeyValueOption {
|
||||
option_name: "ON_ERROR".to_string(),
|
||||
option_type: DataLoadingOptionType::ENUM,
|
||||
option_type: KeyValueOptionType::ENUM,
|
||||
value: "CONTINUE".to_string()
|
||||
}));
|
||||
assert!(copy_options.options.contains(&DataLoadingOption {
|
||||
assert!(copy_options.options.contains(&KeyValueOption {
|
||||
option_name: "FORCE".to_string(),
|
||||
option_type: DataLoadingOptionType::BOOLEAN,
|
||||
option_type: KeyValueOptionType::BOOLEAN,
|
||||
value: "TRUE".to_string()
|
||||
}));
|
||||
}
|
||||
|
@ -3475,3 +3450,35 @@ fn test_grant_database_role_to() {
|
|||
snowflake_and_generic().verified_stmt("GRANT DATABASE ROLE r1 TO ROLE r2");
|
||||
snowflake_and_generic().verified_stmt("GRANT DATABASE ROLE db1.sc1.r1 TO ROLE db1.sc1.r2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_alter_session() {
|
||||
assert_eq!(
|
||||
snowflake()
|
||||
.parse_sql_statements("ALTER SESSION SET")
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"sql parser error: expected at least one option"
|
||||
);
|
||||
assert_eq!(
|
||||
snowflake()
|
||||
.parse_sql_statements("ALTER SESSION UNSET")
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"sql parser error: expected at least one option"
|
||||
);
|
||||
|
||||
snowflake().verified_stmt("ALTER SESSION SET AUTOCOMMIT=TRUE");
|
||||
snowflake().verified_stmt("ALTER SESSION SET AUTOCOMMIT=FALSE QUERY_TAG='tag'");
|
||||
snowflake().verified_stmt("ALTER SESSION UNSET AUTOCOMMIT");
|
||||
snowflake().verified_stmt("ALTER SESSION UNSET AUTOCOMMIT, QUERY_TAG");
|
||||
snowflake().one_statement_parses_to(
|
||||
"ALTER SESSION SET A=false, B='tag';",
|
||||
"ALTER SESSION SET A=FALSE B='tag'",
|
||||
);
|
||||
snowflake().one_statement_parses_to(
|
||||
"ALTER SESSION SET A=true \nB='tag'",
|
||||
"ALTER SESSION SET A=TRUE B='tag'",
|
||||
);
|
||||
snowflake().one_statement_parses_to("ALTER SESSION UNSET a\nB", "ALTER SESSION UNSET a, B");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue