supporting snowflake extract syntax (#1374)

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
Seve Martinez 2024-08-13 05:56:18 -07:00 committed by GitHub
parent ca5262c13f
commit f5b818e74b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 78 additions and 3 deletions

View file

@ -2019,6 +2019,35 @@ fn parse_extract_custom_part() {
assert_eq!(
&Expr::Extract {
field: DateTimeField::Custom(Ident::new("eod")),
syntax: ExtractSyntax::From,
expr: Box::new(Expr::Identifier(Ident::new("d"))),
},
expr_from_projection(only(&select.projection)),
);
}
#[test]
fn parse_extract_comma() {
let sql = "SELECT EXTRACT(HOUR, d)";
let select = snowflake_and_generic().verified_only_select(sql);
assert_eq!(
&Expr::Extract {
field: DateTimeField::Hour,
syntax: ExtractSyntax::Comma,
expr: Box::new(Expr::Identifier(Ident::new("d"))),
},
expr_from_projection(only(&select.projection)),
);
}
#[test]
fn parse_extract_comma_quoted() {
let sql = "SELECT EXTRACT('hour', d)";
let select = snowflake_and_generic().verified_only_select(sql);
assert_eq!(
&Expr::Extract {
field: DateTimeField::Custom(Ident::with_quote('\'', "hour")),
syntax: ExtractSyntax::Comma,
expr: Box::new(Expr::Identifier(Ident::new("d"))),
},
expr_from_projection(only(&select.projection)),