Skip to content

Commit 7c836ab

Browse files
author
aleksei.p
committed
update
1 parent 33cc4d9 commit 7c836ab

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

src/ast/helpers/stmt_create_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use sqlparser_derive::{Visit, VisitMut};
99

1010
use crate::ast::{
1111
ColumnDef, Expr, FileFormat, HiveDistributionStyle, HiveFormat, Ident, ObjectName, OnCommit,
12-
Query, SqlOption, Statement, TableConstraint, TableEngine,
12+
OneOrManyWithParens, Query, SqlOption, Statement, TableConstraint, TableEngine,
1313
};
1414
use crate::parser::ParserError;
1515

@@ -72,7 +72,7 @@ pub struct CreateTableBuilder {
7272
pub on_commit: Option<OnCommit>,
7373
pub on_cluster: Option<String>,
7474
pub primary_key: Option<Box<Expr>>,
75-
pub order_by: Option<Vec<Expr>>,
75+
pub order_by: Option<OneOrManyWithParens<Expr>>,
7676
pub partition_by: Option<Box<Expr>>,
7777
pub cluster_by: Option<Vec<Ident>>,
7878
pub options: Option<Vec<SqlOption>>,
@@ -244,7 +244,7 @@ impl CreateTableBuilder {
244244
self
245245
}
246246

247-
pub fn order_by(mut self, order_by: Option<Vec<Expr>>) -> Self {
247+
pub fn order_by(mut self, order_by: Option<OneOrManyWithParens<Expr>>) -> Self {
248248
self.order_by = order_by;
249249
self
250250
}

src/ast/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ pub enum Statement {
20102010
/// ClickHouse "ORDER BY " clause. Note that omitted ORDER BY is different
20112011
/// than empty (represented as ()), the latter meaning "no sorting".
20122012
/// <https://clickhouse.com/docs/en/sql-reference/statements/create/table/>
2013-
order_by: Option<Vec<Expr>>,
2013+
order_by: Option<OneOrManyWithParens<Expr>>,
20142014
/// BigQuery: A partition expression for the table.
20152015
/// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#partition_expression>
20162016
partition_by: Option<Box<Expr>>,
@@ -3568,7 +3568,7 @@ impl fmt::Display for Statement {
35683568
write!(f, " PRIMARY KEY {primary_key}")?;
35693569
}
35703570
if let Some(order_by) = order_by {
3571-
write!(f, " ORDER BY ({})", display_comma_separated(order_by))?;
3571+
write!(f, " ORDER BY {order_by}")?;
35723572
}
35733573
if let Some(partition_by) = partition_by.as_ref() {
35743574
write!(f, " PARTITION BY {partition_by}")?;

src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5183,9 +5183,9 @@ impl<'a> Parser<'a> {
51835183
vec![]
51845184
};
51855185
self.expect_token(&Token::RParen)?;
5186-
Some(columns)
5186+
Some(OneOrManyWithParens::Many(columns))
51875187
} else {
5188-
Some(vec![self.parse_expr()?])
5188+
Some(OneOrManyWithParens::One(self.parse_expr()?))
51895189
}
51905190
} else {
51915191
None

tests/sqlparser_clickhouse.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,9 @@ fn parse_delimited_identifiers() {
211211
#[test]
212212
fn parse_create_table() {
213213
clickhouse().verified_stmt(r#"CREATE TABLE "x" ("a" "int") ENGINE=MergeTree ORDER BY ("x")"#);
214-
clickhouse().one_statement_parses_to(
215-
r#"CREATE TABLE "x" ("a" "int") ENGINE=MergeTree ORDER BY "x""#,
216-
r#"CREATE TABLE "x" ("a" "int") ENGINE=MergeTree ORDER BY ("x")"#,
217-
);
214+
clickhouse().verified_stmt(r#"CREATE TABLE "x" ("a" "int") ENGINE=MergeTree ORDER BY "x""#);
218215
clickhouse().verified_stmt(
219-
r#"CREATE TABLE "x" ("a" "int") ENGINE=MergeTree ORDER BY ("x") AS SELECT * FROM "t" WHERE true"#,
216+
r#"CREATE TABLE "x" ("a" "int") ENGINE=MergeTree ORDER BY "x" AS SELECT * FROM "t" WHERE true"#,
220217
);
221218
}
222219

@@ -233,7 +230,7 @@ fn parse_create_table_with_primary_key() {
233230
r#"CREATE TABLE db.table (`i` INT, `k` INT)"#,
234231
" ENGINE=SharedMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}')",
235232
" PRIMARY KEY tuple(i)",
236-
" ORDER BY (tuple(i))",
233+
" ORDER BY tuple(i)",
237234
),
238235
) {
239236
Statement::CreateTable {
@@ -292,9 +289,9 @@ fn parse_create_table_with_primary_key() {
292289
}
293290
_ => panic!("unexpected primary key type"),
294291
}
295-
match order_by.unwrap().first().unwrap() {
296-
Expr::Function(order_by) => {
297-
assert!(assert_function(order_by, "tuple", "i"));
292+
match order_by {
293+
Some(OneOrManyWithParens::One(Expr::Function(order_by))) => {
294+
assert!(assert_function(&order_by, "tuple", "i"));
298295
}
299296
_ => panic!("unexpected order by type"),
300297
};

0 commit comments

Comments
 (0)