Skip to content

Commit 2575081

Browse files
committed
code improvements
1 parent 39be235 commit 2575081

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

src/parser/mod.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,7 @@ impl<'a> Parser<'a> {
27712771

27722772
if self.dialect.supports_dictionary_syntax() {
27732773
self.prev_token(); // Put back the '{'
2774-
return self.parse_duckdb_and_clickhouse_struct_literal();
2774+
return self.parse_dictionary();
27752775
}
27762776

27772777
self.expected("an expression", token)
@@ -3157,13 +3157,10 @@ impl<'a> Parser<'a> {
31573157
///
31583158
/// [dictionary]: https://duckdb.org/docs/sql/data_types/struct#creating-structs
31593159
/// [map]: https://clickhouse.com/docs/operations/settings/settings#additional_table_filters
3160-
fn parse_duckdb_and_clickhouse_struct_literal(&mut self) -> Result<Expr, ParserError> {
3160+
fn parse_dictionary(&mut self) -> Result<Expr, ParserError> {
31613161
self.expect_token(&Token::LBrace)?;
31623162

3163-
let fields = self.parse_comma_separated0(
3164-
Self::parse_duckdb_and_clickhouse_struct_field,
3165-
Token::RBrace,
3166-
)?;
3163+
let fields = self.parse_comma_separated0(Self::parse_dictionary_field, Token::RBrace)?;
31673164

31683165
self.expect_token(&Token::RBrace)?;
31693166

@@ -3180,7 +3177,7 @@ impl<'a> Parser<'a> {
31803177
///
31813178
/// [dictionary]: https://duckdb.org/docs/sql/data_types/struct#creating-structs
31823179
/// [map]: https://clickhouse.com/docs/operations/settings/settings#additional_table_filters
3183-
fn parse_duckdb_and_clickhouse_struct_field(&mut self) -> Result<DictionaryField, ParserError> {
3180+
fn parse_dictionary_field(&mut self) -> Result<DictionaryField, ParserError> {
31843181
let key = self.parse_identifier()?;
31853182

31863183
self.expect_token(&Token::Colon)?;
@@ -11194,12 +11191,7 @@ impl<'a> Parser<'a> {
1119411191
let key_values = self.parse_comma_separated(|p| {
1119511192
let key = p.parse_identifier()?;
1119611193
p.expect_token(&Token::Eq)?;
11197-
11198-
let value = if p.peek_token_ref().token == Token::LBrace {
11199-
p.parse_duckdb_and_clickhouse_struct_literal()?
11200-
} else {
11201-
Expr::Value(p.parse_value()?)
11202-
};
11194+
let value = p.parse_expr()?;
1120311195
Ok(Setting { key, value })
1120411196
})?;
1120511197
Some(key_values)

tests/sqlparser_clickhouse.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,16 +1019,12 @@ fn parse_settings_in_query() {
10191019
("SELECT * FROM t SETTINGS a", "Expected: =, found: EOF"),
10201020
(
10211021
"SELECT * FROM t SETTINGS a=",
1022-
"Expected: a value, found: EOF",
1022+
"Expected: an expression, found: EOF",
10231023
),
10241024
("SELECT * FROM t SETTINGS a=1, b", "Expected: =, found: EOF"),
10251025
(
10261026
"SELECT * FROM t SETTINGS a=1, b=",
1027-
"Expected: a value, found: EOF",
1028-
),
1029-
(
1030-
"SELECT * FROM t SETTINGS a=1, b=c",
1031-
"Expected: a concrete value, found: c",
1027+
"Expected: an expression, found: EOF",
10321028
),
10331029
(
10341030
"SELECT * FROM t SETTINGS a = {",
@@ -1658,7 +1654,6 @@ fn parse_select_table_function_settings() {
16581654
"SELECT * FROM t(SETTINGS a=)",
16591655
"SELECT * FROM t(SETTINGS a=1, b)",
16601656
"SELECT * FROM t(SETTINGS a=1, b=)",
1661-
"SELECT * FROM t(SETTINGS a=1, b=c)",
16621657
];
16631658
for sql in invalid_cases {
16641659
clickhouse_and_generic()

0 commit comments

Comments
 (0)