-
Notifications
You must be signed in to change notification settings - Fork 616
BigQuery: Add support for select expr star #1680
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1002,7 +1002,7 @@ fn parse_select_wildcard() { | |
let select = verified_only_select(sql); | ||
assert_eq!( | ||
&SelectItem::QualifiedWildcard( | ||
ObjectName::from(vec![Ident::new("foo")]), | ||
SelectItemQualifiedWildcardKind::ObjectName(ObjectName::from(vec![Ident::new("foo")])), | ||
WildcardAdditionalOptions::default() | ||
), | ||
only(&select.projection) | ||
|
@@ -1012,7 +1012,10 @@ fn parse_select_wildcard() { | |
let select = verified_only_select(sql); | ||
assert_eq!( | ||
&SelectItem::QualifiedWildcard( | ||
ObjectName::from(vec![Ident::new("myschema"), Ident::new("mytable"),]), | ||
SelectItemQualifiedWildcardKind::ObjectName(ObjectName::from(vec![ | ||
Ident::new("myschema"), | ||
Ident::new("mytable"), | ||
])), | ||
WildcardAdditionalOptions::default(), | ||
), | ||
only(&select.projection) | ||
|
@@ -1057,6 +1060,84 @@ fn parse_column_aliases() { | |
one_statement_parses_to("SELECT a.col + 1 newname FROM foo AS a", sql); | ||
} | ||
|
||
#[test] | ||
fn parse_select_expr_star() { | ||
let dialects = all_dialects_where(|d| d.supports_select_expr_star()); | ||
|
||
// Identifier wildcard expansion. | ||
let select = dialects.verified_only_select("SELECT foo.bar.* FROM T"); | ||
let SelectItem::QualifiedWildcard(SelectItemQualifiedWildcardKind::ObjectName(object_name), _) = | ||
only(&select.projection) | ||
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.
|
||
else { | ||
unreachable!( | ||
"expected wildcard select item: got {:?}", | ||
&select.projection[0] | ||
) | ||
}; | ||
assert_eq!( | ||
&ObjectName::from( | ||
["foo", "bar"] | ||
.into_iter() | ||
.map(Ident::new) | ||
.collect::<Vec<_>>() | ||
), | ||
object_name | ||
); | ||
|
||
// Arbitrary compound expression with wildcard expansion. | ||
let select = dialects.verified_only_select("SELECT foo - bar.* FROM T"); | ||
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. this is kind of wild 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. 😅 thankfully the query isn't semantically valid, maybe the test is misleading in that sense, I added it only to verify that the parser accepts arbitrary expressions and wildcard on variables, but as far as binary operators specifically combined with the wildcard syntax wouldn't have meaning in BigQuery either |
||
let SelectItem::QualifiedWildcard( | ||
SelectItemQualifiedWildcardKind::Expr(Expr::BinaryOp { left, op, right }), | ||
_, | ||
) = only(&select.projection) | ||
else { | ||
unreachable!( | ||
"expected wildcard select item: got {:?}", | ||
&select.projection[0] | ||
) | ||
}; | ||
let (Expr::Identifier(left), BinaryOperator::Minus, Expr::Identifier(right)) = | ||
(left.as_ref(), op, right.as_ref()) | ||
else { | ||
unreachable!("expected binary op expr: got {:?}", &select.projection[0]) | ||
}; | ||
assert_eq!(&Ident::new("foo"), left); | ||
assert_eq!(&Ident::new("bar"), right); | ||
|
||
// Arbitrary expression wildcard expansion. | ||
let select = dialects.verified_only_select("SELECT myfunc().foo.* FROM T"); | ||
let SelectItem::QualifiedWildcard( | ||
SelectItemQualifiedWildcardKind::Expr(Expr::CompoundFieldAccess { root, access_chain }), | ||
_, | ||
) = only(&select.projection) | ||
else { | ||
unreachable!("expected wildcard expr: got {:?}", &select.projection[0]) | ||
}; | ||
assert!(matches!(root.as_ref(), Expr::Function(_))); | ||
assert_eq!(1, access_chain.len()); | ||
assert!(matches!( | ||
&access_chain[0], | ||
AccessExpr::Dot(Expr::Identifier(_)) | ||
)); | ||
|
||
dialects.one_statement_parses_to( | ||
"SELECT 2. * 3 FROM T", | ||
#[cfg(feature = "bigdecimal")] | ||
"SELECT 2 * 3 FROM T", | ||
#[cfg(not(feature = "bigdecimal"))] | ||
"SELECT 2. * 3 FROM T", | ||
); | ||
dialects.verified_only_select("SELECT myfunc().* FROM T"); | ||
dialects.verified_only_select("SELECT myfunc().* EXCEPT (foo) FROM T"); | ||
|
||
// Invalid | ||
let res = dialects.parse_sql_statements("SELECT foo.*.* FROM T"); | ||
assert_eq!( | ||
ParserError::ParserError("Expected: end of statement, found: .".to_string()), | ||
res.unwrap_err() | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_eof_after_as() { | ||
let res = parse_sql_statements("SELECT foo AS"); | ||
|
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.
👍