Skip to content

Commit

Permalink
parse: SETTINGS (VAR, ...)=(VAL, ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Oct 24, 2024
1 parent 7a7b577 commit ce965e2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/query/ast/src/ast/statements/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,11 @@ impl Display for Statement {
}
Statement::QueryWithSetting { settings, query } => {
if let Some(setting) = settings {
write!(f, "SETTINGS ({setting}) ")?;
if setting.identifiers.len() > 1 {
write!(f, "SETTINGS {setting} ")?;
} else {
write!(f, "SETTINGS ({setting}) ")?;
}
}
write!(f, "{query}")?;
}
Expand Down
6 changes: 3 additions & 3 deletions src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2807,10 +2807,10 @@ pub fn query_statement_setting(i: Input) -> IResult<Settings> {
);
let more_set = map_res(
rule! {
^"(" ~ "(" ~ #comma_separated_list0(ident) ~ ")" ~ "="
~ "(" ~ #comma_separated_list0(subexpr(0)) ~ ")" ~ ^")"
"(" ~ #comma_separated_list0(ident) ~ ")" ~ "="
~ "(" ~ #comma_separated_list0(subexpr(0)) ~ ")"
},
|(_, _, ids, _, _, _, values, _, _)| {
|(_, ids, _, _, _, values, _)| {
if ids.len() == values.len() {
Ok(Settings {
set_type: SetType::SettingsQuery,
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/tests/it/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn test_statement() {
r#"select * from a semi join b on a.a = b.a;"#,
r#"select * from a left anti join b on a.a = b.a;"#,
r#"select * from a anti join b on a.a = b.a;"#,
r#"SETTINGS ((max_thread, timezone)=(1, 'Aisa/Shanghai')) select 1;"#,
r#"SETTINGS (max_thread, timezone)=(1, 'Aisa/Shanghai') select 1;"#,
r#"SETTINGS (max_thread=1) select * from a anti join b on a.a = b.a;"#,
r#"select * from a right semi join b on a.a = b.a;"#,
r#"select * from a right anti join b on a.a = b.a;"#,
Expand Down
18 changes: 9 additions & 9 deletions src/query/ast/tests/it/testdata/stmt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7139,9 +7139,9 @@ Query(


---------- Input ----------
SETTINGS ((max_thread, timezone)=(1, 'Aisa/Shanghai')) select 1;
SETTINGS (max_thread, timezone)=(1, 'Aisa/Shanghai') select 1;
---------- Output ---------
SETTINGS ((max_thread, timezone) = (1, 'Aisa/Shanghai')) SELECT 1
SETTINGS (max_thread, timezone) = (1, 'Aisa/Shanghai') SELECT 1
---------- AST ------------
QueryWithSetting {
settings: Some(
Expand All @@ -7150,15 +7150,15 @@ QueryWithSetting {
identifiers: [
Identifier {
span: Some(
11..21,
10..20,
),
name: "max_thread",
quote: None,
ident_type: None,
},
Identifier {
span: Some(
23..31,
22..30,
),
name: "timezone",
quote: None,
Expand All @@ -7169,15 +7169,15 @@ QueryWithSetting {
[
Literal {
span: Some(
34..35,
33..34,
),
value: UInt64(
1,
),
},
Literal {
span: Some(
37..52,
36..51,
),
value: String(
"Aisa/Shanghai",
Expand All @@ -7190,13 +7190,13 @@ QueryWithSetting {
query: Query(
Query {
span: Some(
55..63,
53..61,
),
with: None,
body: Select(
SelectStmt {
span: Some(
55..63,
53..61,
),
hints: None,
distinct: false,
Expand All @@ -7205,7 +7205,7 @@ QueryWithSetting {
AliasedExpr {
expr: Literal {
span: Some(
62..63,
60..61,
),
value: UInt64(
1,
Expand Down
2 changes: 1 addition & 1 deletion tests/sqllogictests/suites/query/set.test
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ select id, c from t union all select id, c from t1 order by id, c;
NULL 2022-02-02 00:00:00.000000

query TTTT
settings ((timezone, default_order_by_null)=('Asia/Shanghai', 'nulls_first')) select id, c from t union all select id, c from t1 order by id, c;
settings (timezone, default_order_by_null)=('Asia/Shanghai', 'nulls_first') select id, c from t union all select id, c from t1 order by id, c;
----
NULL 2022-02-02 08:00:00.000000
1 2022-02-02 00:00:00.000000
Expand Down

0 comments on commit ce965e2

Please sign in to comment.