Skip to content

Commit c7285be

Browse files
authored
Revert "Support trailing commas in FROM clause (apache#1645)"
This reverts commit b10b291.
1 parent 3623d50 commit c7285be

File tree

5 files changed

+12
-88
lines changed

5 files changed

+12
-88
lines changed

src/dialect/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,6 @@ pub trait Dialect: Debug + Any {
404404
self.supports_trailing_commas()
405405
}
406406

407-
/// Returns true if the dialect supports trailing commas in the `FROM` clause of a `SELECT` statement.
408-
/// /// Example: `SELECT 1 FROM T, U, LIMIT 1`
409-
fn supports_from_trailing_commas(&self) -> bool {
410-
false
411-
}
412-
413407
/// Returns true if the dialect supports double dot notation for object names
414408
///
415409
/// Example
@@ -781,12 +775,6 @@ pub trait Dialect: Debug + Any {
781775
keywords::RESERVED_FOR_IDENTIFIER.contains(&kw)
782776
}
783777

784-
// Returns reserved keywords when looking to parse a [TableFactor].
785-
/// See [Self::supports_from_trailing_commas]
786-
fn get_reserved_keywords_for_table_factor(&self) -> &[Keyword] {
787-
keywords::RESERVED_FOR_TABLE_FACTOR
788-
}
789-
790778
/// Returns true if this dialect supports the `TABLESAMPLE` option
791779
/// before the table alias option. For example:
792780
///

src/dialect/snowflake.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ impl Dialect for SnowflakeDialect {
5656
true
5757
}
5858

59-
fn supports_from_trailing_commas(&self) -> bool {
60-
true
61-
}
62-
6359
// Snowflake supports double-dot notation when the schema name is not specified
6460
// In this case the default PUBLIC schema is used
6561
//

src/keywords.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,16 +1007,6 @@ pub const RESERVED_FOR_COLUMN_ALIAS: &[Keyword] = &[
10071007
Keyword::END,
10081008
];
10091009

1010-
// Global list of reserved keywords alloweed after FROM.
1011-
// Parser should call Dialect::get_reserved_keyword_after_from
1012-
// to allow for each dialect to customize the list.
1013-
pub const RESERVED_FOR_TABLE_FACTOR: &[Keyword] = &[
1014-
Keyword::INTO,
1015-
Keyword::LIMIT,
1016-
Keyword::HAVING,
1017-
Keyword::WHERE,
1018-
];
1019-
10201010
/// Global list of reserved keywords that cannot be parsed as identifiers
10211011
/// without special handling like quoting. Parser should call `Dialect::is_reserved_for_identifier`
10221012
/// to allow for each dialect to customize the list.

src/parser/mod.rs

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3940,11 +3940,7 @@ impl<'a> Parser<'a> {
39403940
let trailing_commas =
39413941
self.options.trailing_commas | self.dialect.supports_projection_trailing_commas();
39423942

3943-
self.parse_comma_separated_with_trailing_commas(
3944-
|p| p.parse_select_item(),
3945-
trailing_commas,
3946-
None,
3947-
)
3943+
self.parse_comma_separated_with_trailing_commas(|p| p.parse_select_item(), trailing_commas)
39483944
}
39493945

39503946
pub fn parse_actions_list(&mut self) -> Result<Vec<ParsedAction>, ParserError> {
@@ -3970,32 +3966,20 @@ impl<'a> Parser<'a> {
39703966
Ok(values)
39713967
}
39723968

3973-
/// Parse a list of [TableWithJoins]
3974-
fn parse_table_with_joins(&mut self) -> Result<Vec<TableWithJoins>, ParserError> {
3975-
let trailing_commas = self.dialect.supports_from_trailing_commas();
3976-
3977-
self.parse_comma_separated_with_trailing_commas(
3978-
Parser::parse_table_and_joins,
3979-
trailing_commas,
3980-
Some(self.dialect.get_reserved_keywords_for_table_factor()),
3981-
)
3982-
}
3983-
39843969
/// Parse the comma of a comma-separated syntax element.
39853970
/// Allows for control over trailing commas
39863971
/// Returns true if there is a next element
3987-
fn is_parse_comma_separated_end_with_trailing_commas(
3988-
&mut self,
3989-
trailing_commas: bool,
3990-
reserved_keywords: Option<&[Keyword]>,
3991-
) -> bool {
3992-
let reserved_keywords = reserved_keywords.unwrap_or(keywords::RESERVED_FOR_COLUMN_ALIAS);
3972+
fn is_parse_comma_separated_end_with_trailing_commas(&mut self, trailing_commas: bool) -> bool {
39933973
if !self.consume_token(&Token::Comma) {
39943974
true
39953975
} else if trailing_commas {
39963976
let token = self.peek_token().token;
39973977
match token {
3998-
Token::Word(ref kw) if reserved_keywords.contains(&kw.keyword) => true,
3978+
Token::Word(ref kw)
3979+
if keywords::RESERVED_FOR_COLUMN_ALIAS.contains(&kw.keyword) =>
3980+
{
3981+
true
3982+
}
39993983
Token::RParen | Token::SemiColon | Token::EOF | Token::RBracket | Token::RBrace => {
40003984
true
40013985
}
@@ -4009,15 +3993,15 @@ impl<'a> Parser<'a> {
40093993
/// Parse the comma of a comma-separated syntax element.
40103994
/// Returns true if there is a next element
40113995
fn is_parse_comma_separated_end(&mut self) -> bool {
4012-
self.is_parse_comma_separated_end_with_trailing_commas(self.options.trailing_commas, None)
3996+
self.is_parse_comma_separated_end_with_trailing_commas(self.options.trailing_commas)
40133997
}
40143998

40153999
/// Parse a comma-separated list of 1+ items accepted by `F`
40164000
pub fn parse_comma_separated<T, F>(&mut self, f: F) -> Result<Vec<T>, ParserError>
40174001
where
40184002
F: FnMut(&mut Parser<'a>) -> Result<T, ParserError>,
40194003
{
4020-
self.parse_comma_separated_with_trailing_commas(f, self.options.trailing_commas, None)
4004+
self.parse_comma_separated_with_trailing_commas(f, self.options.trailing_commas)
40214005
}
40224006

40234007
/// Parse a comma-separated list of 1+ items accepted by `F`
@@ -4026,18 +4010,14 @@ impl<'a> Parser<'a> {
40264010
&mut self,
40274011
mut f: F,
40284012
trailing_commas: bool,
4029-
reserved_keywords: Option<&[Keyword]>,
40304013
) -> Result<Vec<T>, ParserError>
40314014
where
40324015
F: FnMut(&mut Parser<'a>) -> Result<T, ParserError>,
40334016
{
40344017
let mut values = vec![];
40354018
loop {
40364019
values.push(f(self)?);
4037-
if self.is_parse_comma_separated_end_with_trailing_commas(
4038-
trailing_commas,
4039-
reserved_keywords,
4040-
) {
4020+
if self.is_parse_comma_separated_end_with_trailing_commas(trailing_commas) {
40414021
break;
40424022
}
40434023
}
@@ -10093,7 +10073,7 @@ impl<'a> Parser<'a> {
1009310073
// or `from`.
1009410074

1009510075
let from = if self.parse_keyword(Keyword::FROM) {
10096-
self.parse_table_with_joins()?
10076+
self.parse_comma_separated(Parser::parse_table_and_joins)?
1009710077
} else {
1009810078
vec![]
1009910079
};

tests/sqlparser_common.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12957,38 +12957,8 @@ fn parse_update_from_before_select() {
1295712957
parse_sql_statements(query).unwrap_err()
1295812958
);
1295912959
}
12960+
1296012961
#[test]
1296112962
fn parse_overlaps() {
1296212963
verified_stmt("SELECT (DATE '2016-01-10', DATE '2016-02-01') OVERLAPS (DATE '2016-01-20', DATE '2016-02-10')");
1296312964
}
12964-
12965-
#[test]
12966-
fn test_trailing_commas_in_from() {
12967-
let dialects = all_dialects_where(|d| d.supports_from_trailing_commas());
12968-
dialects.verified_only_select_with_canonical("SELECT 1, 2 FROM t,", "SELECT 1, 2 FROM t");
12969-
12970-
dialects
12971-
.verified_only_select_with_canonical("SELECT 1, 2 FROM t1, t2,", "SELECT 1, 2 FROM t1, t2");
12972-
12973-
let sql = "SELECT a, FROM b, LIMIT 1";
12974-
let _ = dialects.parse_sql_statements(sql).unwrap();
12975-
12976-
let sql = "INSERT INTO a SELECT b FROM c,";
12977-
let _ = dialects.parse_sql_statements(sql).unwrap();
12978-
12979-
let sql = "SELECT a FROM b, HAVING COUNT(*) > 1";
12980-
let _ = dialects.parse_sql_statements(sql).unwrap();
12981-
12982-
let sql = "SELECT a FROM b, WHERE c = 1";
12983-
let _ = dialects.parse_sql_statements(sql).unwrap();
12984-
12985-
// nasted
12986-
let sql = "SELECT 1, 2 FROM (SELECT * FROM t,),";
12987-
let _ = dialects.parse_sql_statements(sql).unwrap();
12988-
12989-
// multiple_subqueries
12990-
dialects.verified_only_select_with_canonical(
12991-
"SELECT 1, 2 FROM (SELECT * FROM t1), (SELECT * FROM t2),",
12992-
"SELECT 1, 2 FROM (SELECT * FROM t1), (SELECT * FROM t2)",
12993-
);
12994-
}

0 commit comments

Comments
 (0)