-
Notifications
You must be signed in to change notification settings - Fork 572
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
Implement SnowFlake ALTER SESSION #1712
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks @osipovartem -- I started the CI checks on this PR (looks like there are some failures)
@yoavcloud since you are more familiar with Snowflake syntax, would you be able to review this PR as well?
/// true is to set for the session parameters, false is to unset | ||
set: bool, | ||
/// The session parameters to set or unset | ||
session_params: DataLoadingOptions, |
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.
DataLoading options come from here
pub struct DataLoadingOptions { |
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.
DataLoadingOptions is a very useful struct IMO, I would rename it to KeyValueOptions and promote it to its own helper file.
|
||
#[test] | ||
fn test_alter_session() { | ||
snowflake().verified_stmt("ALTER SESSION SET"); |
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.
This is not a valid Snowflake statement, Snowflake doesn't allow an empty list of params.
#[test] | ||
fn test_alter_session() { | ||
snowflake().verified_stmt("ALTER SESSION SET"); | ||
snowflake().verified_stmt("ALTER SESSION UNSET"); |
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.
This is not a valid Snowflake statement, Snowflake doesn't allow an empty list of params.
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"); |
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.
Snowflake requires a comma for unsetting multiple params
@@ -120,6 +120,12 @@ impl Dialect for SnowflakeDialect { | |||
} | |||
|
|||
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> { | |||
if parser.parse_keywords(&[Keyword::ALTER, Keyword::SESSION]) { | |||
// ALTER SESSION | |||
let set = parser.parse_keyword(Keyword::SET) | !parser.parse_keyword(Keyword::UNSET); |
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.
This would accept any statements that are not accepted by Snowflake such as ALTER SESSION XYZ
. Suggest to rewrite as:
let set = match parser.parse_one_of_keywords(&[Keyword::SET, Keyword::UNSET]) {
Some(Keyword::SET) => true,
Some(Keyword::UNSET) => false,
_ => return Some(parser.expected("SET or UNSET", parser.peek_token()))
};
}, | ||
} | ||
} | ||
Ok(options) |
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.
Perhaps add a check here for empty options and raise error
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.
See my comments inline. Generally speaking, I support parsing of arbitrary options using DataLoadingOptions but would rename and move this struct to a more central location in the codebase to reflect its new purpose.
Sounds good -- @osipovartem -- what do you think? |
Closes #1710
https://docs.snowflake.com/en/sql-reference/sql/alter-session