mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-12-23 11:12:51 +00:00
Support parsing parenthesized wildcard (*) (#2123)
Some checks failed
Rust / codestyle (push) Has been cancelled
Rust / lint (push) Has been cancelled
Rust / benchmark-lint (push) Has been cancelled
Rust / compile (push) Has been cancelled
Rust / docs (push) Has been cancelled
Rust / compile-no-std (push) Has been cancelled
Rust / test (beta) (push) Has been cancelled
Rust / test (nightly) (push) Has been cancelled
Rust / test (stable) (push) Has been cancelled
license / Release Audit Tool (RAT) (push) Has been cancelled
Some checks failed
Rust / codestyle (push) Has been cancelled
Rust / lint (push) Has been cancelled
Rust / benchmark-lint (push) Has been cancelled
Rust / compile (push) Has been cancelled
Rust / docs (push) Has been cancelled
Rust / compile-no-std (push) Has been cancelled
Rust / test (beta) (push) Has been cancelled
Rust / test (nightly) (push) Has been cancelled
Rust / test (stable) (push) Has been cancelled
license / Release Audit Tool (RAT) (push) Has been cancelled
This commit is contained in:
parent
39418cfebb
commit
355a3bfd90
2 changed files with 28 additions and 0 deletions
|
|
@ -1268,6 +1268,15 @@ impl<'a> Parser<'a> {
|
|||
Token::Mul => {
|
||||
return Ok(Expr::Wildcard(AttachedToken(next_token)));
|
||||
}
|
||||
// Handle parenthesized wildcard: (*)
|
||||
Token::LParen => {
|
||||
let [maybe_mul, maybe_rparen] = self.peek_tokens_ref();
|
||||
if maybe_mul.token == Token::Mul && maybe_rparen.token == Token::RParen {
|
||||
let mul_token = self.next_token(); // consume Mul
|
||||
self.next_token(); // consume RParen
|
||||
return Ok(Expr::Wildcard(AttachedToken(mul_token)));
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -17953,3 +17953,22 @@ fn test_parse_set_session_authorization() {
|
|||
}))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_select_parenthesized_wildcard() {
|
||||
// Test SELECT DISTINCT(*) which uses a parenthesized wildcard
|
||||
// The parentheses are syntactic sugar and get normalized to just *
|
||||
let sql = "SELECT DISTINCT (*) FROM table1";
|
||||
let canonical = "SELECT DISTINCT * FROM table1";
|
||||
let select = all_dialects().verified_only_select_with_canonical(sql, canonical);
|
||||
assert_eq!(select.distinct, Some(Distinct::Distinct));
|
||||
assert_eq!(select.projection.len(), 1);
|
||||
assert!(matches!(select.projection[0], SelectItem::Wildcard(_)));
|
||||
|
||||
// Also test without spaces: SELECT DISTINCT(*)
|
||||
let sql_no_spaces = "SELECT DISTINCT(*) FROM table1";
|
||||
let select2 = all_dialects().verified_only_select_with_canonical(sql_no_spaces, canonical);
|
||||
assert_eq!(select2.distinct, Some(Distinct::Distinct));
|
||||
assert_eq!(select2.projection.len(), 1);
|
||||
assert!(matches!(select2.projection[0], SelectItem::Wildcard(_)));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue