Skip to content

SYN-1945 Support Snowflake TRIM. #2

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 1 commit into from
Sep 22, 2023

Conversation

zdenal
Copy link

@zdenal zdenal commented Sep 22, 2023

Why

We are getting errors with parsing snowflake TRIM expression including removing characters separated by comma.

https://docs.snowflake.com/en/sql-reference/functions/trim

Example of real failing sql

WITH sub_coupons AS (
    SELECT
        customer_id,
        subscription_id,
        TRIM(coupons.value:coupon_id, '"') AS coupon_id
    FROM model_staging.subscriptions,
    TABLE(FLATTEN(PARSE_JSON(coupons))) AS coupons
),

@@ -1275,13 +1276,24 @@ impl<'a> Parser<'a> {
expr: Box::new(expr),
trim_where,
trim_what: Some(trim_what),
trim_characters: None,
})
} else if self.consume_token(&Token::Comma) && dialect_of!(self is SnowflakeDialect) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no FROM and Snowflake and next is Comma (by doc Snowflake doesn't support FROM syntax) -> parse characters

Box::new(PostgreSqlDialect {}),
Box::new(MsSqlDialect {}),
Box::new(AnsiDialect {}),
//Box::new(SnowflakeDialect {}),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure it is still failing on others than snowflake.

@@ -0,0 +1,36 @@
name: Test Suite
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added simple test workflow to see on PRs results of tests.

@zdenal zdenal marked this pull request as ready for review September 22, 2023 10:52
@zdenal zdenal self-assigned this Sep 22, 2023
@zdenal zdenal requested a review from lustefaniak September 22, 2023 10:52
@@ -994,6 +997,9 @@ impl fmt::Display for Expr {
} else {
write!(f, "{expr}")?;
}
if let Some(characters) = trim_characters {
write!(f, ", {}", display_comma_separated(characters))?;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print trim characters after expression if there are

@zdenal zdenal force-pushed the zdenko/snowflake-parse-trim-with-second-param-2 branch from c01f05c to 0398ed5 Compare September 22, 2023 11:25
@zdenal zdenal merged commit 9bce54f into main Sep 22, 2023
@zdenal zdenal changed the title Support Snowflake TRIM. SYN-1945 Support Snowflake TRIM. Sep 22, 2023
@lustefaniak lustefaniak deleted the zdenko/snowflake-parse-trim-with-second-param-2 branch October 27, 2023 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants