-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Test Suite | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
types: [opened, synchronize] | ||
|
||
jobs: | ||
check: | ||
name: Check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: check | ||
|
||
test: | ||
name: Test Suite | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
override: true | ||
- uses: actions-rs/cargo@v1 | ||
with: | ||
command: test |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -584,12 +584,14 @@ pub enum Expr { | |
/// ```sql | ||
/// TRIM([BOTH | LEADING | TRAILING] [<expr> FROM] <expr>) | ||
/// TRIM(<expr>) | ||
/// TRIM(<expr>, [, characters]) -- only Snowflake | ||
/// ``` | ||
Trim { | ||
expr: Box<Expr>, | ||
// ([BOTH | LEADING | TRAILING] | ||
trim_where: Option<TrimWhereField>, | ||
trim_what: Option<Box<Expr>>, | ||
trim_characters: Option<Vec<Expr>>, | ||
}, | ||
/// ```sql | ||
/// OVERLAY(<expr> PLACING <expr> FROM <expr>[ FOR <expr> ] | ||
|
@@ -984,6 +986,7 @@ impl fmt::Display for Expr { | |
expr, | ||
trim_where, | ||
trim_what, | ||
trim_characters | ||
} => { | ||
write!(f, "TRIM(")?; | ||
if let Some(ident) = trim_where { | ||
|
@@ -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))?; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. print trim characters after expression if there are |
||
|
||
write!(f, ")") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1254,6 +1254,7 @@ impl<'a> Parser<'a> { | |
/// ```sql | ||
/// TRIM ([WHERE] ['text' FROM] 'text') | ||
/// TRIM ('text') | ||
/// TRIM(<expr>, [, characters]) -- only Snowflake | ||
/// ``` | ||
pub fn parse_trim_expr(&mut self) -> Result<Expr, ParserError> { | ||
self.expect_token(&Token::LParen)?; | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no |
||
let characters = self.parse_comma_separated(Parser::parse_expr)?; | ||
self.expect_token(&Token::RParen)?; | ||
Ok(Expr::Trim { | ||
expr: Box::new(expr), | ||
trim_where: None, | ||
trim_what: None, | ||
trim_characters: Some(characters), | ||
}) | ||
} else { | ||
self.expect_token(&Token::RParen)?; | ||
Ok(Expr::Trim { | ||
expr: Box::new(expr), | ||
trim_where, | ||
trim_what: None, | ||
trim_characters: None, | ||
}) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4967,6 +4967,30 @@ fn parse_trim() { | |
ParserError::ParserError("Expected ), found: 'xyz'\nNear `SELECT TRIM(FOO`".to_owned()), | ||
parse_sql_statements("SELECT TRIM(FOO 'xyz' FROM 'xyzfooxyz')").unwrap_err() | ||
); | ||
|
||
//keep Snowflake TRIM syntax failing | ||
let all_expected_snowflake = TestedDialects { | ||
dialects: vec![ | ||
Box::new(GenericDialect {}), | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. make sure it is still failing on others than snowflake. |
||
Box::new(HiveDialect {}), | ||
Box::new(RedshiftSqlDialect {}), | ||
Box::new(MySqlDialect {}), | ||
Box::new(BigQueryDialect {}), | ||
Box::new(SQLiteDialect {}), | ||
Box::new(DuckDbDialect {}), | ||
], | ||
options: None, | ||
}; | ||
assert_eq!( | ||
ParserError::ParserError("Expected ), found: 'a'\nNear `SELECT TRIM('xyz',`".to_owned()), | ||
all_expected_snowflake | ||
.parse_sql_statements("SELECT TRIM('xyz', 'a')") | ||
.unwrap_err() | ||
); | ||
} | ||
|
||
#[test] | ||
|
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.
Added simple test workflow to see on PRs results of tests.