Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

osipovartem
Copy link

Copy link
Contributor

@alamb alamb left a 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,
Copy link
Contributor

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 {

Copy link
Contributor

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");
Copy link
Contributor

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");
Copy link
Contributor

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");
Copy link
Contributor

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);
Copy link
Contributor

@yoavcloud yoavcloud Feb 8, 2025

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)
Copy link
Contributor

@yoavcloud yoavcloud Feb 8, 2025

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

Copy link
Contributor

@yoavcloud yoavcloud left a 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.

@alamb
Copy link
Contributor

alamb commented Feb 8, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ALTER SESSION
3 participants