-
Notifications
You must be signed in to change notification settings - Fork 606
Fix INTERVAL
parsing to support expressions and units via dialect
#1398
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
f70d90a
f643d44
d61d73e
83e9398
fa8e807
829be2a
2c14b95
b6dcbf2
6c2a971
522f981
aebf858
4e13da3
31a19f7
5aed0d3
4cc404a
297df8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
#[macro_use] | ||
mod test_utils; | ||
|
||
use sqlparser::ast; | ||
use std::ops::Deref; | ||
|
||
use sqlparser::ast::*; | ||
|
@@ -830,16 +829,14 @@ fn parse_typed_struct_syntax_bigquery() { | |
expr_from_projection(&select.projection[3]) | ||
); | ||
|
||
let sql = r#"SELECT STRUCT<INTERVAL>(INTERVAL '1-2 3 4:5:6.789999'), STRUCT<JSON>(JSON '{"class" : {"students" : [{"name" : "Jane"}]}}')"#; | ||
let sql = r#"SELECT STRUCT<INTERVAL>(INTERVAL '2' HOUR), STRUCT<JSON>(JSON '{"class" : {"students" : [{"name" : "Jane"}]}}')"#; | ||
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. Could you please
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. Looking at the BigQuery syntax in https://cloud.google.com/bigquery/docs/reference/standard-sql/interval_functions I actually think the new test is more useful / correct -- all the intervals appear to have a unit after them, such as: ...
UNNEST([INTERVAL '1-2 3 4:5:6.789999' YEAR TO SECOND,
INTERVAL '0-13 370 48:61:61' YEAR TO SECOND]) AS i
... 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. yup, BigQuery is MySQL flavoured when it comes to intervals, so intervals without units are not permitted. |
||
let select = bigquery().verified_only_select(sql); | ||
assert_eq!(2, select.projection.len()); | ||
assert_eq!( | ||
&Expr::Struct { | ||
values: vec![Expr::Interval(ast::Interval { | ||
value: Box::new(Expr::Value(Value::SingleQuotedString( | ||
"1-2 3 4:5:6.789999".to_string() | ||
))), | ||
leading_field: None, | ||
values: vec![Expr::Interval(Interval { | ||
value: Box::new(Expr::Value(Value::SingleQuotedString("2".to_string()))), | ||
leading_field: Some(DateTimeField::Hour), | ||
leading_precision: None, | ||
last_field: None, | ||
fractional_seconds_precision: None | ||
|
@@ -1141,16 +1138,14 @@ fn parse_typed_struct_syntax_bigquery_and_generic() { | |
expr_from_projection(&select.projection[3]) | ||
); | ||
|
||
let sql = r#"SELECT STRUCT<INTERVAL>(INTERVAL '1-2 3 4:5:6.789999'), STRUCT<JSON>(JSON '{"class" : {"students" : [{"name" : "Jane"}]}}')"#; | ||
let sql = r#"SELECT STRUCT<INTERVAL>(INTERVAL '1' MONTH), STRUCT<JSON>(JSON '{"class" : {"students" : [{"name" : "Jane"}]}}')"#; | ||
let select = bigquery_and_generic().verified_only_select(sql); | ||
assert_eq!(2, select.projection.len()); | ||
assert_eq!( | ||
&Expr::Struct { | ||
values: vec![Expr::Interval(ast::Interval { | ||
value: Box::new(Expr::Value(Value::SingleQuotedString( | ||
"1-2 3 4:5:6.789999".to_string() | ||
))), | ||
leading_field: None, | ||
values: vec![Expr::Interval(Interval { | ||
value: Box::new(Expr::Value(Value::SingleQuotedString("1".to_string()))), | ||
leading_field: Some(DateTimeField::Month), | ||
leading_precision: None, | ||
last_field: None, | ||
fractional_seconds_precision: None | ||
|
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.
drive-by change, this seemed really ugly, I couldn't resist fixing it.