Skip to content

Commit 0984b3f

Browse files
authored
chore(query): bump ast 0.1.3 (#17145)
* chore(query): add bump ast 0.1.0 * chore(query): add bump ast 0.1.0 * chore(query): add bump ast 0.1.0 * chore(query): add bump ast 0.1.0 * chore(query): add bump ast 0.1.1 * chore(query): add bump ast 0.1.1 * chore(query): add bump ast 0.1.2 * chore(query): add bump ast 0.1.3 * chore(query): add bump ast 0.1.0 * update * update * update * chore(cli): fix tests * chore(cli): fix tests * chore(cli): fix tests
1 parent ddb5c7d commit 0984b3f

File tree

33 files changed

+656
-2508
lines changed

33 files changed

+656
-2508
lines changed

Cargo.lock

Lines changed: 6 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/query/ast/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "databend-common-ast"
3-
version = "0.0.4"
3+
version = "0.1.3"
44
publish = true
55
description = "SQL parser for Databend"
66
authors = { workspace = true }
@@ -25,7 +25,6 @@ nom-rule = { workspace = true }
2525
ordered-float = { workspace = true }
2626
percent-encoding = { workspace = true }
2727
pratt = { workspace = true }
28-
pretty = { workspace = true }
2928
pretty_assertions = { workspace = true }
3029
recursive = { workspace = true }
3130
rspack-codespan-reporting = { workspace = true }

src/query/ast/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# databend-common-ast
2+
3+
`databend-common-ast` is a module of the Databend project. It provides the Abstract Syntax Tree (AST) used for parsing and interpreting SQL queries.

src/query/ast/src/ast/expr.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,27 +1241,42 @@ pub struct WindowSpec {
12411241
impl Display for WindowSpec {
12421242
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
12431243
write!(f, "(")?;
1244+
1245+
let mut write = false;
1246+
12441247
if let Some(existing_window_name) = &self.existing_window_name {
1245-
write!(f, " {existing_window_name}")?;
1248+
write!(f, "{existing_window_name}")?;
1249+
write = true;
12461250
}
12471251

12481252
if !self.partition_by.is_empty() {
1249-
write!(f, " PARTITION BY ")?;
1253+
if write {
1254+
write!(f, " ")?;
1255+
}
1256+
write = true;
1257+
write!(f, "PARTITION BY ")?;
12501258
write_comma_separated_list(f, &self.partition_by)?;
12511259
}
12521260

12531261
if !self.order_by.is_empty() {
1254-
write!(f, " ORDER BY ")?;
1262+
if write {
1263+
write!(f, " ")?;
1264+
}
1265+
write = true;
1266+
write!(f, "ORDER BY ")?;
12551267
write_comma_separated_list(f, &self.order_by)?;
12561268
}
12571269

12581270
if let Some(frame) = &self.window_frame {
1271+
if write {
1272+
write!(f, " ")?;
1273+
}
12591274
match frame.units {
12601275
WindowFrameUnits::Rows => {
1261-
write!(f, " ROWS")?;
1276+
write!(f, "ROWS")?;
12621277
}
12631278
WindowFrameUnits::Range => {
1264-
write!(f, " RANGE")?;
1279+
write!(f, "RANGE")?;
12651280
}
12661281
}
12671282

@@ -1281,7 +1296,7 @@ impl Display for WindowSpec {
12811296
format_frame(&frame.end_bound)
12821297
)?
12831298
}
1284-
write!(f, " )")?;
1299+
write!(f, ")")?;
12851300
Ok(())
12861301
}
12871302
}
@@ -1868,10 +1883,10 @@ impl ExprReplacer {
18681883
self.replace_expr(expr);
18691884
}
18701885
SelectTarget::StarColumns { column_filter, .. } => {
1871-
if let Some(column_filter) = column_filter
1872-
&& let ColumnFilter::Lambda(lambda) = column_filter
1873-
{
1874-
self.replace_expr(&mut lambda.expr);
1886+
if let Some(column_filter) = column_filter {
1887+
if let ColumnFilter::Lambda(lambda) = column_filter {
1888+
self.replace_expr(&mut lambda.expr);
1889+
}
18751890
}
18761891
}
18771892
}
@@ -2006,10 +2021,10 @@ impl ExprReplacer {
20062021
}
20072022
}
20082023
Expr::CountAll { window, .. } => {
2009-
if let Some(window) = window
2010-
&& let Window::WindowSpec(window_spec) = window
2011-
{
2012-
self.replace_window_spec(window_spec);
2024+
if let Some(window) = window {
2025+
if let Window::WindowSpec(window_spec) = window {
2026+
self.replace_window_spec(window_spec);
2027+
}
20132028
}
20142029
}
20152030
Expr::Tuple { exprs, .. } => {
@@ -2024,10 +2039,10 @@ impl ExprReplacer {
20242039
for param in func.params.iter_mut() {
20252040
self.replace_expr(param);
20262041
}
2027-
if let Some(window_desc) = &mut func.window
2028-
&& let Window::WindowSpec(window_spec) = &mut window_desc.window
2029-
{
2030-
self.replace_window_spec(window_spec);
2042+
if let Some(window_desc) = &mut func.window {
2043+
if let Window::WindowSpec(window_spec) = &mut window_desc.window {
2044+
self.replace_window_spec(window_spec);
2045+
}
20312046
}
20322047
if let Some(lambda) = &mut func.lambda {
20332048
self.replace_expr(&mut lambda.expr);

src/query/ast/src/ast/format/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414

1515
mod indent_format;
1616
mod pretty_format;
17-
mod syntax;
1817

1918
use std::fmt::Display;
2019

21-
pub use syntax::pretty_statement;
22-
2320
#[derive(Clone)]
2421
pub struct FormatTreeNode<T: Display + Clone = String> {
2522
pub payload: T,

0 commit comments

Comments
 (0)