Skip to content

Implement SnowFlake ALTER SESSION #1712

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

Merged
merged 7 commits into from
Feb 21, 2025
Merged

Conversation

osipovartem
Copy link
Contributor

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?

src/ast/mod.rs Outdated
/// 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?

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.

LGTM @iffyio @alamb!

Copy link
Contributor

@iffyio iffyio 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!

@iffyio
Copy link
Contributor

iffyio commented Feb 17, 2025

@osipovartem could you take a look into the CI failure?

@alamb alamb marked this pull request as draft February 18, 2025 19:37
@alamb
Copy link
Contributor

alamb commented Feb 18, 2025

Marking as draft as we sort out the CI failure

@osipovartem osipovartem marked this pull request as ready for review February 20, 2025 08:47
@iffyio iffyio merged commit 3ace97c into apache:main Feb 21, 2025
9 checks passed
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Apr 10, 2025
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
4 participants