-
Notifications
You must be signed in to change notification settings - Fork 550
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
Support Snowflake/BigQuery TRIM. #975
Conversation
@@ -905,6 +908,9 @@ impl fmt::Display for Expr { | |||
} else { | |||
write!(f, "{expr}")?; | |||
} | |||
if let Some(characters) = trim_characters { | |||
write!(f, ", {}", display_comma_separated(characters))?; | |||
} |
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.
print trim characters after expression if there are
src/parser/mod.rs
Outdated
@@ -1323,13 +1324,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) { |
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.
no FROM
(by doc Snowflake doesn't support FROM
syntax) and Snowflake
and next is Comma
-> parse characters
Box::new(PostgreSqlDialect {}), | ||
Box::new(MsSqlDialect {}), | ||
Box::new(AnsiDialect {}), | ||
//Box::new(SnowflakeDialect {}), |
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.
make sure it is still failing on others than snowflake.
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.
Looks great -- thank you @zdenal
There appear to be some small CI errors -- @zdenal can you please fix them? |
@alamb RDY again. I have also added BigQuery to support this syntax (link to BigQuery TRIM doc attached in PR description). |
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.
Thank you @zdenal for your contribution. I had one small comment and then I think this PR is ready to go
src/parser/mod.rs
Outdated
trim_characters: None, | ||
}) | ||
} else if self.consume_token(&Token::Comma) | ||
&& dialect_of!(self is SnowflakeDialect | BigQueryDialect) |
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.
I think the general pattern for this crate is to also include GenericDialect
so it is a superset (as much as possible) of all dialects
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.
@alamb .. added GenericDialect
The CI failures do not appear to be related to this PR -- see #995 I believe if you merge / rebase this branch with |
@alamb RDY again. |
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.
Thank you @zdenal
Pull Request Test Coverage Report for Build 6423740010
💛 - Coveralls |
Why
We are getting errors with parsing snowflake
TRIM
expression including removing characters separated by comma.Snowflake doc for TRIM
https://docs.snowflake.com/en/sql-reference/functions/trim
BigQuery doc for TRIM
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#trim
Example of real failing sql