Skip to content

Commit

Permalink
chore(query): bump ast 0.1.3 (#17145)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sundy-li authored Jan 1, 2025
1 parent ddb5c7d commit 0984b3f
Show file tree
Hide file tree
Showing 33 changed files with 656 additions and 2,508 deletions.
37 changes: 6 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/query/ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "databend-common-ast"
version = "0.0.4"
version = "0.1.3"
publish = true
description = "SQL parser for Databend"
authors = { workspace = true }
Expand All @@ -25,7 +25,6 @@ nom-rule = { workspace = true }
ordered-float = { workspace = true }
percent-encoding = { workspace = true }
pratt = { workspace = true }
pretty = { workspace = true }
pretty_assertions = { workspace = true }
recursive = { workspace = true }
rspack-codespan-reporting = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions src/query/ast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# databend-common-ast

`databend-common-ast` is a module of the Databend project. It provides the Abstract Syntax Tree (AST) used for parsing and interpreting SQL queries.
51 changes: 33 additions & 18 deletions src/query/ast/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,27 +1241,42 @@ pub struct WindowSpec {
impl Display for WindowSpec {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "(")?;

let mut write = false;

if let Some(existing_window_name) = &self.existing_window_name {
write!(f, " {existing_window_name}")?;
write!(f, "{existing_window_name}")?;
write = true;
}

if !self.partition_by.is_empty() {
write!(f, " PARTITION BY ")?;
if write {
write!(f, " ")?;
}
write = true;
write!(f, "PARTITION BY ")?;
write_comma_separated_list(f, &self.partition_by)?;
}

if !self.order_by.is_empty() {
write!(f, " ORDER BY ")?;
if write {
write!(f, " ")?;
}
write = true;
write!(f, "ORDER BY ")?;
write_comma_separated_list(f, &self.order_by)?;
}

if let Some(frame) = &self.window_frame {
if write {
write!(f, " ")?;
}
match frame.units {
WindowFrameUnits::Rows => {
write!(f, " ROWS")?;
write!(f, "ROWS")?;
}
WindowFrameUnits::Range => {
write!(f, " RANGE")?;
write!(f, "RANGE")?;
}
}

Expand All @@ -1281,7 +1296,7 @@ impl Display for WindowSpec {
format_frame(&frame.end_bound)
)?
}
write!(f, " )")?;
write!(f, ")")?;
Ok(())
}
}
Expand Down Expand Up @@ -1868,10 +1883,10 @@ impl ExprReplacer {
self.replace_expr(expr);
}
SelectTarget::StarColumns { column_filter, .. } => {
if let Some(column_filter) = column_filter
&& let ColumnFilter::Lambda(lambda) = column_filter
{
self.replace_expr(&mut lambda.expr);
if let Some(column_filter) = column_filter {
if let ColumnFilter::Lambda(lambda) = column_filter {
self.replace_expr(&mut lambda.expr);
}
}
}
}
Expand Down Expand Up @@ -2006,10 +2021,10 @@ impl ExprReplacer {
}
}
Expr::CountAll { window, .. } => {
if let Some(window) = window
&& let Window::WindowSpec(window_spec) = window
{
self.replace_window_spec(window_spec);
if let Some(window) = window {
if let Window::WindowSpec(window_spec) = window {
self.replace_window_spec(window_spec);
}
}
}
Expr::Tuple { exprs, .. } => {
Expand All @@ -2024,10 +2039,10 @@ impl ExprReplacer {
for param in func.params.iter_mut() {
self.replace_expr(param);
}
if let Some(window_desc) = &mut func.window
&& let Window::WindowSpec(window_spec) = &mut window_desc.window
{
self.replace_window_spec(window_spec);
if let Some(window_desc) = &mut func.window {
if let Window::WindowSpec(window_spec) = &mut window_desc.window {
self.replace_window_spec(window_spec);
}
}
if let Some(lambda) = &mut func.lambda {
self.replace_expr(&mut lambda.expr);
Expand Down
3 changes: 0 additions & 3 deletions src/query/ast/src/ast/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@

mod indent_format;
mod pretty_format;
mod syntax;

use std::fmt::Display;

pub use syntax::pretty_statement;

#[derive(Clone)]
pub struct FormatTreeNode<T: Display + Clone = String> {
pub payload: T,
Expand Down
Loading

0 comments on commit 0984b3f

Please sign in to comment.