From 9509cd753fb23a084833d2e3fb31cf595d379c49 Mon Sep 17 00:00:00 2001 From: Andy Lok Date: Sun, 3 Mar 2024 18:23:43 +0800 Subject: [PATCH] refactor(ast): add derive-visitor for expr and query (#14814) * refactor(ast): add derive-visitor for expr and query * fix * fix * fix * fix --- Cargo.lock | 23 + Cargo.toml | 1 + src/query/ast/Cargo.toml | 1 + src/query/ast/src/ast/common.rs | 46 +- src/query/ast/src/ast/expr.rs | 223 +- src/query/ast/src/ast/format/ast_format.rs | 2 +- src/query/ast/src/ast/format/syntax/expr.rs | 102 +- src/query/ast/src/ast/format/syntax/query.rs | 2 +- src/query/ast/src/ast/query.rs | 125 +- src/query/ast/src/ast/statements/copy.rs | 40 +- src/query/ast/src/ast/statements/database.rs | 6 +- src/query/ast/src/ast/statements/hint.rs | 7 +- src/query/ast/src/ast/statements/stage.rs | 95 +- src/query/ast/src/ast/visitors/walk.rs | 24 +- src/query/ast/src/ast/visitors/walk_mut.rs | 24 +- src/query/ast/src/parser/common.rs | 7 + src/query/ast/src/parser/expr.rs | 204 +- src/query/ast/src/parser/query.rs | 15 +- src/query/ast/src/parser/statement.rs | 70 +- src/query/ast/src/parser/stream.rs | 2 +- .../tests/it/testdata/experimental-expr.txt | 794 ++-- src/query/ast/tests/it/testdata/expr.txt | 3658 +++++++++-------- src/query/ast/tests/it/testdata/query.txt | 2060 +++++----- src/query/ast/tests/it/testdata/statement.txt | 3584 ++++++++-------- src/query/constraint/tests/it/parser.rs | 52 +- .../functions/tests/it/scalars/parser.rs | 17 +- src/query/sql/src/planner/binder/aggregate.rs | 10 +- .../sql/src/planner/binder/copy_into_table.rs | 11 +- .../sql/src/planner/binder/ddl/database.rs | 4 +- .../src/planner/binder/ddl/virtual_column.rs | 4 +- src/query/sql/src/planner/binder/project.rs | 22 +- .../sql/src/planner/binder/project_set.rs | 20 +- src/query/sql/src/planner/binder/select.rs | 41 +- src/query/sql/src/planner/binder/stage.rs | 2 +- src/query/sql/src/planner/binder/table.rs | 43 +- .../sql/src/planner/binder/table_args.rs | 5 +- src/query/sql/src/planner/dataframe.rs | 24 +- .../planner/semantic/aggregate_rewriter.rs | 13 +- .../semantic/aggregating_index_visitor.rs | 68 +- .../planner/semantic/distinct_to_groupby.rs | 45 +- .../sql/src/planner/semantic/type_check.rs | 157 +- src/tests/sqlsmith/src/sql_gen/expr.rs | 122 +- src/tests/sqlsmith/src/sql_gen/func.rs | 15 +- src/tests/sqlsmith/src/sql_gen/query.rs | 29 +- 44 files changed, 6409 insertions(+), 5410 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5689b9330f8fb..9decb8d10bc47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2588,6 +2588,7 @@ dependencies = [ "databend-common-functions", "databend-common-io", "databend-common-meta-app", + "derive-visitor", "enum-as-inner 0.5.1", "ethnum 1.5.0 (git+https://github.com/ariesdevil/ethnum-rs?rev=4cb05f1)", "fast-float", @@ -4847,6 +4848,28 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive-visitor" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21045832f19977a1bec46f3d826609794661c0d23370f3ee35b8ef6537861cd6" +dependencies = [ + "derive-visitor-macros", +] + +[[package]] +name = "derive-visitor-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22c6a42ab7b480fb19a029c5e54cb8cdf912c7798cf0192441d2d92eb4af8012" +dependencies = [ + "convert_case 0.4.0", + "itertools 0.10.5", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "derive-where" version = "1.2.7" diff --git a/Cargo.toml b/Cargo.toml index fabfd206577a6..d1221316f2bfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -172,6 +172,7 @@ tonic-reflection = { version = "0.10.2" } typetag = "0.2.3" uuid = { version = "1.1.2", features = ["serde", "v4"] } walkdir = "2.3.2" +derive-visitor = "0.3.0" # Future and async futures = "0.3.24" diff --git a/src/query/ast/Cargo.toml b/src/query/ast/Cargo.toml index 183004b44f700..ca7e660b67395 100644 --- a/src/query/ast/Cargo.toml +++ b/src/query/ast/Cargo.toml @@ -18,6 +18,7 @@ databend-common-io = { path = "../../common/io" } databend-common-meta-app = { path = "../../meta/app" } # Crates.io dependencies +derive-visitor = { workspace = true } enum-as-inner = "0.5.1" ethnum = { workspace = true } fast-float = "0.2.0" diff --git a/src/query/ast/src/ast/common.rs b/src/query/ast/src/ast/common.rs index 35166df4d5475..8690d63e75ca1 100644 --- a/src/query/ast/src/ast/common.rs +++ b/src/query/ast/src/ast/common.rs @@ -16,14 +16,19 @@ use std::fmt::Display; use std::fmt::Formatter; use databend_common_exception::Span; +use derive_visitor::Drive; +use derive_visitor::DriveMut; use crate::parser::quote::quote_ident; // Identifier of table name or column name. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub struct Identifier { + #[drive(skip)] pub span: Span, + #[drive(skip)] pub name: String, + #[drive(skip)] pub quote: Option, } @@ -60,10 +65,13 @@ impl Display for Identifier { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub struct ColumnPosition { + #[drive(skip)] pub span: Span, + #[drive(skip)] pub pos: usize, + #[drive(skip)] pub name: String, } @@ -86,7 +94,7 @@ impl Display for ColumnPosition { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum ColumnID { Name(Identifier), Position(ColumnPosition), @@ -110,7 +118,23 @@ impl Display for ColumnID { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] +pub struct DatabaseRef { + pub catalog: Option, + pub database: Identifier, +} + +impl Display for DatabaseRef { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + if let Some(catalog) = &self.catalog { + write!(f, "{}.", catalog)?; + } + write!(f, "{}", self.database)?; + Ok(()) + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub struct TableRef { pub catalog: Option, pub database: Option, @@ -121,7 +145,7 @@ impl Display for TableRef { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { assert!(self.catalog.is_none() || (self.catalog.is_some() && self.database.is_some())); if let Some(catalog) = &self.catalog { - write!(f, "{catalog}.")?; + write!(f, "{}.", catalog)?; } if let Some(database) = &self.database { write!(f, "{}.", database)?; @@ -131,7 +155,7 @@ impl Display for TableRef { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub struct ColumnRef { pub database: Option, pub table: Option, @@ -140,13 +164,21 @@ pub struct ColumnRef { impl Display for ColumnRef { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + assert!(self.database.is_none() || (self.database.is_some() && self.table.is_some())); + + if f.alternate() { + write!(f, "{}", self.column)?; + return Ok(()); + } + if let Some(database) = &self.database { write!(f, "{}.", database)?; } if let Some(table) = &self.table { write!(f, "{}.", table)?; } - write!(f, "{}", self.column) + write!(f, "{}", self.column)?; + Ok(()) } } diff --git a/src/query/ast/src/ast/expr.rs b/src/query/ast/src/ast/expr.rs index 72b82e6224843..5a695c4121572 100644 --- a/src/query/ast/src/ast/expr.rs +++ b/src/query/ast/src/ast/expr.rs @@ -21,62 +21,73 @@ use databend_common_exception::Span; use databend_common_functions::aggregates::AggregateFunctionFactory; use databend_common_io::display_decimal_256; use databend_common_io::escape_string_with_quote; +use derive_visitor::Drive; +use derive_visitor::DriveMut; use enum_as_inner::EnumAsInner; use ethnum::i256; -use super::ColumnID; +use super::ColumnRef; use super::OrderByExpr; use crate::ast::write_comma_separated_list; -use crate::ast::write_dot_separated_list; use crate::ast::Identifier; use crate::ast::Query; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum Expr { /// Column reference, with indirection like `table.column` ColumnRef { + #[drive(skip)] span: Span, - database: Option, - table: Option, - column: ColumnID, + column: ColumnRef, }, /// `IS [ NOT ] NULL` expression IsNull { + #[drive(skip)] span: Span, expr: Box, + #[drive(skip)] not: bool, }, /// `IS [NOT] DISTINCT` expression IsDistinctFrom { + #[drive(skip)] span: Span, left: Box, right: Box, + #[drive(skip)] not: bool, }, /// `[ NOT ] IN (expr, ...)` InList { + #[drive(skip)] span: Span, expr: Box, list: Vec, + #[drive(skip)] not: bool, }, /// `[ NOT ] IN (SELECT ...)` InSubquery { + #[drive(skip)] span: Span, expr: Box, subquery: Box, + #[drive(skip)] not: bool, }, /// `BETWEEN ... AND ...` Between { + #[drive(skip)] span: Span, expr: Box, low: Box, high: Box, + #[drive(skip)] not: bool, }, /// Binary operation BinaryOp { + #[drive(skip)] span: Span, op: BinaryOperator, left: Box, @@ -84,6 +95,7 @@ pub enum Expr { }, /// JSON operation JsonOp { + #[drive(skip)] span: Span, op: JsonOperator, left: Box, @@ -91,43 +103,51 @@ pub enum Expr { }, /// Unary operation UnaryOp { + #[drive(skip)] span: Span, op: UnaryOperator, expr: Box, }, /// `CAST` expression, like `CAST(expr AS target_type)` Cast { + #[drive(skip)] span: Span, expr: Box, target_type: TypeName, + #[drive(skip)] pg_style: bool, }, /// `TRY_CAST` expression` TryCast { + #[drive(skip)] span: Span, expr: Box, target_type: TypeName, }, /// EXTRACT(IntervalKind FROM ) Extract { + #[drive(skip)] span: Span, kind: IntervalKind, expr: Box, }, /// DATE_PART(IntervalKind, ) DatePart { + #[drive(skip)] span: Span, kind: IntervalKind, expr: Box, }, /// POSITION( IN ) Position { + #[drive(skip)] span: Span, substr_expr: Box, str_expr: Box, }, /// SUBSTRING( [FROM ] [FOR ]) Substring { + #[drive(skip)] span: Span, expr: Box, substring_from: Box, @@ -137,30 +157,39 @@ pub enum Expr { /// Or /// TRIM() Trim { + #[drive(skip)] span: Span, expr: Box, // ([BOTH | LEADING | TRAILING], ) trim_where: Option<(TrimWhere, Box)>, }, /// A literal value, such as string, number, date or NULL - Literal { span: Span, lit: Literal }, + Literal { + #[drive(skip)] + span: Span, + lit: Literal, + }, /// `COUNT(*)` expression - CountAll { span: Span, window: Option }, + CountAll { + #[drive(skip)] + span: Span, + window: Option, + }, /// `(foo, bar)` - Tuple { span: Span, exprs: Vec }, + Tuple { + #[drive(skip)] + span: Span, + exprs: Vec, + }, /// Scalar/Agg/Window function call FunctionCall { + #[drive(skip)] span: Span, - /// Set to true if the function is aggregate function with `DISTINCT`, like `COUNT(DISTINCT a)` - distinct: bool, - name: Identifier, - args: Vec, - params: Vec, - window: Option, - lambda: Option, + func: FunctionCall, }, /// `CASE ... WHEN ... ELSE ...` expression Case { + #[drive(skip)] span: Span, operand: Option>, conditions: Vec, @@ -169,56 +198,69 @@ pub enum Expr { }, /// `EXISTS` expression Exists { + #[drive(skip)] span: Span, /// Indicate if this is a `NOT EXISTS` + #[drive(skip)] not: bool, subquery: Box, }, /// Scalar/ANY/ALL/SOME subquery Subquery { + #[drive(skip)] span: Span, modifier: Option, subquery: Box, }, /// Access elements of `Array`, `Map` and `Variant` by index or key, like `arr[0]`, or `obj:k1` MapAccess { + #[drive(skip)] span: Span, expr: Box, accessor: MapAccessor, }, /// The `Array` expr - Array { span: Span, exprs: Vec }, + Array { + #[drive(skip)] + span: Span, + exprs: Vec, + }, /// The `Map` expr Map { + #[drive(skip)] span: Span, kvs: Vec<(Literal, Expr)>, }, /// The `Interval 1 DAY` expr Interval { + #[drive(skip)] span: Span, expr: Box, unit: IntervalKind, }, DateAdd { + #[drive(skip)] span: Span, unit: IntervalKind, interval: Box, date: Box, }, DateSub { + #[drive(skip)] span: Span, unit: IntervalKind, interval: Box, date: Box, }, DateTrunc { + #[drive(skip)] span: Span, unit: IntervalKind, date: Box, }, } -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum IntervalKind { Year, Quarter, @@ -232,40 +274,58 @@ pub enum IntervalKind { Dow, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum SubqueryModifier { Any, All, Some, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum Literal { - UInt64(u64), - Float64(f64), + UInt64(#[drive(skip)] u64), + Float64(#[drive(skip)] f64), Decimal256 { + #[drive(skip)] value: i256, + #[drive(skip)] precision: u8, + #[drive(skip)] scale: u8, }, // Quoted string literal value - String(String), - Boolean(bool), + String(#[drive(skip)] String), + Boolean(#[drive(skip)] bool), Null, } +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] +pub struct FunctionCall { + /// Set to true if the function is aggregate function with `DISTINCT`, like `COUNT(DISTINCT a)` + #[drive(skip)] + pub distinct: bool, + pub name: Identifier, + pub args: Vec, + pub params: Vec, + pub window: Option, + pub lambda: Option, +} + /// The display style for a map access expression -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum MapAccessor { /// `[0][1]` Bracket { key: Box }, /// `.1` - DotNumber { key: u64 }, + DotNumber { + #[drive(skip)] + key: u64, + }, /// `:a:b` Colon { key: Identifier }, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum TypeName { Boolean, UInt8, @@ -279,7 +339,9 @@ pub enum TypeName { Float32, Float64, Decimal { + #[drive(skip)] precision: u8, + #[drive(skip)] scale: u8, }, Date, @@ -293,6 +355,7 @@ pub enum TypeName { }, Bitmap, Tuple { + #[drive(skip)] fields_name: Option>, fields_type: Vec, }, @@ -323,31 +386,31 @@ impl TypeName { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum TrimWhere { Both, Leading, Trailing, } -#[derive(Debug, Clone, PartialEq, EnumAsInner)] +#[derive(Debug, Clone, PartialEq, EnumAsInner, Drive, DriveMut)] pub enum Window { WindowReference(WindowRef), WindowSpec(WindowSpec), } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct WindowDefinition { pub name: Identifier, pub spec: WindowSpec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct WindowRef { pub window_name: Identifier, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct WindowSpec { pub existing_window_name: Option, pub partition_by: Vec, @@ -356,21 +419,21 @@ pub struct WindowSpec { } /// `RANGE UNBOUNDED PRECEDING` or `ROWS BETWEEN 5 PRECEDING AND CURRENT ROW`. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct WindowFrame { pub units: WindowFrameUnits, pub start_bound: WindowFrameBound, pub end_bound: WindowFrameBound, } -#[derive(Debug, Clone, PartialEq, Eq, Hash, EnumAsInner)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, EnumAsInner, Drive, DriveMut)] pub enum WindowFrameUnits { Rows, Range, } /// Specifies [WindowFrame]'s `start_bound` and `end_bound` -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum WindowFrameBound { /// `CURRENT ROW` CurrentRow, @@ -380,13 +443,13 @@ pub enum WindowFrameBound { Following(Option>), } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct Lambda { pub params: Vec, pub expr: Box, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum BinaryOperator { Plus, Minus, @@ -458,7 +521,7 @@ impl BinaryOperator { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum JsonOperator { /// -> keeps the value as json Arrow, @@ -505,7 +568,7 @@ impl JsonOperator { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum UnaryOperator { Plus, Minus, @@ -600,6 +663,39 @@ impl Display for IntervalKind { } } +impl Display for FunctionCall { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let FunctionCall { + distinct, + name, + args, + params, + window, + lambda, + } = self; + write!(f, "{name}")?; + if !params.is_empty() { + write!(f, "(")?; + write_comma_separated_list(f, params)?; + write!(f, ")")?; + } + write!(f, "(")?; + if *distinct { + write!(f, "DISTINCT ")?; + } + write_comma_separated_list(f, args)?; + if let Some(lambda) = lambda { + write!(f, ", {lambda}")?; + } + write!(f, ")")?; + + if let Some(window) = window { + write!(f, " OVER ({window})")?; + } + Ok(()) + } +} + impl Display for SubqueryModifier { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { @@ -1029,20 +1125,11 @@ impl Display for Lambda { impl Display for Expr { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { - Expr::ColumnRef { - database, - table, - column, - .. - } => { + Expr::ColumnRef { column, .. } => { if f.alternate() { - write!(f, "{}", column)?; + write!(f, "{column:#}")?; } else { - write_dot_separated_list(f, database.iter().chain(table))?; - if table.is_some() { - write!(f, ".")?; - } - write!(f, "{}", column)?; + write!(f, "{column}")?; } } Expr::IsNull { expr, not, .. } => { @@ -1191,34 +1278,8 @@ impl Display for Expr { } write!(f, ")")?; } - Expr::FunctionCall { - distinct, - name, - args, - params, - window, - lambda, - .. - } => { - write!(f, "{name}")?; - if !params.is_empty() { - write!(f, "(")?; - write_comma_separated_list(f, params)?; - write!(f, ")")?; - } - write!(f, "(")?; - if *distinct { - write!(f, "DISTINCT ")?; - } - write_comma_separated_list(f, args)?; - if let Some(lambda) = lambda { - write!(f, ", {lambda}")?; - } - write!(f, ")")?; - - if let Some(window) = window { - write!(f, " OVER ({window})")?; - } + Expr::FunctionCall { func, .. } => { + write!(f, "{func}")?; } Expr::Case { operand, @@ -1369,8 +1430,8 @@ pub fn contain_agg_func(expr: &Expr) -> bool { Expr::Literal { .. } => false, Expr::CountAll { .. } => false, Expr::Tuple { exprs, .. } => exprs.iter().any(contain_agg_func), - Expr::FunctionCall { name, .. } => { - AggregateFunctionFactory::instance().contains(name.to_string()) + Expr::FunctionCall { func, .. } => { + AggregateFunctionFactory::instance().contains(func.name.to_string()) } Expr::Case { operand, diff --git a/src/query/ast/src/ast/format/ast_format.rs b/src/query/ast/src/ast/format/ast_format.rs index 4cfbbe36c80cd..0bc54230946e5 100644 --- a/src/query/ast/src/ast/format/ast_format.rs +++ b/src/query/ast/src/ast/format/ast_format.rs @@ -1184,7 +1184,7 @@ impl<'ast> Visitor<'ast> for AstFormatVisitor { fn visit_create_database(&mut self, stmt: &'ast CreateDatabaseStmt) { let mut children = Vec::new(); - self.visit_database_ref(&stmt.catalog, &stmt.database); + self.visit_database_ref(&stmt.database.catalog, &stmt.database.database); children.push(self.children.pop().unwrap()); if let Some(engine) = &stmt.engine { let engine_name = format!("DatabaseEngine {}", engine); diff --git a/src/query/ast/src/ast/format/syntax/expr.rs b/src/query/ast/src/ast/format/syntax/expr.rs index 4852092656207..a449c2bd2566b 100644 --- a/src/query/ast/src/ast/format/syntax/expr.rs +++ b/src/query/ast/src/ast/format/syntax/expr.rs @@ -21,26 +21,22 @@ use crate::ast::format::syntax::parenthesized; use crate::ast::format::syntax::NEST_FACTOR; use crate::ast::BinaryOperator; use crate::ast::Expr; +use crate::ast::FunctionCall; use crate::ast::MapAccessor; pub(crate) fn pretty_expr(expr: Expr) -> RcDoc<'static> { match expr { - Expr::ColumnRef { - database, - table, - column, - .. - } => if let Some(database) = database { + Expr::ColumnRef { column, .. } => if let Some(database) = column.database { RcDoc::text(database.to_string()).append(RcDoc::text(".")) } else { RcDoc::nil() } - .append(if let Some(table) = table { + .append(if let Some(table) = column.table { RcDoc::text(table.to_string()).append(RcDoc::text(".")) } else { RcDoc::nil() }) - .append(RcDoc::text(column.to_string())), + .append(RcDoc::text(column.column.to_string())), Expr::IsNull { expr, not, .. } => pretty_expr(*expr) .append(RcDoc::space()) .append(RcDoc::text("IS")) @@ -250,40 +246,62 @@ pub(crate) fn pretty_expr(expr: Expr) -> RcDoc<'static> { Expr::Tuple { exprs, .. } => RcDoc::text("(") .append(inline_comma(exprs.into_iter().map(pretty_expr))) .append(RcDoc::text(")")), - Expr::FunctionCall { - distinct, - name, - args, - params, - window, - .. - } => RcDoc::text(name.to_string()) - .append(if !params.is_empty() { - RcDoc::text("(") - .append(inline_comma( - params - .into_iter() - .map(|literal| RcDoc::text(literal.to_string())), - )) - .append(")") - } else { - RcDoc::nil() - }) - .append(RcDoc::text("(")) - .append(if distinct { - RcDoc::text("DISTINCT").append(RcDoc::space()) - } else { - RcDoc::nil() - }) - .append(inline_comma(args.into_iter().map(pretty_expr))) - .append(RcDoc::text(")")) - .append(if let Some(window) = window { - RcDoc::text(" OVER (") - .append(RcDoc::text(window.to_string())) - .append(")") - } else { - RcDoc::nil() - }), + Expr::FunctionCall { func, .. } => { + let FunctionCall { + name, + distinct, + args, + params, + window, + lambda, + } = func; + + RcDoc::text(name.to_string()) + .append(if !params.is_empty() { + RcDoc::text("(") + .append(inline_comma( + params + .into_iter() + .map(|literal| RcDoc::text(literal.to_string())), + )) + .append(")") + } else { + RcDoc::nil() + }) + .append(RcDoc::text("(")) + .append(if distinct { + RcDoc::text("DISTINCT").append(RcDoc::space()) + } else { + RcDoc::nil() + }) + .append(inline_comma(args.into_iter().map(pretty_expr))) + .append(if let Some(lambda) = lambda { + if lambda.params.len() == 1 { + RcDoc::text(lambda.params[0].to_string()) + } else { + RcDoc::text("(") + .append(inline_comma( + lambda + .params + .iter() + .map(|param| RcDoc::text(param.to_string())), + )) + .append(RcDoc::text(")")) + } + .append(RcDoc::text(" -> ")) + .append(pretty_expr(*lambda.expr)) + } else { + RcDoc::nil() + }) + .append(RcDoc::text(")")) + .append(if let Some(window) = window { + RcDoc::text(" OVER (") + .append(RcDoc::text(window.to_string())) + .append(")") + } else { + RcDoc::nil() + }) + } Expr::Case { operand, conditions, diff --git a/src/query/ast/src/ast/format/syntax/query.rs b/src/query/ast/src/ast/format/syntax/query.rs index 9be982e60aad6..69a2df99c248f 100644 --- a/src/query/ast/src/ast/format/syntax/query.rs +++ b/src/query/ast/src/ast/format/syntax/query.rs @@ -402,7 +402,7 @@ pub(crate) fn pretty_table(table: TableReference) -> RcDoc<'static> { .append(inline_comma(params.into_iter().map(pretty_expr))) .append(separator) .append(inline_comma(named_params.into_iter().map(|(k, v)| { - RcDoc::text(k) + RcDoc::text(k.to_string()) .append(RcDoc::text("=>")) .append(pretty_expr(v)) }))) diff --git a/src/query/ast/src/ast/query.rs b/src/query/ast/src/ast/query.rs index 0e28c3ea9ea7b..9821c5ab5a944 100644 --- a/src/query/ast/src/ast/query.rs +++ b/src/query/ast/src/ast/query.rs @@ -16,6 +16,8 @@ use std::fmt::Display; use std::fmt::Formatter; use databend_common_exception::Span; +use derive_visitor::Drive; +use derive_visitor::DriveMut; use super::Lambda; use crate::ast::write_comma_separated_list; @@ -28,8 +30,9 @@ use crate::ast::SelectStageOptions; use crate::ast::WindowDefinition; /// Root node of a query tree -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct Query { + #[drive(skip)] pub span: Span, // With clause, common table expression pub with: Option, @@ -45,38 +48,47 @@ pub struct Query { pub offset: Option, // If ignore the result (not output). + #[drive(skip)] pub ignore_result: bool, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct With { + #[drive(skip)] pub span: Span, + #[drive(skip)] pub recursive: bool, pub ctes: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct CTE { + #[drive(skip)] pub span: Span, pub alias: TableAlias, + #[drive(skip)] pub materialized: bool, pub query: Box, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct SetOperation { + #[drive(skip)] pub span: Span, pub op: SetOperator, + #[drive(skip)] pub all: bool, pub left: Box, pub right: Box, } /// A subquery represented with `SELECT` statement -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct SelectStmt { + #[drive(skip)] pub span: Span, pub hints: Option, + #[drive(skip)] pub distinct: bool, // Result set of current subquery pub select_list: Vec, @@ -97,7 +109,7 @@ pub struct SelectStmt { } /// Group by Clause. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum GroupBy { /// GROUP BY expr [, expr]* Normal(Vec), @@ -114,17 +126,21 @@ pub enum GroupBy { } /// A relational set expression, like `SELECT ... FROM ... {UNION|EXCEPT|INTERSECT} SELECT ... FROM ...` -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum SetExpr { Select(Box), Query(Box), // UNION/EXCEPT/INTERSECT operator SetOperation(Box), // Values clause - Values { span: Span, values: Vec> }, + Values { + #[drive(skip)] + span: Span, + values: Vec>, + }, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum SetOperator { Union, Except, @@ -132,17 +148,19 @@ pub enum SetOperator { } /// `ORDER BY` clause -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct OrderByExpr { pub expr: Expr, // Optional `ASC` or `DESC` + #[drive(skip)] pub asc: Option, // Optional `NULLS FIRST` or `NULLS LAST` + #[drive(skip)] pub nulls_first: Option, } /// One item of the comma-separated list following `SELECT` -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum SelectTarget { // Expression with alias, e.g. `SELECT t.a, b AS a, a+1 AS b FROM t` AliasedExpr { @@ -160,30 +178,6 @@ pub enum SelectTarget { }, } -#[derive(Debug, Clone, PartialEq)] -pub enum ColumnFilter { - Excludes(Vec), - Lambda(Lambda), -} - -impl ColumnFilter { - pub fn get_excludes(&self) -> Option<&[Identifier]> { - if let ColumnFilter::Excludes(ex) = self { - Some(ex) - } else { - None - } - } - - pub fn get_lambda(&self) -> Option<&Lambda> { - if let ColumnFilter::Lambda(l) = self { - Some(l) - } else { - None - } - } -} - impl SelectTarget { pub fn is_star(&self) -> bool { match self { @@ -206,7 +200,7 @@ impl SelectTarget { pub fn has_window(&self) -> bool { match self { SelectTarget::AliasedExpr { box expr, .. } => match expr { - Expr::FunctionCall { window, .. } => window.is_some(), + Expr::FunctionCall { func, .. } => func.window.is_some(), _ => false, }, SelectTarget::StarColumns { .. } => false, @@ -216,8 +210,8 @@ impl SelectTarget { pub fn function_call_name(&self) -> Option { match self { SelectTarget::AliasedExpr { box expr, .. } => match expr { - Expr::FunctionCall { name, window, .. } if window.is_none() => { - Some(name.name.to_lowercase()) + Expr::FunctionCall { func, .. } if func.window.is_none() => { + Some(func.name.name.to_lowercase()) } _ => None, }, @@ -226,33 +220,57 @@ impl SelectTarget { } } +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] +pub enum ColumnFilter { + Excludes(Vec), + Lambda(Lambda), +} + +impl ColumnFilter { + pub fn get_excludes(&self) -> Option<&[Identifier]> { + if let ColumnFilter::Excludes(ex) = self { + Some(ex) + } else { + None + } + } + + pub fn get_lambda(&self) -> Option<&Lambda> { + if let ColumnFilter::Lambda(l) = self { + Some(l) + } else { + None + } + } +} + pub type QualifiedName = Vec; /// Indirection of a select result, like a part of `db.table.column`. /// Can be a database name, table name, field name or wildcard star(`*`). -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum Indirection { // Field name Identifier(Identifier), // Wildcard star - Star(Span), + Star(#[drive(skip)] Span), } /// Time Travel specification -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum TimeTravelPoint { - Snapshot(String), + Snapshot(#[drive(skip)] String), Timestamp(Box), } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct Pivot { pub aggregate: Expr, pub value_column: Identifier, pub values: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct Unpivot { pub value_column: Identifier, pub column_name: Identifier, @@ -260,10 +278,11 @@ pub struct Unpivot { } /// A table name or a parenthesized subquery with an optional alias -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum TableReference { // Table name Table { + #[drive(skip)] span: Span, catalog: Option, database: Option, @@ -276,27 +295,33 @@ pub enum TableReference { }, // `TABLE(expr)[ AS alias ]` TableFunction { + #[drive(skip)] span: Span, /// Whether the table function is a lateral table function + #[drive(skip)] lateral: bool, name: Identifier, params: Vec, - named_params: Vec<(String, Expr)>, + named_params: Vec<(Identifier, Expr)>, alias: Option, }, // Derived table, which can be a subquery or joined tables or combination of them Subquery { + #[drive(skip)] span: Span, /// Whether the subquery is a lateral subquery + #[drive(skip)] lateral: bool, subquery: Box, alias: Option, }, Join { + #[drive(skip)] span: Span, join: Join, }, Location { + #[drive(skip)] span: Span, location: FileLocation, options: SelectStageOptions, @@ -327,13 +352,13 @@ impl TableReference { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub struct TableAlias { pub name: Identifier, pub columns: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct Join { pub op: JoinOperator, pub condition: JoinCondition, @@ -341,7 +366,7 @@ pub struct Join { pub right: Box, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum JoinOperator { Inner, // Outer joins can not work with `JoinCondition::None` @@ -356,7 +381,7 @@ pub enum JoinOperator { CrossJoin, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum JoinCondition { On(Box), Using(Vec), diff --git a/src/query/ast/src/ast/statements/copy.rs b/src/query/ast/src/ast/statements/copy.rs index feebf2a3e5472..392dbb448b36a 100644 --- a/src/query/ast/src/ast/statements/copy.rs +++ b/src/query/ast/src/ast/statements/copy.rs @@ -26,6 +26,8 @@ use databend_common_exception::ErrorCode; use databend_common_meta_app::principal::CopyOptions; use databend_common_meta_app::principal::OnErrorMode; use databend_common_meta_app::principal::COPY_MAX_FILES_PER_COMMIT; +use derive_visitor::Drive; +use derive_visitor::DriveMut; use itertools::Itertools; use url::Url; @@ -43,7 +45,7 @@ use crate::ast::TableRef; /// ```sql /// COPY INTO table from s3://bucket/path/to/x.csv /// ``` -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct CopyIntoTableStmt { pub src: CopyIntoTableSource, pub dst: TableRef, @@ -51,22 +53,34 @@ pub struct CopyIntoTableStmt { pub hints: Option, + #[drive(skip)] pub file_format: BTreeMap, // files to load + #[drive(skip)] pub files: Option>, + #[drive(skip)] pub pattern: Option, + #[drive(skip)] pub force: bool, // copy options /// TODO(xuanwo): parse into validation_mode directly. + #[drive(skip)] pub validation_mode: String, + #[drive(skip)] pub size_limit: usize, + #[drive(skip)] pub max_files: usize, + #[drive(skip)] pub split_size: usize, + #[drive(skip)] pub purge: bool, + #[drive(skip)] pub disable_variant_check: bool, + #[drive(skip)] pub return_failed_only: bool, + #[drive(skip)] pub on_error: String, } @@ -173,14 +187,18 @@ impl Display for CopyIntoTableStmt { } /// CopyIntoLocationStmt is the parsed statement of `COPY into from ...` -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct CopyIntoLocationStmt { pub hints: Option, pub src: CopyIntoLocationSource, pub dst: FileLocation, + #[drive(skip)] pub file_format: BTreeMap, + #[drive(skip)] pub single: bool, + #[drive(skip)] pub max_file_size: usize, + #[drive(skip)] pub detailed_output: bool, } @@ -217,7 +235,7 @@ impl CopyIntoLocationStmt { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum CopyIntoTableSource { Location(FileLocation), /// Load with Transform @@ -236,7 +254,7 @@ impl Display for CopyIntoTableSource { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub enum CopyIntoLocationSource { Query(Box), /// it will be rewrite as `(SELECT * FROM table)` @@ -256,9 +274,11 @@ impl Display for CopyIntoLocationSource { } } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub struct Connection { + #[drive(skip)] visited_keys: HashSet, + #[drive(skip)] pub conns: BTreeMap, } @@ -325,11 +345,15 @@ impl Display for Connection { /// UriLocation (a.k.a external location) can be used in `INTO` or `FROM`. /// /// For examples: `'s3://example/path/to/dir' CONNECTION = (AWS_ACCESS_ID="admin" AWS_SECRET_KEY="admin")` -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub struct UriLocation { + #[drive(skip)] pub protocol: String, + #[drive(skip)] pub name: String, + #[drive(skip)] pub path: String, + #[drive(skip)] pub part_prefix: String, pub connection: Connection, } @@ -427,9 +451,9 @@ impl Display for UriLocation { /// UriLocation (a.k.a external location) can be used in `INTO` or `FROM`. /// /// For examples: `'s3://example/path/to/dir' CONNECTION = (AWS_ACCESS_ID="admin" AWS_SECRET_KEY="admin")` -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub enum FileLocation { - Stage(String), + Stage(#[drive(skip)] String), Uri(UriLocation), } diff --git a/src/query/ast/src/ast/statements/database.rs b/src/query/ast/src/ast/statements/database.rs index b979ac04ee33d..b70eb271c4aec 100644 --- a/src/query/ast/src/ast/statements/database.rs +++ b/src/query/ast/src/ast/statements/database.rs @@ -20,6 +20,7 @@ use databend_common_meta_app::share::ShareNameIdent; use crate::ast::statements::show::ShowLimit; use crate::ast::write_dot_separated_list; +use crate::ast::DatabaseRef; use crate::ast::Identifier; #[derive(Debug, Clone, PartialEq)] // Databases @@ -65,8 +66,7 @@ impl Display for ShowCreateDatabaseStmt { #[derive(Debug, Clone, PartialEq, Eq)] pub struct CreateDatabaseStmt { pub create_option: CreateOption, - pub catalog: Option, - pub database: Identifier, + pub database: DatabaseRef, pub engine: Option, pub options: Vec, pub from_share: Option, @@ -83,7 +83,7 @@ impl Display for CreateDatabaseStmt { write!(f, " IF NOT EXISTS ")?; } - write_dot_separated_list(f, self.catalog.iter().chain(Some(&self.database)))?; + write!(f, "{}", self.database)?; if let Some(engine) = &self.engine { write!(f, " ENGINE = {engine}")?; diff --git a/src/query/ast/src/ast/statements/hint.rs b/src/query/ast/src/ast/statements/hint.rs index 6c92efd37b30c..3ed2e6d4fd913 100644 --- a/src/query/ast/src/ast/statements/hint.rs +++ b/src/query/ast/src/ast/statements/hint.rs @@ -15,15 +15,18 @@ use std::fmt::Display; use std::fmt::Formatter; +use derive_visitor::Drive; +use derive_visitor::DriveMut; + use crate::ast::Expr; use crate::ast::Identifier; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct Hint { pub hints_list: Vec, } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] pub struct HintItem { pub name: Identifier, pub expr: Expr, diff --git a/src/query/ast/src/ast/statements/stage.rs b/src/query/ast/src/ast/statements/stage.rs index 0f2bf15be32a6..ec492ba516774 100644 --- a/src/query/ast/src/ast/statements/stage.rs +++ b/src/query/ast/src/ast/statements/stage.rs @@ -18,25 +18,78 @@ use std::fmt::Display; use std::fmt::Formatter; use databend_common_meta_app::schema::CreateOption; +use derive_visitor::Drive; +use derive_visitor::DriveMut; use crate::ast::write_comma_separated_map; use crate::ast::write_comma_separated_quoted_list; use crate::ast::UriLocation; -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)] pub struct CreateStageStmt { + #[drive(skip)] pub create_option: CreateOption, + #[drive(skip)] pub stage_name: String, pub location: Option, + #[drive(skip)] pub file_format_options: BTreeMap, + #[drive(skip)] pub on_error: String, + #[drive(skip)] pub size_limit: usize, + #[drive(skip)] pub validation_mode: String, + #[drive(skip)] pub comments: String, } +#[derive(Debug, Clone, PartialEq, Drive, DriveMut)] +pub enum SelectStageOption { + Files(#[drive(skip)] Vec), + Pattern(#[drive(skip)] String), + FileFormat(#[drive(skip)] String), + Connection(#[drive(skip)] BTreeMap), +} + +impl SelectStageOptions { + pub fn from(opts: Vec) -> Self { + let mut options: SelectStageOptions = Default::default(); + for opt in opts.into_iter() { + match opt { + SelectStageOption::Files(v) => options.files = Some(v), + SelectStageOption::Pattern(v) => options.pattern = Some(v), + SelectStageOption::FileFormat(v) => options.file_format = Some(v), + SelectStageOption::Connection(v) => options.connection = v, + } + } + options + } +} + +#[derive(Debug, Clone, PartialEq, Default, Drive, DriveMut)] +pub struct SelectStageOptions { + #[drive(skip)] + pub files: Option>, + #[drive(skip)] + pub pattern: Option, + #[drive(skip)] + pub file_format: Option, + #[drive(skip)] + pub connection: BTreeMap, +} + +impl SelectStageOptions { + pub fn is_empty(&self) -> bool { + self.files.is_none() + && self.pattern.is_none() + && self.file_format.is_none() + && self.connection.is_empty() + } +} + impl Display for CreateStageStmt { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "CREATE")?; @@ -79,31 +132,6 @@ impl Display for CreateStageStmt { } } -#[derive(Debug, Clone, PartialEq)] -pub enum SelectStageOption { - Files(Vec), - Pattern(String), - FileFormat(String), - Connection(BTreeMap), -} - -#[derive(Debug, Clone, PartialEq, Default)] -pub struct SelectStageOptions { - pub files: Option>, - pub pattern: Option, - pub file_format: Option, - pub connection: BTreeMap, -} - -impl SelectStageOptions { - pub fn is_empty(&self) -> bool { - self.files.is_none() - && self.pattern.is_none() - && self.file_format.is_none() - && self.connection.is_empty() - } -} - // SELECT FROM // {@[/] | ''} [( // [ PATTERN => ''] @@ -148,18 +176,3 @@ impl Display for SelectStageOptions { Ok(()) } } - -impl SelectStageOptions { - pub fn from(opts: Vec) -> Self { - let mut options: SelectStageOptions = Default::default(); - for opt in opts.into_iter() { - match opt { - SelectStageOption::Files(v) => options.files = Some(v), - SelectStageOption::Pattern(v) => options.pattern = Some(v), - SelectStageOption::FileFormat(v) => options.file_format = Some(v), - SelectStageOption::Connection(v) => options.connection = v, - } - } - options - } -} diff --git a/src/query/ast/src/ast/visitors/walk.rs b/src/query/ast/src/ast/visitors/walk.rs index 90be8bd8f7713..00c0f5293b255 100644 --- a/src/query/ast/src/ast/visitors/walk.rs +++ b/src/query/ast/src/ast/visitors/walk.rs @@ -19,9 +19,12 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expr: &'a Expr) { match expr { Expr::ColumnRef { span, - database, - table, - column, + column: + ColumnRef { + database, + table, + column, + }, } => visitor.visit_column_ref(*span, database, table, column), Expr::IsNull { span, expr, not } => visitor.visit_is_null(*span, expr, *not), Expr::IsDistinctFrom { @@ -96,12 +99,15 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expr: &'a Expr) { Expr::Tuple { span, exprs } => visitor.visit_tuple(*span, exprs), Expr::FunctionCall { span, - distinct, - name, - args, - params, - window, - lambda, + func: + FunctionCall { + distinct, + name, + args, + params, + window, + lambda, + }, } => visitor.visit_function_call(*span, *distinct, name, args, params, window, lambda), Expr::Case { span, diff --git a/src/query/ast/src/ast/visitors/walk_mut.rs b/src/query/ast/src/ast/visitors/walk_mut.rs index a3b2f2e09a1c7..28f7edfe3491f 100644 --- a/src/query/ast/src/ast/visitors/walk_mut.rs +++ b/src/query/ast/src/ast/visitors/walk_mut.rs @@ -19,9 +19,12 @@ pub fn walk_expr_mut(visitor: &mut V, expr: &mut Expr) { match expr { Expr::ColumnRef { span, - database, - table, - column, + column: + ColumnRef { + database, + table, + column, + }, } => visitor.visit_column_ref(*span, database, table, column), Expr::IsNull { span, expr, not } => visitor.visit_is_null(*span, expr, *not), Expr::IsDistinctFrom { @@ -96,12 +99,15 @@ pub fn walk_expr_mut(visitor: &mut V, expr: &mut Expr) { Expr::Tuple { span, exprs } => visitor.visit_tuple(*span, exprs), Expr::FunctionCall { span, - distinct, - name, - args, - params, - window, - lambda, + func: + FunctionCall { + distinct, + name, + args, + params, + window, + lambda, + }, } => visitor.visit_function_call(*span, *distinct, name, args, params, window, lambda), Expr::Case { span, diff --git a/src/query/ast/src/parser/common.rs b/src/query/ast/src/parser/common.rs index 04f4a69643492..57e5df7051d15 100644 --- a/src/query/ast/src/parser/common.rs +++ b/src/query/ast/src/parser/common.rs @@ -23,6 +23,7 @@ use pratt::PrattParser; use pratt::Precedence; use crate::ast::ColumnID; +use crate::ast::DatabaseRef; use crate::ast::Identifier; use crate::ast::TableRef; use crate::parser::input::Input; @@ -172,6 +173,12 @@ fn non_reserved_keyword( } } +pub fn database_ref(i: Input) -> IResult { + map(dot_separated_idents_1_to_2, |(catalog, database)| { + DatabaseRef { catalog, database } + })(i) +} + pub fn table_ref(i: Input) -> IResult { map(dot_separated_idents_1_to_3, |(catalog, database, table)| { TableRef { diff --git a/src/query/ast/src/parser/expr.rs b/src/query/ast/src/parser/expr.rs index d97fed7df101a..2a54cdc647d9f 100644 --- a/src/query/ast/src/parser/expr.rs +++ b/src/query/ast/src/parser/expr.rs @@ -160,9 +160,7 @@ pub fn subexpr(min_precedence: u32) -> impl FnMut(Input) -> IResult { pub enum ExprElement { /// Column reference, with indirection like `table.column` ColumnRef { - database: Option, - table: Option, - column: ColumnID, + column: ColumnRef, }, /// `.a.b` after column ref, currently it'll be taken as column reference DotAccess { @@ -261,13 +259,7 @@ pub enum ExprElement { }, /// Scalar function call FunctionCall { - /// Set to true if the function is aggregate function with `DISTINCT`, like `COUNT(DISTINCT a)` - distinct: bool, - name: Identifier, - args: Vec, - params: Vec, - window: Option, - lambda: Option, + func: FunctionCall, }, /// `CASE ... WHEN ... ELSE ...` expression Case { @@ -416,14 +408,8 @@ impl<'a, I: Iterator>> PrattParser for ExprP fn primary(&mut self, elem: WithSpan<'a, ExprElement>) -> Result { let expr = match elem.elem { - ExprElement::ColumnRef { - database, - table, - column, - } => Expr::ColumnRef { + ExprElement::ColumnRef { column } => Expr::ColumnRef { span: transform_span(elem.span.0), - database, - table, column, }, ExprElement::Cast { expr, target_type } => Expr::Cast { @@ -482,21 +468,9 @@ impl<'a, I: Iterator>> PrattParser for ExprP span: transform_span(elem.span.0), exprs, }, - ExprElement::FunctionCall { - distinct, - name, - args, - params, - window, - lambda, - } => Expr::FunctionCall { + ExprElement::FunctionCall { func } => Expr::FunctionCall { span: transform_span(elem.span.0), - distinct, - name, - args, - params, - window, - lambda, + func, }, ExprElement::Case { operand, @@ -538,29 +512,33 @@ impl<'a, I: Iterator>> PrattParser for ExprP if let Some(filter) = filter { source = Expr::FunctionCall { span, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("array_filter"), + args: vec![source], + params: vec![], + window: None, + lambda: Some(Lambda { + params: vec![param.clone()], + expr: Box::new(filter), + }), + }, + }; + } + // array_map(source, result) + Expr::FunctionCall { + span, + func: FunctionCall { distinct: false, - name: Identifier::from_name("array_filter"), + name: Identifier::from_name("array_map"), args: vec![source], params: vec![], window: None, lambda: Some(Lambda { params: vec![param.clone()], - expr: Box::new(filter), + expr: Box::new(result), }), - }; - } - // array_map(source, result) - Expr::FunctionCall { - span, - distinct: false, - name: Identifier::from_name("array_map"), - args: vec![source], - params: vec![], - window: None, - lambda: Some(Lambda { - params: vec![param.clone()], - expr: Box::new(result), - }), + }, } } ExprElement::Map { kvs } => Expr::Map { @@ -658,18 +636,12 @@ impl<'a, I: Iterator>> PrattParser for ExprP // Lift level up the identifier ExprElement::DotAccess { key } => { let mut is_map_access = true; - if let Expr::ColumnRef { - database, - table, - column, - .. - } = &mut lhs - { - if let ColumnID::Name(name) = column { + if let Expr::ColumnRef { column, .. } = &mut lhs { + if let ColumnID::Name(name) = &column.column { is_map_access = false; - *database = table.take(); - *table = Some(name.clone()); - *column = key.clone(); + column.database = column.table.take(); + column.table = Some(name.clone()); + column.column = key.clone(); } } @@ -690,12 +662,14 @@ impl<'a, I: Iterator>> PrattParser for ExprP } ExprElement::ChainFunctionCall { name, args, lambda } => Expr::FunctionCall { span: transform_span(elem.span.0), - distinct: false, - name, - args: [vec![lhs], args].concat(), - params: vec![], - window: None, - lambda, + func: FunctionCall { + distinct: false, + name, + args: [vec![lhs], args].concat(), + params: vec![], + window: None, + lambda, + }, }, ExprElement::IsNull { not } => Expr::IsNull { span: transform_span(elem.span.0), @@ -740,11 +714,12 @@ impl<'a, I: Iterator>> PrattParser for ExprP pub fn expr_element(i: Input) -> IResult> { let column_ref = map(column_id, |column| ExprElement::ColumnRef { - database: None, - table: None, - column, + column: ColumnRef { + database: None, + table: None, + column, + }, }); - let is_null = map( rule! { IS ~ NOT? ~ NULL @@ -918,12 +893,14 @@ pub fn expr_element(i: Input) -> IResult> { ~ "(" ~ DISTINCT? ~ #comma_separated_list0(subexpr(0))? ~ ")" }, |(name, _, opt_distinct, opt_args, _)| ExprElement::FunctionCall { - distinct: opt_distinct.is_some(), - name, - args: opt_args.unwrap_or_default(), - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: opt_distinct.is_some(), + name, + args: opt_args.unwrap_or_default(), + params: vec![], + window: None, + lambda: None, + }, }, ); let function_call_with_lambda = map( @@ -932,15 +909,17 @@ pub fn expr_element(i: Input) -> IResult> { ~ "(" ~ #subexpr(0) ~ "," ~ #lambda_params ~ "->" ~ #subexpr(0) ~ ")" }, |(name, _, arg, _, params, _, expr, _)| ExprElement::FunctionCall { - distinct: false, - name, - args: vec![arg], - params: vec![], - window: None, - lambda: Some(Lambda { - params, - expr: Box::new(expr), - }), + func: FunctionCall { + distinct: false, + name, + args: vec![arg], + params: vec![], + window: None, + lambda: Some(Lambda { + params, + expr: Box::new(expr), + }), + }, }, ); let function_call_with_window = map( @@ -950,12 +929,14 @@ pub fn expr_element(i: Input) -> IResult> { ~ (OVER ~ #window_spec_ident) }, |(name, _, opt_distinct, opt_args, _, window)| ExprElement::FunctionCall { - distinct: opt_distinct.is_some(), - name, - args: opt_args.unwrap_or_default(), - params: vec![], - window: Some(window.1), - lambda: None, + func: FunctionCall { + distinct: opt_distinct.is_some(), + name, + args: opt_args.unwrap_or_default(), + params: vec![], + window: Some(window.1), + lambda: None, + }, }, ); let function_call_with_params = map( @@ -965,12 +946,14 @@ pub fn expr_element(i: Input) -> IResult> { ~ "(" ~ DISTINCT? ~ #comma_separated_list0(subexpr(0))? ~ ")" }, |(name, params, _, opt_distinct, opt_args, _)| ExprElement::FunctionCall { - distinct: opt_distinct.is_some(), - name, - args: opt_args.unwrap_or_default(), - params: params.map(|(_, x, _)| x).unwrap_or_default(), - window: None, - lambda: None, + func: FunctionCall { + distinct: opt_distinct.is_some(), + name, + args: opt_args.unwrap_or_default(), + params: params.map(|(_, x, _)| x).unwrap_or_default(), + window: None, + lambda: None, + }, }, ); @@ -1175,12 +1158,14 @@ pub fn expr_element(i: Input) -> IResult> { let current_timestamp = value( ExprElement::FunctionCall { - distinct: false, - name: Identifier::from_name("current_timestamp"), - args: vec![], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("current_timestamp"), + args: vec![], + params: vec![], + window: None, + lambda: None, + }, }, rule! { CURRENT_TIMESTAMP }, ); @@ -1236,23 +1221,6 @@ pub fn expr_element(i: Input) -> IResult> { Ok((rest, WithSpan { span, elem })) } -/// Parse one to three idents separated by a dot, fulfilling from the right. -/// -/// Example: `db.table.column` -pub fn column_ref(i: Input) -> IResult<(Option, Option, ColumnID)> { - alt(( - map( - rule! { #ident ~ "." ~ #ident ~ "." ~ #column_id }, - |(ident1, _, ident2, _, ident3)| (Some(ident1), Some(ident2), ident3), - ), - map( - rule! { #ident ~ "." ~ #column_id }, - |(ident2, _, ident3)| (None, Some(ident2), ident3), - ), - map(rule! { #column_id }, |ident3| (None, None, ident3)), - ))(i) -} - pub fn unary_op(i: Input) -> IResult { // Plus and Minus are parsed as binary op at first. alt(( diff --git a/src/query/ast/src/parser/query.rs b/src/query/ast/src/parser/query.rs index cf5fbcb314483..b0866d56cfade 100644 --- a/src/query/ast/src/parser/query.rs +++ b/src/query/ast/src/parser/query.rs @@ -452,9 +452,11 @@ pub fn select_target(i: Input) -> IResult { op: BinaryOperator::Regexp, left: Box::new(Expr::ColumnRef { span: None, - database: None, - table: None, - column: ColumnID::Name(Identifier::from_name("_t")), + column: ColumnRef { + database: None, + table: None, + column: ColumnID::Name(Identifier::from_name("_t")), + }, }), right: Box::new(Expr::Literal { span: Some(t.span), @@ -600,17 +602,14 @@ pub fn table_reference(i: Input) -> IResult { #[derive(Debug, Clone, PartialEq)] pub enum TableFunctionParam { // func(name => arg) - Named { name: String, value: Expr }, + Named { name: Identifier, value: Expr }, // func(arg) Normal(Expr), } pub fn table_function_param(i: Input) -> IResult { let named = map(rule! { #ident ~ "=>" ~ #expr }, |(name, _, value)| { - TableFunctionParam::Named { - name: name.to_string(), - value, - } + TableFunctionParam::Named { name, value } }); let normal = map(rule! { #expr }, TableFunctionParam::Normal); diff --git a/src/query/ast/src/parser/statement.rs b/src/query/ast/src/parser/statement.rs index 8e27d9e9082eb..469eb98d16b1f 100644 --- a/src/query/ast/src/parser/statement.rs +++ b/src/query/ast/src/parser/statement.rs @@ -108,7 +108,7 @@ pub fn statement(i: Input) -> IResult { let create_task = map( rule! { - CREATE ~ TASK ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ TASK ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ #task_warehouse_option ~ (SCHEDULE ~ "=" ~ #task_schedule_option)? @@ -460,7 +460,7 @@ pub fn statement(i: Input) -> IResult { // TODO: use a more specific option struct instead of BTreeMap let create_catalog = map( rule! { - CREATE ~ CATALOG ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ CATALOG ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ TYPE ~ "=" ~ #catalog_type ~ CONNECTION ~ "=" ~ #connection_options @@ -509,9 +509,14 @@ pub fn statement(i: Input) -> IResult { let create_database = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ ( DATABASE | SCHEMA ) ~ (IF ~ ^NOT ~ ^EXISTS)? ~ #dot_separated_idents_1_to_2 ~ #create_database_option? + CREATE + ~ ( OR ~ ^REPLACE )? + ~ ( DATABASE | SCHEMA ) + ~ ( IF ~ ^NOT ~ ^EXISTS )? + ~ #database_ref + ~ #create_database_option? }, - |(_, opt_or_replace, _, opt_if_not_exists, (catalog, database), create_database_option)| { + |(_, opt_or_replace, _, opt_if_not_exists, database, create_database_option)| { let create_option = parse_create_option(opt_or_replace.is_some(), opt_if_not_exists.is_some())?; @@ -519,7 +524,6 @@ pub fn statement(i: Input) -> IResult { Some(CreateDatabaseOption::DatabaseEngine(engine)) => { Statement::CreateDatabase(CreateDatabaseStmt { create_option, - catalog, database, engine: Some(engine), options: vec![], @@ -529,7 +533,6 @@ pub fn statement(i: Input) -> IResult { Some(CreateDatabaseOption::FromShare(share_name)) => { Statement::CreateDatabase(CreateDatabaseStmt { create_option, - catalog, database, engine: None, options: vec![], @@ -538,7 +541,6 @@ pub fn statement(i: Input) -> IResult { } None => Statement::CreateDatabase(CreateDatabaseStmt { create_option, - catalog, database, engine: None, options: vec![], @@ -612,7 +614,11 @@ pub fn statement(i: Input) -> IResult { ); let show_columns = map( rule! { - SHOW ~ FULL? ~ COLUMNS ~ ( FROM | IN ) ~ #ident ~ (( FROM | IN ) ~ ^#dot_separated_idents_1_to_2)? ~ #show_limit? + SHOW + ~ FULL? ~ COLUMNS + ~ ( FROM | IN ) ~ #ident + ~ (( FROM | IN ) ~ ^#dot_separated_idents_1_to_2)? + ~ #show_limit? }, |(_, opt_full, _, _, table, ctl_db, limit)| { let (catalog, database) = match ctl_db { @@ -707,7 +713,7 @@ pub fn statement(i: Input) -> IResult { ); let create_table = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ TRANSIENT? ~ TABLE ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ ( OR ~ ^REPLACE )? ~ TRANSIENT? ~ TABLE ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #dot_separated_idents_1_to_3 ~ #create_table_source? ~ ( #engine )? @@ -903,7 +909,7 @@ pub fn statement(i: Input) -> IResult { let create_view = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ VIEW ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ ( OR ~ ^REPLACE )? ~ VIEW ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #dot_separated_idents_1_to_3 ~ ( "(" ~ #comma_separated_list1(ident) ~ ")" )? ~ AS ~ #query @@ -967,7 +973,11 @@ pub fn statement(i: Input) -> IResult { let create_index = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ ASYNC? ~ AGGREGATING ~ INDEX ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE + ~ ( OR ~ ^REPLACE )? + ~ ASYNC? + ~ AGGREGATING ~ INDEX + ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ AS ~ #query }, @@ -1010,7 +1020,12 @@ pub fn statement(i: Input) -> IResult { let create_virtual_column = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ VIRTUAL ~ COLUMN ~ (IF ~ ^NOT ~ ^EXISTS)? ~ ^"(" ~ ^#comma_separated_list1(expr) ~ ^")" ~ FOR ~ #dot_separated_idents_1_to_3 + CREATE + ~ ( OR ~ ^REPLACE )? + ~ VIRTUAL ~ COLUMN + ~ ( IF ~ ^NOT ~ ^EXISTS )? + ~ ^"(" ~ ^#comma_separated_list1(expr) ~ ^")" + ~ FOR ~ #dot_separated_idents_1_to_3 }, |( _, @@ -1101,7 +1116,7 @@ pub fn statement(i: Input) -> IResult { let show_users = value(Statement::ShowUsers, rule! { SHOW ~ USERS }); let create_user = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ USER ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ ( OR ~ ^REPLACE )? ~ USER ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #user_identity ~ IDENTIFIED ~ ( WITH ~ ^#auth_type )? ~ ( BY ~ ^#literal_string )? ~ ( WITH ~ ^#comma_separated_list1(user_option))? @@ -1163,7 +1178,7 @@ pub fn statement(i: Input) -> IResult { let show_roles = value(Statement::ShowRoles, rule! { SHOW ~ ROLES }); let create_role = map( rule! { - CREATE ~ ROLE ~ (IF ~ ^NOT ~ ^EXISTS)? ~ #role_name + CREATE ~ ROLE ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #role_name }, |(_, _, opt_if_not_exists, role_name)| Statement::CreateRole { if_not_exists: opt_if_not_exists.is_some(), @@ -1234,7 +1249,7 @@ pub fn statement(i: Input) -> IResult { ); let create_udf = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ FUNCTION ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ ( OR ~ ^REPLACE )? ~ FUNCTION ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ #udf_definition ~ ( DESC ~ ^"=" ~ ^#literal_string )? }, @@ -1276,7 +1291,7 @@ pub fn statement(i: Input) -> IResult { // stages let create_stage = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ STAGE ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ ( OR ~ ^REPLACE )? ~ STAGE ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ ( #stage_name ) ~ ( (URL ~ ^"=")? ~ #uri_location )? ~ ( #file_format_clause )? @@ -1358,7 +1373,7 @@ pub fn statement(i: Input) -> IResult { let connection_opt = connection_opt("="); let create_connection = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ CONNECTION ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ ( OR ~ ^REPLACE )? ~ CONNECTION ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ STORAGE_TYPE ~ "=" ~ #literal_string ~ #connection_opt* }, |( @@ -1446,7 +1461,7 @@ pub fn statement(i: Input) -> IResult { // share statements let create_share_endpoint = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ SHARE ~ ENDPOINT ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ ( OR ~ ^REPLACE )? ~ SHARE ~ ENDPOINT ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ URL ~ "=" ~ #share_endpoint_uri_location ~ TENANT ~ "=" ~ #ident @@ -1507,7 +1522,7 @@ pub fn statement(i: Input) -> IResult { ); let create_share = map( rule! { - CREATE ~ SHARE ~ (IF ~ ^NOT ~ ^EXISTS)? ~ #ident ~ ( COMMENT ~ "=" ~ #literal_string)? + CREATE ~ SHARE ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ ( COMMENT ~ "=" ~ #literal_string)? }, |(_, _, opt_if_not_exists, share, comment_opt)| { Statement::CreateShare(CreateShareStmt { @@ -1557,7 +1572,12 @@ pub fn statement(i: Input) -> IResult { ); let alter_share_tenants = map( rule! { - ALTER ~ SHARE ~ ( IF ~ ^EXISTS )? ~ #ident ~ #alter_add_share_accounts ~ TENANTS ~ Eq ~ #comma_separated_list1(ident) + ALTER + ~ SHARE + ~ ( IF ~ ^EXISTS )? + ~ #ident + ~ #alter_add_share_accounts + ~ TENANTS ~ Eq ~ #comma_separated_list1(ident) }, |(_, _, opt_if_exists, share, is_add, _, _, tenants)| { Statement::AlterShareTenants(AlterShareTenantsStmt { @@ -1583,7 +1603,7 @@ pub fn statement(i: Input) -> IResult { let create_file_format = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ FILE ~ FORMAT ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ ( OR ~ ^REPLACE )? ~ FILE ~ FORMAT ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ #format_options }, |(_, opt_or_replace, _, _, opt_if_not_exists, name, options)| { @@ -1613,7 +1633,7 @@ pub fn statement(i: Input) -> IResult { // data mark policy let create_data_mask_policy = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ MASKING ~ POLICY ~ (IF ~ ^NOT ~ ^EXISTS)? ~ #ident ~ #data_mask_policy + CREATE ~ ( OR ~ ^REPLACE )? ~ MASKING ~ POLICY ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ #data_mask_policy }, |(_, opt_or_replace, _, _, opt_if_not_exists, name, policy)| { let create_option = @@ -1651,7 +1671,7 @@ pub fn statement(i: Input) -> IResult { let create_network_policy = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ NETWORK ~ ^POLICY ~ (IF ~ ^NOT ~ ^EXISTS)? ~ ^#ident + CREATE ~ ( OR ~ ^REPLACE )? ~ NETWORK ~ ^POLICY ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ ^#ident ~ ALLOWED_IP_LIST ~ ^Eq ~ ^"(" ~ ^#comma_separated_list0(literal_string) ~ ^")" ~ ( BLOCKED_IP_LIST ~ ^Eq ~ ^"(" ~ ^#comma_separated_list0(literal_string) ~ ^")" ) ? ~ ( COMMENT ~ ^Eq ~ ^#literal_string)? @@ -1755,7 +1775,7 @@ pub fn statement(i: Input) -> IResult { let create_password_policy = map_res( rule! { - CREATE ~ (OR ~ ^REPLACE)? ~ PASSWORD ~ ^POLICY ~ (IF ~ ^NOT ~ ^EXISTS)? ~ ^#ident + CREATE ~ ( OR ~ ^REPLACE )? ~ PASSWORD ~ ^POLICY ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ ^#ident ~ #password_set_options }, |(_, opt_or_replace, _, _, opt_if_not_exists, name, set_options)| { @@ -1814,7 +1834,7 @@ pub fn statement(i: Input) -> IResult { let create_pipe = map( rule! { - CREATE ~ PIPE ~ (IF ~ ^NOT ~ ^EXISTS)? + CREATE ~ PIPE ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #ident ~ ( AUTO_INGEST ~ "=" ~ #literal_bool )? ~ ( (COMMENT | COMMENTS) ~ ^"=" ~ ^#literal_string )? diff --git a/src/query/ast/src/parser/stream.rs b/src/query/ast/src/parser/stream.rs index 657b920a56ab7..3affceb9510fa 100644 --- a/src/query/ast/src/parser/stream.rs +++ b/src/query/ast/src/parser/stream.rs @@ -44,7 +44,7 @@ pub fn stream_table(i: Input) -> IResult { fn create_stream(i: Input) -> IResult { map_res( rule! { - CREATE ~ (OR ~ REPLACE)? ~ STREAM ~ ( IF ~ ^NOT ~ ^EXISTS )? + CREATE ~ ( OR ~ ^REPLACE )? ~ STREAM ~ ( IF ~ ^NOT ~ ^EXISTS )? ~ #dot_separated_idents_1_to_3 ~ ON ~ TABLE ~ #dot_separated_idents_1_to_2 ~ ( #stream_point )? diff --git a/src/query/ast/tests/it/testdata/experimental-expr.txt b/src/query/ast/tests/it/testdata/experimental-expr.txt index f5bfd8c936ca6..209786fcae33b 100644 --- a/src/query/ast/tests/it/testdata/experimental-expr.txt +++ b/src/query/ast/tests/it/testdata/experimental-expr.txt @@ -7,17 +7,19 @@ ColumnRef { span: Some( 0..1, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..1, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..1, + ), + name: "a", + quote: None, + }, + ), + }, } @@ -30,51 +32,57 @@ FunctionCall { span: Some( 1..8, ), - distinct: false, - name: Identifier { - span: Some( - 2..5, - ), - name: "add", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 0..1, + 2..5, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..1, + name: "add", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 0..1, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..1, + ), + name: "a", + quote: None, + }, ), - name: "a", - quote: None, }, - ), - }, - ColumnRef { - span: Some( - 6..7, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 6..7, + }, + ColumnRef { + span: Some( + 6..7, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 6..7, + ), + name: "b", + quote: None, + }, ), - name: "b", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -87,85 +95,95 @@ FunctionCall { span: Some( 8..15, ), - distinct: false, - name: Identifier { - span: Some( - 9..12, - ), - name: "add", - quote: None, - }, - args: [ - FunctionCall { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 1..8, + 9..12, ), - distinct: false, - name: Identifier { + name: "add", + quote: None, + }, + args: [ + FunctionCall { span: Some( - 2..5, + 1..8, ), - name: "sub", - quote: None, - }, - args: [ - ColumnRef { - span: Some( - 0..1, - ), - database: None, - table: None, - column: Name( - Identifier { + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 2..5, + ), + name: "sub", + quote: None, + }, + args: [ + ColumnRef { span: Some( 0..1, ), - name: "a", - quote: None, + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..1, + ), + name: "a", + quote: None, + }, + ), + }, }, - ), + ColumnRef { + span: Some( + 6..7, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 6..7, + ), + name: "b", + quote: None, + }, + ), + }, + }, + ], + params: [], + window: None, + lambda: None, }, - ColumnRef { - span: Some( - 6..7, - ), + }, + ColumnRef { + span: Some( + 13..14, + ), + column: ColumnRef { database: None, table: None, column: Name( Identifier { span: Some( - 6..7, + 13..14, ), - name: "b", + name: "e", quote: None, }, ), }, - ], - params: [], - window: None, - lambda: None, - }, - ColumnRef { - span: Some( - 13..14, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 13..14, - ), - name: "e", - quote: None, - }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -178,85 +196,95 @@ FunctionCall { span: Some( 8..15, ), - distinct: false, - name: Identifier { - span: Some( - 9..12, - ), - name: "add", - quote: None, - }, - args: [ - FunctionCall { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 1..8, + 9..12, ), - distinct: false, - name: Identifier { + name: "add", + quote: None, + }, + args: [ + FunctionCall { span: Some( - 2..5, + 1..8, ), - name: "sub", - quote: None, - }, - args: [ - ColumnRef { - span: Some( - 0..1, - ), - database: None, - table: None, - column: Name( - Identifier { + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 2..5, + ), + name: "sub", + quote: None, + }, + args: [ + ColumnRef { span: Some( 0..1, ), - name: "a", - quote: None, + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..1, + ), + name: "a", + quote: None, + }, + ), + }, }, - ), + ColumnRef { + span: Some( + 6..7, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 6..7, + ), + name: "b", + quote: None, + }, + ), + }, + }, + ], + params: [], + window: None, + lambda: None, }, - ColumnRef { - span: Some( - 6..7, - ), + }, + ColumnRef { + span: Some( + 13..14, + ), + column: ColumnRef { database: None, table: None, column: Name( Identifier { span: Some( - 6..7, + 13..14, ), - name: "b", + name: "e", quote: None, }, ), }, - ], - params: [], - window: None, - lambda: None, - }, - ColumnRef { - span: Some( - 13..14, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 13..14, - ), - name: "e", - quote: None, - }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -324,35 +352,37 @@ FunctionCall { span: Some( 3..11, ), - distinct: false, - name: Identifier { - span: Some( - 4..8, - ), - name: "plus", - quote: None, - }, - args: [ - Literal { - span: Some( - 0..3, - ), - lit: String( - "3", - ), - }, - Literal { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 9..10, - ), - lit: UInt64( - 4, + 4..8, ), + name: "plus", + quote: None, }, - ], - params: [], - window: None, - lambda: None, + args: [ + Literal { + span: Some( + 0..3, + ), + lit: String( + "3", + ), + }, + Literal { + span: Some( + 9..10, + ), + lit: UInt64( + 4, + ), + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -365,61 +395,63 @@ FunctionCall { span: Some( 3..22, ), - distinct: false, - name: Identifier { - span: Some( - 4..7, - ), - name: "add", - quote: None, - }, - args: [ - Literal { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 1..2, - ), - lit: UInt64( - 3, + 4..7, ), + name: "add", + quote: None, }, - MapAccess { - span: Some( - 18..21, - ), - expr: Map { + args: [ + Literal { span: Some( - 8..18, + 1..2, + ), + lit: UInt64( + 3, ), - kvs: [ - ( - String( - "k1", - ), - Literal { - span: Some( - 15..16, - ), - lit: UInt64( - 4, - ), - }, - ), - ], }, - accessor: Colon { - key: Identifier { + MapAccess { + span: Some( + 18..21, + ), + expr: Map { span: Some( - 19..21, + 8..18, ), - name: "k1", - quote: None, + kvs: [ + ( + String( + "k1", + ), + Literal { + span: Some( + 15..16, + ), + lit: UInt64( + 4, + ), + }, + ), + ], + }, + accessor: Colon { + key: Identifier { + span: Some( + 19..21, + ), + name: "k1", + quote: None, + }, }, }, - }, - ], - params: [], - window: None, - lambda: None, + ], + params: [], + window: None, + lambda: None, + }, } @@ -432,162 +464,170 @@ FunctionCall { span: Some( 0..41, ), - distinct: false, - name: Identifier { - span: None, - name: "array_map", - quote: None, - }, - args: [ - FunctionCall { - span: Some( - 0..41, - ), - distinct: false, - name: Identifier { - span: None, - name: "array_filter", - quote: None, - }, - args: [ - Array { - span: Some( - 19..26, - ), - exprs: [ - Literal { - span: Some( - 20..21, - ), - lit: UInt64( - 1, - ), - }, - Literal { - span: Some( - 22..23, - ), - lit: UInt64( - 2, - ), - }, - Literal { - span: Some( - 24..25, - ), - lit: UInt64( - 3, - ), - }, - ], - }, - ], - params: [], - window: None, - lambda: Some( - Lambda { - params: [ - Identifier { + func: FunctionCall { + distinct: false, + name: Identifier { + span: None, + name: "array_map", + quote: None, + }, + args: [ + FunctionCall { + span: Some( + 0..41, + ), + func: FunctionCall { + distinct: false, + name: Identifier { + span: None, + name: "array_filter", + quote: None, + }, + args: [ + Array { span: Some( - 14..15, + 19..26, ), - name: "x", - quote: None, + exprs: [ + Literal { + span: Some( + 20..21, + ), + lit: UInt64( + 1, + ), + }, + Literal { + span: Some( + 22..23, + ), + lit: UInt64( + 2, + ), + }, + Literal { + span: Some( + 24..25, + ), + lit: UInt64( + 3, + ), + }, + ], }, ], - expr: BinaryOp { - span: Some( - 36..37, - ), - op: Eq, - left: BinaryOp { - span: Some( - 32..33, - ), - op: Modulo, - left: ColumnRef { + params: [], + window: None, + lambda: Some( + Lambda { + params: [ + Identifier { + span: Some( + 14..15, + ), + name: "x", + quote: None, + }, + ], + expr: BinaryOp { span: Some( - 30..31, + 36..37, ), - database: None, - table: None, - column: Name( - Identifier { + op: Eq, + left: BinaryOp { + span: Some( + 32..33, + ), + op: Modulo, + left: ColumnRef { span: Some( 30..31, ), - name: "x", - quote: None, + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 30..31, + ), + name: "x", + quote: None, + }, + ), + }, }, - ), - }, - right: Literal { - span: Some( - 34..35, - ), - lit: UInt64( - 2, - ), + right: Literal { + span: Some( + 34..35, + ), + lit: UInt64( + 2, + ), + }, + }, + right: Literal { + span: Some( + 38..39, + ), + lit: UInt64( + 0, + ), + }, }, }, - right: Literal { - span: Some( - 38..39, - ), - lit: UInt64( - 0, - ), - }, - }, - }, - ), - }, - ], - params: [], - window: None, - lambda: Some( - Lambda { - params: [ - Identifier { - span: Some( - 14..15, ), - name: "x", - quote: None, }, - ], - expr: BinaryOp { - span: Some( - 4..5, - ), - op: Multiply, - left: ColumnRef { + }, + ], + params: [], + window: None, + lambda: Some( + Lambda { + params: [ + Identifier { + span: Some( + 14..15, + ), + name: "x", + quote: None, + }, + ], + expr: BinaryOp { span: Some( - 2..3, + 4..5, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 2..3, + op: Multiply, + left: ColumnRef { + span: Some( + 2..3, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 2..3, + ), + name: "x", + quote: None, + }, ), - name: "x", - quote: None, }, - ), - }, - right: Literal { - span: Some( - 6..9, - ), - lit: UInt64( - 100, - ), + }, + right: Literal { + span: Some( + 6..9, + ), + lit: UInt64( + 100, + ), + }, }, }, - }, - ), + ), + }, } diff --git a/src/query/ast/tests/it/testdata/expr.txt b/src/query/ast/tests/it/testdata/expr.txt index 271b6e6b2edc0..006c8f6214015 100644 --- a/src/query/ast/tests/it/testdata/expr.txt +++ b/src/query/ast/tests/it/testdata/expr.txt @@ -7,17 +7,19 @@ ColumnRef { span: Some( 0..1, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..1, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..1, + ), + name: "a", + quote: None, + }, + ), + }, } @@ -60,43 +62,45 @@ FunctionCall { span: Some( 0..22, ), - distinct: false, - name: Identifier { - span: Some( - 0..4, - ), - name: "char", - quote: None, - }, - args: [ - Literal { - span: Some( - 5..9, - ), - lit: UInt64( - 208, - ), - }, - Literal { - span: Some( - 11..15, - ), - lit: UInt64( - 191, - ), - }, - Literal { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 17..21, - ), - lit: UInt64( - 209, + 0..4, ), + name: "char", + quote: None, }, - ], - params: [], - window: None, - lambda: None, + args: [ + Literal { + span: Some( + 5..9, + ), + lit: UInt64( + 208, + ), + }, + Literal { + span: Some( + 11..15, + ), + lit: UInt64( + 191, + ), + }, + Literal { + span: Some( + 17..21, + ), + lit: UInt64( + 209, + ), + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -757,41 +761,43 @@ FunctionCall { span: Some( 0..13, ), - distinct: false, - name: Identifier { - span: Some( - 0..6, - ), - name: "typeof", - quote: None, - }, - args: [ - BinaryOp { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 9..10, + 0..6, ), - op: Plus, - left: Literal { - span: Some( - 7..8, - ), - lit: UInt64( - 1, - ), - }, - right: Literal { + name: "typeof", + quote: None, + }, + args: [ + BinaryOp { span: Some( - 11..12, - ), - lit: UInt64( - 2, + 9..10, ), + op: Plus, + left: Literal { + span: Some( + 7..8, + ), + lit: UInt64( + 1, + ), + }, + right: Literal { + span: Some( + 11..12, + ), + lit: UInt64( + 2, + ), + }, }, - }, - ], - params: [], - window: None, - lambda: None, + ], + params: [], + window: None, + lambda: None, + }, } @@ -1003,41 +1009,45 @@ BinaryOp { span: Some( 4..5, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 4..5, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 4..5, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 8..9, ), - database: None, - table: Some( - Identifier { - span: Some( - 8..9, - ), - name: "c", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 10..11, - ), - name: "d", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 8..9, + ), + name: "c", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 10..11, + ), + name: "d", + quote: None, + }, + ), + }, }, }, } @@ -1057,17 +1067,19 @@ BinaryOp { span: Some( 0..6, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..6, - ), - name: "number", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..6, + ), + name: "number", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -1097,19 +1109,21 @@ MapAccess { span: Some( 0..3, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..3, - ), - name: "t", - quote: Some( - '"', - ), - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..3, + ), + name: "t", + quote: Some( + '"', + ), + }, + ), + }, }, accessor: Colon { key: Identifier { @@ -1154,19 +1168,21 @@ MapAccess { span: Some( 0..3, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..3, - ), - name: "t", - quote: Some( - '"', - ), - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..3, + ), + name: "t", + quote: Some( + '"', + ), + }, + ), + }, }, accessor: Colon { key: Identifier { @@ -1207,17 +1223,19 @@ MapAccess { span: Some( 0..1, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..1, - ), - name: "t", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..1, + ), + name: "t", + quote: None, + }, + ), + }, }, accessor: DotNumber { key: 0, @@ -1266,17 +1284,19 @@ Between { span: Some( 0..4, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..4, - ), - name: "col1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..4, + ), + name: "col1", + quote: None, + }, + ), + }, }, low: Literal { span: Some( @@ -1307,35 +1327,39 @@ FunctionCall { span: Some( 0..9, ), - distinct: false, - name: Identifier { - span: Some( - 0..3, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 4..8, + 0..3, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 4..8, + name: "sum", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 4..8, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 4..8, + ), + name: "col1", + quote: None, + }, ), - name: "col1", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -1348,20 +1372,22 @@ FunctionCall { span: Some( 0..10, ), - distinct: false, - name: Identifier { - span: Some( - 0..8, - ), - name: "random", - quote: Some( - '"', - ), + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 0..8, + ), + name: "random", + quote: Some( + '"', + ), + }, + args: [], + params: [], + window: None, + lambda: None, }, - args: [], - params: [], - window: None, - lambda: None, } @@ -1374,18 +1400,20 @@ FunctionCall { span: Some( 0..16, ), - distinct: true, - name: Identifier { - span: Some( - 0..6, - ), - name: "random", - quote: None, + func: FunctionCall { + distinct: true, + name: Identifier { + span: Some( + 0..6, + ), + name: "random", + quote: None, + }, + args: [], + params: [], + window: None, + lambda: None, }, - args: [], - params: [], - window: None, - lambda: None, } @@ -1398,51 +1426,57 @@ FunctionCall { span: Some( 0..26, ), - distinct: false, - name: Identifier { - span: Some( - 0..10, - ), - name: "covar_samp", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 11..17, + 0..10, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 11..17, + name: "covar_samp", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 11..17, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 11..17, + ), + name: "number", + quote: None, + }, ), - name: "number", - quote: None, }, - ), - }, - ColumnRef { - span: Some( - 19..25, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 19..25, + }, + ColumnRef { + span: Some( + 19..25, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 19..25, + ), + name: "number", + quote: None, + }, ), - name: "number", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -1459,17 +1493,19 @@ Cast { span: Some( 5..9, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 5..9, - ), - name: "col1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 5..9, + ), + name: "col1", + quote: None, + }, + ), + }, }, target_type: UInt64, pg_style: false, @@ -1489,17 +1525,19 @@ TryCast { span: Some( 9..13, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 9..13, - ), - name: "col1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 9..13, + ), + name: "col1", + quote: None, + }, + ), + }, }, target_type: UInt64, } @@ -1518,17 +1556,19 @@ TryCast { span: Some( 9..13, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 9..13, - ), - name: "col1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 9..13, + ), + name: "col1", + quote: None, + }, + ), + }, }, target_type: Tuple { fields_name: None, @@ -1589,17 +1629,19 @@ Extract { span: Some( 18..19, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 18..19, - ), - name: "d", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 18..19, + ), + name: "d", + quote: None, + }, + ), + }, }, } @@ -1618,17 +1660,19 @@ DatePart { span: Some( 16..17, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 16..17, - ), - name: "d", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 16..17, + ), + name: "d", + quote: None, + }, + ), + }, }, } @@ -1654,22 +1698,24 @@ Position { span: Some( 16..19, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 16..19, - ), - name: "str", - quote: None, - }, - ), - }, -} - - ----------- Input ---------- + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 16..19, + ), + name: "str", + quote: None, + }, + ), + }, + }, +} + + +---------- Input ---------- substring(a from b for c) ---------- Output --------- SUBSTRING(a FROM b FOR c) @@ -1682,51 +1728,57 @@ Substring { span: Some( 10..11, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 10..11, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 10..11, + ), + name: "a", + quote: None, + }, + ), + }, }, substring_from: ColumnRef { span: Some( 17..18, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 17..18, - ), - name: "b", - quote: None, - }, - ), - }, - substring_for: Some( - ColumnRef { - span: Some( - 23..24, - ), + column: ColumnRef { database: None, table: None, column: Name( Identifier { span: Some( - 23..24, + 17..18, ), - name: "c", + name: "b", quote: None, }, ), }, + }, + substring_for: Some( + ColumnRef { + span: Some( + 23..24, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..24, + ), + name: "c", + quote: None, + }, + ), + }, + }, ), } @@ -1744,51 +1796,57 @@ Substring { span: Some( 10..11, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 10..11, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 10..11, + ), + name: "a", + quote: None, + }, + ), + }, }, substring_from: ColumnRef { span: Some( 13..14, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 13..14, - ), - name: "b", - quote: None, - }, - ), - }, - substring_for: Some( - ColumnRef { - span: Some( - 16..17, - ), + column: ColumnRef { database: None, table: None, column: Name( Identifier { span: Some( - 16..17, + 13..14, ), - name: "c", + name: "b", quote: None, }, ), }, + }, + substring_for: Some( + ColumnRef { + span: Some( + 16..17, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 16..17, + ), + name: "c", + quote: None, + }, + ), + }, + }, ), } @@ -1806,17 +1864,19 @@ Cast { span: Some( 0..4, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..4, - ), - name: "col1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..4, + ), + name: "col1", + quote: None, + }, + ), + }, }, target_type: UInt8, pg_style: true, @@ -1844,17 +1904,19 @@ MapAccess { span: Some( 1..4, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 1..4, - ), - name: "arr", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 1..4, + ), + name: "arr", + quote: None, + }, + ), + }, }, accessor: Bracket { key: Literal { @@ -1906,17 +1968,19 @@ MapAccess { span: Some( 0..3, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..3, - ), - name: "arr", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..3, + ), + name: "arr", + quote: None, + }, + ), + }, }, accessor: Bracket { key: Literal { @@ -1934,19 +1998,21 @@ MapAccess { span: Some( 7..10, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 7..10, - ), - name: "k", - quote: Some( - '"', - ), - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 7..10, + ), + name: "k", + quote: Some( + '"', + ), + }, + ), + }, }, }, } @@ -1966,17 +2032,19 @@ BinaryOp { span: Some( 0..1, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..1, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..1, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -2053,33 +2121,35 @@ BinaryOp { span: Some( 0..1, ), - database: Some( - Identifier { - span: Some( - 0..1, - ), - name: "G", - quote: None, - }, - ), - table: Some( - Identifier { - span: Some( - 2..3, - ), - name: "E", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 4..5, - ), - name: "B", - quote: None, - }, - ), + column: ColumnRef { + database: Some( + Identifier { + span: Some( + 0..1, + ), + name: "G", + quote: None, + }, + ), + table: Some( + Identifier { + span: Some( + 2..3, + ), + name: "E", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 4..5, + ), + name: "B", + quote: None, + }, + ), + }, }, not: true, }, @@ -2091,33 +2161,37 @@ BinaryOp { span: Some( 22..26, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 22..26, - ), - name: "col1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 22..26, + ), + name: "col1", + quote: None, + }, + ), + }, }, low: ColumnRef { span: Some( 39..43, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 39..43, - ), - name: "col2", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 39..43, + ), + name: "col2", + quote: None, + }, + ), + }, }, high: BinaryOp { span: Some( @@ -2141,52 +2215,58 @@ BinaryOp { span: Some( 53..57, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 53..57, - ), - name: "col3", - quote: None, - }, - ), - }, - }, - right: FunctionCall { - span: Some( - 63..72, - ), - distinct: false, - name: Identifier { - span: Some( - 63..66, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { - span: Some( - 67..71, - ), + column: ColumnRef { database: None, table: None, column: Name( Identifier { span: Some( - 67..71, + 53..57, ), - name: "col4", + name: "col3", quote: None, }, ), }, - ], - params: [], - window: None, - lambda: None, + }, + }, + right: FunctionCall { + span: Some( + 63..72, + ), + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 63..66, + ), + name: "sum", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 67..71, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 67..71, + ), + name: "col4", + quote: None, + }, + ), + }, + }, + ], + params: [], + window: None, + lambda: None, + }, }, }, not: true, @@ -2208,93 +2288,99 @@ BinaryOp { span: Some( 0..62, ), - distinct: false, - name: Identifier { - span: Some( - 0..3, - ), - name: "sum", - quote: None, - }, - args: [ - Case { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 4..61, + 0..3, ), - operand: None, - conditions: [ - BinaryOp { - span: Some( - 24..25, - ), - op: Eq, - left: ColumnRef { + name: "sum", + quote: None, + }, + args: [ + Case { + span: Some( + 4..61, + ), + operand: None, + conditions: [ + BinaryOp { span: Some( - 14..16, + 24..25, ), - database: None, - table: Some( - Identifier { - span: Some( - 14..16, + op: Eq, + left: ColumnRef { + span: Some( + 14..16, + ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 14..16, + ), + name: "n2", + quote: None, + }, ), - name: "n2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 17..23, + column: Name( + Identifier { + span: Some( + 17..23, + ), + name: "n_name", + quote: None, + }, ), - name: "n_name", - quote: None, }, + }, + right: Literal { + span: Some( + 26..35, + ), + lit: String( + "GERMANY", + ), + }, + }, + ], + results: [ + ColumnRef { + span: Some( + 41..50, ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 41..50, + ), + name: "ol_amount", + quote: None, + }, + ), + }, }, - right: Literal { + ], + else_result: Some( + Literal { span: Some( - 26..35, + 56..57, ), - lit: String( - "GERMANY", + lit: UInt64( + 0, ), }, - }, - ], - results: [ - ColumnRef { - span: Some( - 41..50, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 41..50, - ), - name: "ol_amount", - quote: None, - }, - ), - }, - ], - else_result: Some( - Literal { - span: Some( - 56..57, - ), - lit: UInt64( - 0, - ), - }, - ), - }, - ], - params: [], - window: None, - lambda: None, + ), + }, + ], + params: [], + window: None, + lambda: None, + }, }, right: Case { span: Some( @@ -2311,35 +2397,39 @@ BinaryOp { span: Some( 75..89, ), - distinct: false, - name: Identifier { - span: Some( - 75..78, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 79..88, + 75..78, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 79..88, + name: "sum", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 79..88, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 79..88, + ), + name: "ol_amount", + quote: None, + }, ), - name: "ol_amount", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, right: Literal { span: Some( @@ -2366,35 +2456,39 @@ BinaryOp { span: Some( 106..120, ), - distinct: false, - name: Identifier { - span: Some( - 106..109, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 110..119, + 106..109, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 110..119, + name: "sum", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 110..119, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 110..119, + ), + name: "ol_amount", + quote: None, + }, ), - name: "ol_amount", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, ), }, @@ -2456,33 +2550,37 @@ BinaryOp { span: Some( 0..9, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..9, - ), - name: "p_partkey", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..9, + ), + name: "p_partkey", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 12..21, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 12..21, - ), - name: "l_partkey", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 12..21, + ), + name: "l_partkey", + quote: None, + }, + ), + }, }, }, right: BinaryOp { @@ -2494,17 +2592,19 @@ BinaryOp { span: Some( 38..45, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 38..45, - ), - name: "p_brand", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 38..45, + ), + name: "p_brand", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -2524,17 +2624,19 @@ BinaryOp { span: Some( 75..86, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 75..86, - ), - name: "p_container", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 75..86, + ), + name: "p_container", + quote: None, + }, + ), + }, }, list: [ Literal { @@ -2582,17 +2684,19 @@ BinaryOp { span: Some( 149..159, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 149..159, - ), - name: "l_quantity", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 149..159, + ), + name: "l_quantity", + quote: None, + }, + ), + }, }, right: Cast { span: Some( @@ -2620,17 +2724,19 @@ BinaryOp { span: Some( 188..198, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 188..198, - ), - name: "l_quantity", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 188..198, + ), + name: "l_quantity", + quote: None, + }, + ), + }, }, right: Cast { span: Some( @@ -2671,17 +2777,19 @@ BinaryOp { span: Some( 244..250, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 244..250, - ), - name: "p_size", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 244..250, + ), + name: "p_size", + quote: None, + }, + ), + }, }, low: Cast { span: Some( @@ -2724,17 +2832,19 @@ BinaryOp { span: Some( 321..331, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 321..331, - ), - name: "l_shipmode", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 321..331, + ), + name: "l_shipmode", + quote: None, + }, + ), + }, }, list: [ Literal { @@ -2766,17 +2876,19 @@ BinaryOp { span: Some( 370..384, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 370..384, - ), - name: "l_shipinstruct", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 370..384, + ), + name: "l_shipinstruct", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -2799,35 +2911,37 @@ FunctionCall { span: Some( 0..12, ), - distinct: false, - name: Identifier { - span: Some( - 0..6, - ), - name: "nullif", - quote: None, - }, - args: [ - Literal { - span: Some( - 7..8, - ), - lit: UInt64( - 1, - ), - }, - Literal { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 10..11, - ), - lit: UInt64( - 1, + 0..6, ), + name: "nullif", + quote: None, }, - ], - params: [], - window: None, - lambda: None, + args: [ + Literal { + span: Some( + 7..8, + ), + lit: UInt64( + 1, + ), + }, + Literal { + span: Some( + 10..11, + ), + lit: UInt64( + 1, + ), + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -2840,51 +2954,57 @@ FunctionCall { span: Some( 0..12, ), - distinct: false, - name: Identifier { - span: Some( - 0..6, - ), - name: "nullif", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 7..8, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 7..8, - ), - name: "a", - quote: None, - }, + 0..6, ), + name: "nullif", + quote: None, }, - ColumnRef { - span: Some( - 10..11, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 10..11, + args: [ + ColumnRef { + span: Some( + 7..8, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 7..8, + ), + name: "a", + quote: None, + }, ), - name: "b", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ColumnRef { + span: Some( + 10..11, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 10..11, + ), + name: "b", + quote: None, + }, + ), + }, + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -2897,43 +3017,45 @@ FunctionCall { span: Some( 0..17, ), - distinct: false, - name: Identifier { - span: Some( - 0..8, - ), - name: "coalesce", - quote: None, - }, - args: [ - Literal { - span: Some( - 9..10, - ), - lit: UInt64( - 1, - ), - }, - Literal { - span: Some( - 12..13, - ), - lit: UInt64( - 2, - ), - }, - Literal { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 15..16, - ), - lit: UInt64( - 3, + 0..8, ), + name: "coalesce", + quote: None, }, - ], - params: [], - window: None, - lambda: None, + args: [ + Literal { + span: Some( + 9..10, + ), + lit: UInt64( + 1, + ), + }, + Literal { + span: Some( + 12..13, + ), + lit: UInt64( + 2, + ), + }, + Literal { + span: Some( + 15..16, + ), + lit: UInt64( + 3, + ), + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -2946,67 +3068,75 @@ FunctionCall { span: Some( 0..17, ), - distinct: false, - name: Identifier { - span: Some( - 0..8, - ), - name: "coalesce", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 9..10, + 0..8, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 9..10, + name: "coalesce", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 9..10, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 9..10, + ), + name: "a", + quote: None, + }, ), - name: "a", - quote: None, }, - ), - }, - ColumnRef { - span: Some( - 12..13, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 12..13, + }, + ColumnRef { + span: Some( + 12..13, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 12..13, + ), + name: "b", + quote: None, + }, ), - name: "b", - quote: None, }, - ), - }, - ColumnRef { - span: Some( - 15..16, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 15..16, + }, + ColumnRef { + span: Some( + 15..16, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 15..16, + ), + name: "c", + quote: None, + }, ), - name: "c", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -3019,35 +3149,37 @@ FunctionCall { span: Some( 0..12, ), - distinct: false, - name: Identifier { - span: Some( - 0..6, - ), - name: "ifnull", - quote: None, - }, - args: [ - Literal { - span: Some( - 7..8, - ), - lit: UInt64( - 1, - ), - }, - Literal { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 10..11, - ), - lit: UInt64( - 1, + 0..6, ), + name: "ifnull", + quote: None, }, - ], - params: [], - window: None, - lambda: None, + args: [ + Literal { + span: Some( + 7..8, + ), + lit: UInt64( + 1, + ), + }, + Literal { + span: Some( + 10..11, + ), + lit: UInt64( + 1, + ), + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -3060,51 +3192,57 @@ FunctionCall { span: Some( 0..12, ), - distinct: false, - name: Identifier { - span: Some( - 0..6, - ), - name: "ifnull", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 7..8, + 0..6, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 7..8, + name: "ifnull", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 7..8, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 7..8, + ), + name: "a", + quote: None, + }, ), - name: "a", - quote: None, }, - ), - }, - ColumnRef { - span: Some( - 10..11, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 10..11, + }, + ColumnRef { + span: Some( + 10..11, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 10..11, + ), + name: "b", + quote: None, + }, ), - name: "b", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, } @@ -3150,33 +3288,37 @@ IsDistinctFrom { span: Some( 0..1, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 0..1, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 0..1, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 19..20, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 19..20, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 19..20, + ), + name: "b", + quote: None, + }, + ), + }, }, not: false, } @@ -3258,50 +3400,54 @@ FunctionCall { span: Some( 0..40, ), - distinct: false, - name: Identifier { - span: Some( - 0..10, - ), - name: "ROW_NUMBER", - quote: None, - }, - args: [], - params: [], - window: Some( - WindowSpec( - WindowSpec { - existing_window_name: None, - partition_by: [], - order_by: [ - OrderByExpr { - expr: ColumnRef { - span: Some( - 28..34, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 28..34, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 0..10, + ), + name: "ROW_NUMBER", + quote: None, + }, + args: [], + params: [], + window: Some( + WindowSpec( + WindowSpec { + existing_window_name: None, + partition_by: [], + order_by: [ + OrderByExpr { + expr: ColumnRef { + span: Some( + 28..34, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 28..34, + ), + name: "salary", + quote: None, + }, ), - name: "salary", - quote: None, }, + }, + asc: Some( + false, ), + nulls_first: None, }, - asc: Some( - false, - ), - nulls_first: None, - }, - ], - window_frame: None, - }, + ], + window_frame: None, + }, + ), ), - ), - lambda: None, + lambda: None, + }, } @@ -3314,44 +3460,48 @@ FunctionCall { span: Some( 0..19, ), - distinct: false, - name: Identifier { - span: Some( - 0..3, - ), - name: "SUM", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 4..10, + 0..3, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 4..10, + name: "SUM", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 4..10, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 4..10, + ), + name: "salary", + quote: None, + }, ), - name: "salary", - quote: None, }, - ), - }, - ], - params: [], - window: Some( - WindowSpec( - WindowSpec { - existing_window_name: None, - partition_by: [], - order_by: [], - window_frame: None, }, + ], + params: [], + window: Some( + WindowSpec( + WindowSpec { + existing_window_name: None, + partition_by: [], + order_by: [], + window_frame: None, + }, + ), ), - ), - lambda: None, + lambda: None, + }, } @@ -3364,61 +3514,67 @@ FunctionCall { span: Some( 0..42, ), - distinct: false, - name: Identifier { - span: Some( - 0..3, - ), - name: "AVG", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 4..10, + 0..3, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 4..10, + name: "AVG", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 4..10, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 4..10, + ), + name: "salary", + quote: None, + }, ), - name: "salary", - quote: None, }, - ), - }, - ], - params: [], - window: Some( - WindowSpec( - WindowSpec { - existing_window_name: None, - partition_by: [ - ColumnRef { - span: Some( - 31..41, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 31..41, + }, + ], + params: [], + window: Some( + WindowSpec( + WindowSpec { + existing_window_name: None, + partition_by: [ + ColumnRef { + span: Some( + 31..41, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 31..41, + ), + name: "department", + quote: None, + }, ), - name: "department", - quote: None, }, - ), - }, - ], - order_by: [], - window_frame: None, - }, + }, + ], + order_by: [], + window_frame: None, + }, + ), ), - ), - lambda: None, + lambda: None, + }, } @@ -3431,92 +3587,100 @@ FunctionCall { span: Some( 0..112, ), - distinct: false, - name: Identifier { - span: Some( - 0..3, - ), - name: "SUM", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 4..10, + 0..3, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 4..10, + name: "SUM", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 4..10, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 4..10, + ), + name: "salary", + quote: None, + }, ), - name: "salary", - quote: None, }, - ), - }, - ], - params: [], - window: Some( - WindowSpec( - WindowSpec { - existing_window_name: None, - partition_by: [ - ColumnRef { - span: Some( - 31..41, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 31..41, - ), - name: "department", - quote: None, - }, - ), - }, - ], - order_by: [ - OrderByExpr { - expr: ColumnRef { + }, + ], + params: [], + window: Some( + WindowSpec( + WindowSpec { + existing_window_name: None, + partition_by: [ + ColumnRef { span: Some( - 51..57, + 31..41, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 51..57, + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 31..41, + ), + name: "department", + quote: None, + }, + ), + }, + }, + ], + order_by: [ + OrderByExpr { + expr: ColumnRef { + span: Some( + 51..57, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 51..57, + ), + name: "salary", + quote: None, + }, ), - name: "salary", - quote: None, }, + }, + asc: Some( + false, ), + nulls_first: None, }, - asc: Some( - false, - ), - nulls_first: None, - }, - ], - window_frame: Some( - WindowFrame { - units: Rows, - start_bound: Preceding( - None, - ), - end_bound: CurrentRow, - }, - ), - }, + ], + window_frame: Some( + WindowFrame { + units: Rows, + start_bound: Preceding( + None, + ), + end_bound: CurrentRow, + }, + ), + }, + ), ), - ), - lambda: None, + lambda: None, + }, } @@ -3529,99 +3693,107 @@ FunctionCall { span: Some( 0..102, ), - distinct: false, - name: Identifier { - span: Some( - 0..3, - ), - name: "AVG", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 4..10, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 4..10, - ), - name: "salary", - quote: None, - }, + 0..3, ), + name: "AVG", + quote: None, }, - ], - params: [], - window: Some( - WindowSpec( - WindowSpec { - existing_window_name: None, - partition_by: [ - ColumnRef { - span: Some( - 31..41, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 31..41, - ), - name: "department", - quote: None, - }, - ), - }, - ], - order_by: [ - OrderByExpr { - expr: ColumnRef { + args: [ + ColumnRef { + span: Some( + 4..10, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { span: Some( - 51..60, + 4..10, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 51..60, - ), - name: "hire_date", - quote: None, - }, + name: "salary", + quote: None, + }, + ), + }, + }, + ], + params: [], + window: Some( + WindowSpec( + WindowSpec { + existing_window_name: None, + partition_by: [ + ColumnRef { + span: Some( + 31..41, ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 31..41, + ), + name: "department", + quote: None, + }, + ), + }, }, - asc: None, - nulls_first: None, - }, - ], - window_frame: Some( - WindowFrame { - units: Rows, - start_bound: Preceding( - Some( - Literal { - span: Some( - 74..75, - ), - lit: UInt64( - 2, + ], + order_by: [ + OrderByExpr { + expr: ColumnRef { + span: Some( + 51..60, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 51..60, + ), + name: "hire_date", + quote: None, + }, ), }, + }, + asc: None, + nulls_first: None, + }, + ], + window_frame: Some( + WindowFrame { + units: Rows, + start_bound: Preceding( + Some( + Literal { + span: Some( + 74..75, + ), + lit: UInt64( + 2, + ), + }, + ), ), - ), - end_bound: CurrentRow, - }, - ), - }, + end_bound: CurrentRow, + }, + ), + }, + ), ), - ), - lambda: None, + lambda: None, + }, } @@ -3634,71 +3806,75 @@ FunctionCall { span: Some( 0..90, ), - distinct: false, - name: Identifier { - span: Some( - 0..5, - ), - name: "COUNT", - quote: None, - }, - args: [], - params: [], - window: Some( - WindowSpec( - WindowSpec { - existing_window_name: None, - partition_by: [], - order_by: [ - OrderByExpr { - expr: ColumnRef { - span: Some( - 23..32, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..32, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 0..5, + ), + name: "COUNT", + quote: None, + }, + args: [], + params: [], + window: Some( + WindowSpec( + WindowSpec { + existing_window_name: None, + partition_by: [], + order_by: [ + OrderByExpr { + expr: ColumnRef { + span: Some( + 23..32, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..32, + ), + name: "hire_date", + quote: None, + }, ), - name: "hire_date", - quote: None, }, - ), + }, + asc: None, + nulls_first: None, }, - asc: None, - nulls_first: None, - }, - ], - window_frame: Some( - WindowFrame { - units: Range, - start_bound: Preceding( - Some( - Interval { - span: Some( - 47..63, - ), - expr: Literal { + ], + window_frame: Some( + WindowFrame { + units: Range, + start_bound: Preceding( + Some( + Interval { span: Some( - 56..59, - ), - lit: String( - "7", + 47..63, ), + expr: Literal { + span: Some( + 56..59, + ), + lit: String( + "7", + ), + }, + unit: Day, }, - unit: Day, - }, + ), ), - ), - end_bound: CurrentRow, - }, - ), - }, + end_bound: CurrentRow, + }, + ), + }, + ), ), - ), - lambda: None, + lambda: None, + }, } @@ -3711,56 +3887,60 @@ FunctionCall { span: Some( 0..58, ), - distinct: false, - name: Identifier { - span: Some( - 0..5, - ), - name: "COUNT", - quote: None, - }, - args: [], - params: [], - window: Some( - WindowSpec( - WindowSpec { - existing_window_name: None, - partition_by: [], - order_by: [ - OrderByExpr { - expr: ColumnRef { - span: Some( - 23..32, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..32, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 0..5, + ), + name: "COUNT", + quote: None, + }, + args: [], + params: [], + window: Some( + WindowSpec( + WindowSpec { + existing_window_name: None, + partition_by: [], + order_by: [ + OrderByExpr { + expr: ColumnRef { + span: Some( + 23..32, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..32, + ), + name: "hire_date", + quote: None, + }, ), - name: "hire_date", - quote: None, }, + }, + asc: None, + nulls_first: None, + }, + ], + window_frame: Some( + WindowFrame { + units: Rows, + start_bound: Preceding( + None, ), + end_bound: CurrentRow, }, - asc: None, - nulls_first: None, - }, - ], - window_frame: Some( - WindowFrame { - units: Rows, - start_bound: Preceding( - None, - ), - end_bound: CurrentRow, - }, - ), - }, + ), + }, + ), ), - ), - lambda: None, + lambda: None, + }, } @@ -3773,54 +3953,58 @@ FunctionCall { span: Some( 0..50, ), - distinct: false, - name: Identifier { - span: Some( - 0..5, - ), - name: "COUNT", - quote: None, - }, - args: [], - params: [], - window: Some( - WindowSpec( - WindowSpec { - existing_window_name: None, - partition_by: [], - order_by: [ - OrderByExpr { - expr: ColumnRef { - span: Some( - 23..32, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..32, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 0..5, + ), + name: "COUNT", + quote: None, + }, + args: [], + params: [], + window: Some( + WindowSpec( + WindowSpec { + existing_window_name: None, + partition_by: [], + order_by: [ + OrderByExpr { + expr: ColumnRef { + span: Some( + 23..32, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..32, + ), + name: "hire_date", + quote: None, + }, ), - name: "hire_date", - quote: None, }, - ), + }, + asc: None, + nulls_first: None, }, - asc: None, - nulls_first: None, - }, - ], - window_frame: Some( - WindowFrame { - units: Rows, - start_bound: CurrentRow, - end_bound: CurrentRow, - }, - ), - }, + ], + window_frame: Some( + WindowFrame { + units: Rows, + start_bound: CurrentRow, + end_bound: CurrentRow, + }, + ), + }, + ), ), - ), - lambda: None, + lambda: None, + }, } @@ -3833,65 +4017,69 @@ FunctionCall { span: Some( 0..50, ), - distinct: false, - name: Identifier { - span: Some( - 0..5, - ), - name: "COUNT", - quote: None, - }, - args: [], - params: [], - window: Some( - WindowSpec( - WindowSpec { - existing_window_name: None, - partition_by: [], - order_by: [ - OrderByExpr { - expr: ColumnRef { - span: Some( - 23..32, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..32, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 0..5, + ), + name: "COUNT", + quote: None, + }, + args: [], + params: [], + window: Some( + WindowSpec( + WindowSpec { + existing_window_name: None, + partition_by: [], + order_by: [ + OrderByExpr { + expr: ColumnRef { + span: Some( + 23..32, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..32, + ), + name: "hire_date", + quote: None, + }, ), - name: "hire_date", - quote: None, }, - ), + }, + asc: None, + nulls_first: None, }, - asc: None, - nulls_first: None, - }, - ], - window_frame: Some( - WindowFrame { - units: Rows, - start_bound: Preceding( - Some( - Literal { - span: Some( - 38..39, - ), - lit: UInt64( - 3, - ), - }, + ], + window_frame: Some( + WindowFrame { + units: Rows, + start_bound: Preceding( + Some( + Literal { + span: Some( + 38..39, + ), + lit: UInt64( + 3, + ), + }, + ), ), - ), - end_bound: CurrentRow, - }, - ), - }, + end_bound: CurrentRow, + }, + ), + }, + ), ), - ), - lambda: None, + lambda: None, + }, } @@ -3904,92 +4092,96 @@ FunctionCall { span: Some( 0..32, ), - distinct: false, - name: Identifier { - span: Some( - 0..11, - ), - name: "ARRAY_APPLY", - quote: None, - }, - args: [ - Array { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 12..19, + 0..11, ), - exprs: [ - Literal { - span: Some( - 13..14, - ), - lit: UInt64( - 1, - ), - }, - Literal { - span: Some( - 15..16, - ), - lit: UInt64( - 2, - ), - }, - Literal { - span: Some( - 17..18, - ), - lit: UInt64( - 3, - ), - }, - ], + name: "ARRAY_APPLY", + quote: None, }, - ], - params: [], - window: None, - lambda: Some( - Lambda { - params: [ - Identifier { - span: Some( - 21..22, - ), - name: "x", - quote: None, - }, - ], - expr: BinaryOp { + args: [ + Array { span: Some( - 28..29, + 12..19, ), - op: Plus, - left: ColumnRef { + exprs: [ + Literal { + span: Some( + 13..14, + ), + lit: UInt64( + 1, + ), + }, + Literal { + span: Some( + 15..16, + ), + lit: UInt64( + 2, + ), + }, + Literal { + span: Some( + 17..18, + ), + lit: UInt64( + 3, + ), + }, + ], + }, + ], + params: [], + window: None, + lambda: Some( + Lambda { + params: [ + Identifier { + span: Some( + 21..22, + ), + name: "x", + quote: None, + }, + ], + expr: BinaryOp { span: Some( - 26..27, + 28..29, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 26..27, + op: Plus, + left: ColumnRef { + span: Some( + 26..27, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 26..27, + ), + name: "x", + quote: None, + }, ), - name: "x", - quote: None, }, - ), - }, - right: Literal { - span: Some( - 30..31, - ), - lit: UInt64( - 1, - ), + }, + right: Literal { + span: Some( + 30..31, + ), + lit: UInt64( + 1, + ), + }, }, }, - }, - ), + ), + }, } @@ -4002,91 +4194,97 @@ FunctionCall { span: Some( 0..33, ), - distinct: false, - name: Identifier { - span: Some( - 0..12, - ), - name: "ARRAY_FILTER", - quote: None, - }, - args: [ - ColumnRef { - span: Some( - 13..16, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 13..16, - ), - name: "col", - quote: None, - }, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 0..12, ), + name: "ARRAY_FILTER", + quote: None, }, - ], - params: [], - window: None, - lambda: Some( - Lambda { - params: [ - Identifier { - span: Some( - 18..19, - ), - name: "y", - quote: None, - }, - ], - expr: BinaryOp { + args: [ + ColumnRef { span: Some( - 29..30, + 13..16, ), - op: Eq, - left: BinaryOp { + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 13..16, + ), + name: "col", + quote: None, + }, + ), + }, + }, + ], + params: [], + window: None, + lambda: Some( + Lambda { + params: [ + Identifier { + span: Some( + 18..19, + ), + name: "y", + quote: None, + }, + ], + expr: BinaryOp { span: Some( - 25..26, + 29..30, ), - op: Modulo, - left: ColumnRef { + op: Eq, + left: BinaryOp { span: Some( - 23..24, + 25..26, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..24, + op: Modulo, + left: ColumnRef { + span: Some( + 23..24, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..24, + ), + name: "y", + quote: None, + }, ), - name: "y", - quote: None, }, - ), + }, + right: Literal { + span: Some( + 27..28, + ), + lit: UInt64( + 2, + ), + }, }, right: Literal { span: Some( - 27..28, + 31..32, ), lit: UInt64( - 2, + 0, ), }, }, - right: Literal { - span: Some( - 31..32, - ), - lit: UInt64( - 0, - ), - }, }, - }, - ), + ), + }, } @@ -4104,50 +4302,56 @@ Tuple { span: Some( 1..18, ), - distinct: false, - name: Identifier { - span: None, - name: "current_timestamp", - quote: None, + func: FunctionCall { + distinct: false, + name: Identifier { + span: None, + name: "current_timestamp", + quote: None, + }, + args: [], + params: [], + window: None, + lambda: None, }, - args: [], - params: [], - window: None, - lambda: None, }, FunctionCall { span: Some( 20..39, ), - distinct: false, - name: Identifier { - span: Some( - 20..37, - ), - name: "current_timestamp", - quote: None, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 20..37, + ), + name: "current_timestamp", + quote: None, + }, + args: [], + params: [], + window: None, + lambda: None, }, - args: [], - params: [], - window: None, - lambda: None, }, FunctionCall { span: Some( 41..46, ), - distinct: false, - name: Identifier { - span: Some( - 41..44, - ), - name: "now", - quote: None, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 41..44, + ), + name: "now", + quote: None, + }, + args: [], + params: [], + window: None, + lambda: None, }, - args: [], - params: [], - window: None, - lambda: None, }, ], } @@ -4162,107 +4366,113 @@ FunctionCall { span: Some( 0..41, ), - distinct: false, - name: Identifier { - span: Some( - 0..12, - ), - name: "ARRAY_REDUCE", - quote: None, - }, - args: [ - Array { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 13..20, + 0..12, ), - exprs: [ - Literal { - span: Some( - 14..15, - ), - lit: UInt64( - 1, - ), - }, - Literal { - span: Some( - 16..17, - ), - lit: UInt64( - 2, - ), - }, - Literal { - span: Some( - 18..19, - ), - lit: UInt64( - 3, - ), - }, - ], + name: "ARRAY_REDUCE", + quote: None, }, - ], - params: [], - window: None, - lambda: Some( - Lambda { - params: [ - Identifier { - span: Some( - 23..26, - ), - name: "acc", - quote: None, - }, - Identifier { - span: Some( - 27..28, - ), - name: "t", - quote: None, - }, - ], - expr: BinaryOp { + args: [ + Array { span: Some( - 37..38, + 13..20, ), - op: Plus, - left: ColumnRef { + exprs: [ + Literal { + span: Some( + 14..15, + ), + lit: UInt64( + 1, + ), + }, + Literal { + span: Some( + 16..17, + ), + lit: UInt64( + 2, + ), + }, + Literal { + span: Some( + 18..19, + ), + lit: UInt64( + 3, + ), + }, + ], + }, + ], + params: [], + window: None, + lambda: Some( + Lambda { + params: [ + Identifier { + span: Some( + 23..26, + ), + name: "acc", + quote: None, + }, + Identifier { + span: Some( + 27..28, + ), + name: "t", + quote: None, + }, + ], + expr: BinaryOp { span: Some( - 33..36, + 37..38, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 33..36, + op: Plus, + left: ColumnRef { + span: Some( + 33..36, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 33..36, + ), + name: "acc", + quote: None, + }, ), - name: "acc", - quote: None, }, - ), - }, - right: ColumnRef { - span: Some( - 39..40, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 39..40, + }, + right: ColumnRef { + span: Some( + 39..40, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 39..40, + ), + name: "t", + quote: None, + }, ), - name: "t", - quote: None, }, - ), + }, }, }, - }, - ), + ), + }, } diff --git a/src/query/ast/tests/it/testdata/query.txt b/src/query/ast/tests/it/testdata/query.txt index 4d0fc4fc2c4cf..de282cfc73634 100644 --- a/src/query/ast/tests/it/testdata/query.txt +++ b/src/query/ast/tests/it/testdata/query.txt @@ -101,33 +101,37 @@ Query { span: Some( 81..82, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 81..82, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 81..82, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 85..86, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 85..86, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 85..86, + ), + name: "b", + quote: None, + }, + ), + }, }, }, ), @@ -238,15 +242,17 @@ Query { op: Regexp, left: ColumnRef { span: None, - database: None, - table: None, - column: Name( - Identifier { - span: None, - name: "_t", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: None, + name: "_t", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -290,35 +296,39 @@ Query { span: Some( 36..45, ), - distinct: false, - name: Identifier { - span: Some( - 36..42, - ), - name: "length", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 43..44, + 36..42, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 43..44, + name: "length", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 43..44, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 43..44, + ), + name: "a", + quote: None, + }, ), - name: "a", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, right: Literal { span: Some( @@ -599,33 +609,37 @@ Query { span: Some( 45..46, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 45..46, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 45..46, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 49..50, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 49..50, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 49..50, + ), + name: "b", + quote: None, + }, + ), + }, }, }, ), @@ -730,33 +744,37 @@ Query { span: Some( 44..45, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 44..45, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 44..45, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 48..49, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 48..49, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 48..49, + ), + name: "b", + quote: None, + }, + ), + }, }, }, ), @@ -870,33 +888,37 @@ Query { span: Some( 44..45, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 44..45, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 44..45, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 48..49, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 48..49, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 48..49, + ), + name: "b", + quote: None, + }, + ), + }, }, }, ), @@ -1252,17 +1274,19 @@ Query { span: Some( 23..24, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..24, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..24, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -1317,25 +1341,27 @@ Query { span: Some( 40..42, ), - database: None, - table: Some( - Identifier { - span: Some( - 40..42, - ), - name: "t2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 43..45, - ), - name: "tt", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 40..42, + ), + name: "t2", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 43..45, + ), + name: "tt", + quote: None, + }, + ), + }, }, alias: None, }, @@ -1371,25 +1397,27 @@ Query { span: Some( 61..63, ), - database: None, - table: Some( - Identifier { - span: Some( - 61..63, - ), - name: "t2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 64..66, - ), - name: "tt", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 61..63, + ), + name: "t2", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 64..66, + ), + name: "tt", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -1471,17 +1499,19 @@ Query { span: Some( 36..37, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 36..37, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 36..37, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -1536,25 +1566,27 @@ Query { span: Some( 53..55, ), - database: None, - table: Some( - Identifier { - span: Some( - 53..55, - ), - name: "t2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 56..58, - ), - name: "tt", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 53..55, + ), + name: "t2", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 56..58, + ), + name: "tt", + quote: None, + }, + ), + }, }, alias: None, }, @@ -1590,25 +1622,27 @@ Query { span: Some( 74..76, ), - database: None, - table: Some( - Identifier { - span: Some( - 74..76, - ), - name: "t2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 77..79, - ), - name: "tt", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 74..76, + ), + name: "t2", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 77..79, + ), + name: "tt", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -1682,17 +1716,19 @@ Query { span: Some( 19..20, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 19..20, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 19..20, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -1747,25 +1783,27 @@ Query { span: Some( 36..38, ), - database: None, - table: Some( - Identifier { - span: Some( - 36..38, - ), - name: "t2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 39..40, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 36..38, + ), + name: "t2", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 39..40, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -1801,25 +1839,27 @@ Query { span: Some( 56..58, ), - database: None, - table: Some( - Identifier { - span: Some( - 56..58, - ), - name: "t2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 59..60, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 56..58, + ), + name: "t2", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 59..60, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -1901,17 +1941,19 @@ Query { span: Some( 36..37, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 36..37, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 36..37, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2056,17 +2098,19 @@ Query { span: Some( 99..100, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 99..100, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 99..100, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2102,17 +2146,19 @@ Query { span: Some( 114..115, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 114..115, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 114..115, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -2152,25 +2198,27 @@ Query { span: Some( 128..130, ), - database: None, - table: Some( - Identifier { - span: Some( - 128..130, - ), - name: "t2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 131..133, - ), - name: "tt", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 128..130, + ), + name: "t2", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 131..133, + ), + name: "tt", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2179,25 +2227,27 @@ Query { span: Some( 135..137, ), - database: None, - table: Some( - Identifier { - span: Some( - 135..137, - ), - name: "t3", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 138..139, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 135..137, + ), + name: "t3", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 138..139, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2206,25 +2256,27 @@ Query { span: Some( 141..143, ), - database: None, - table: Some( - Identifier { - span: Some( - 141..143, - ), - name: "t4", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 144..145, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 141..143, + ), + name: "t4", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 144..145, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2298,25 +2350,27 @@ Query { span: Some( 168..170, ), - database: None, - table: Some( - Identifier { - span: Some( - 168..170, - ), - name: "t2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 171..173, - ), - name: "tt", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 168..170, + ), + name: "t2", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 171..173, + ), + name: "tt", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -2405,17 +2459,19 @@ Query { span: Some( 33..34, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 33..34, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 33..34, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2461,17 +2517,19 @@ Query { span: Some( 56..58, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 56..58, - ), - name: "tt", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 56..58, + ), + name: "tt", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2528,25 +2586,27 @@ Query { span: Some( 75..77, ), - database: None, - table: Some( - Identifier { - span: Some( - 75..77, - ), - name: "t2", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 78..80, - ), - name: "tt", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 75..77, + ), + name: "t2", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 78..80, + ), + name: "tt", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2716,25 +2776,27 @@ Query { span: Some( 54..55, ), - database: None, - table: Some( - Identifier { - span: Some( - 54..55, - ), - name: "t", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 56..57, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 54..55, + ), + name: "t", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 56..57, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2743,25 +2805,27 @@ Query { span: Some( 59..60, ), - database: None, - table: Some( - Identifier { - span: Some( - 59..60, - ), - name: "t", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 61..62, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 59..60, + ), + name: "t", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 61..62, + ), + name: "b", + quote: None, + }, + ), + }, }, alias: None, }, @@ -2839,17 +2903,19 @@ Query { span: Some( 7..14, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 7..14, - ), - name: "c_count", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 7..14, + ), + name: "c_count", + quote: None, + }, + ), + }, }, alias: Some( Identifier { @@ -2883,35 +2949,39 @@ Query { span: Some( 41..55, ), - distinct: false, - name: Identifier { - span: Some( - 41..44, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 45..54, + 41..44, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 45..54, + name: "sum", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 45..54, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 45..54, + ), + name: "c_acctbal", + quote: None, + }, ), - name: "c_acctbal", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, alias: Some( Identifier { @@ -2997,17 +3067,19 @@ Query { span: Some( 178..187, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 178..187, - ), - name: "c_custkey", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 178..187, + ), + name: "c_custkey", + quote: None, + }, + ), + }, }, alias: None, }, @@ -3016,35 +3088,39 @@ Query { span: Some( 213..230, ), - distinct: false, - name: Identifier { - span: Some( - 213..218, - ), - name: "count", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 219..229, + 213..218, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 219..229, + name: "count", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 219..229, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 219..229, + ), + name: "o_orderkey", + quote: None, + }, ), - name: "o_orderkey", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, alias: None, }, @@ -3071,33 +3147,37 @@ Query { span: Some( 343..352, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 343..352, - ), - name: "c_custkey", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 343..352, + ), + name: "c_custkey", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 355..364, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 355..364, - ), - name: "o_custkey", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 355..364, + ), + name: "o_custkey", + quote: None, + }, + ), + }, }, }, right: BinaryOp { @@ -3109,17 +3189,19 @@ Query { span: Some( 397..406, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 397..406, - ), - name: "o_comment", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 397..406, + ), + name: "o_comment", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -3181,17 +3263,19 @@ Query { span: Some( 479..488, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 479..488, - ), - name: "c_custkey", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 479..488, + ), + name: "c_custkey", + quote: None, + }, + ), + }, }, ], ), @@ -3228,17 +3312,19 @@ Query { span: Some( 540..547, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 540..547, - ), - name: "c_count", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 540..547, + ), + name: "c_count", + quote: None, + }, + ), + }, }, ], ), @@ -3254,17 +3340,19 @@ Query { span: Some( 569..577, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 569..577, - ), - name: "custdist", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 569..577, + ), + name: "custdist", + quote: None, + }, + ), + }, }, asc: Some( false, @@ -3278,39 +3366,43 @@ Query { span: Some( 596..603, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 596..603, - ), - name: "c_count", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 596..603, + ), + name: "c_count", + quote: None, + }, + ), + }, }, asc: Some( true, ), nulls_first: None, - }, - OrderByExpr { - expr: ColumnRef { - span: Some( - 609..619, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 609..619, - ), - name: "totacctbal", - quote: None, - }, + }, + OrderByExpr { + expr: ColumnRef { + span: Some( + 609..619, ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 609..619, + ), + name: "totacctbal", + quote: None, + }, + ), + }, }, asc: None, nulls_first: Some( @@ -3331,17 +3423,19 @@ Query { span: Some( 653..663, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 653..663, - ), - name: "totacctbal", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 653..663, + ), + name: "totacctbal", + quote: None, + }, + ), + }, }, ], offset: None, @@ -4834,17 +4928,19 @@ Query { span: Some( 42..43, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 42..43, - ), - name: "x", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 42..43, + ), + name: "x", + quote: None, + }, + ), + }, }, asc: None, nulls_first: None, @@ -4854,17 +4950,19 @@ Query { span: Some( 45..46, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 45..46, - ), - name: "y", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 45..46, + ), + name: "y", + quote: None, + }, + ), + }, }, asc: None, nulls_first: None, @@ -4954,35 +5052,39 @@ Query { span: Some( 34..45, ), - distinct: false, - name: Identifier { - span: Some( - 34..37, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 38..44, + 34..37, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 38..44, + name: "sum", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 38..44, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 38..44, + ), + name: "amount", + quote: None, + }, ), - name: "amount", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, value_column: Identifier { span: Some( @@ -5043,17 +5145,19 @@ Query { span: Some( 98..103, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 98..103, - ), - name: "empid", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 98..103, + ), + name: "empid", + quote: None, + }, + ), + }, }, asc: None, nulls_first: None, @@ -5175,17 +5279,19 @@ Query { span: Some( 90..95, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 90..95, - ), - name: "empid", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 90..95, + ), + name: "empid", + quote: None, + }, + ), + }, }, asc: None, nulls_first: None, @@ -5298,47 +5404,51 @@ Query { span: Some( 7..20, ), - distinct: false, - name: Identifier { - span: Some( - 7..10, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 11..12, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 11..12, - ), - name: "a", - quote: None, - }, + 7..10, ), + name: "sum", + quote: None, }, - ], - params: [], - window: Some( - WindowReference( - WindowRef { - window_name: Identifier { - span: Some( - 19..20, + args: [ + ColumnRef { + span: Some( + 11..12, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 11..12, + ), + name: "a", + quote: None, + }, ), - name: "w", - quote: None, }, }, + ], + params: [], + window: Some( + WindowReference( + WindowRef { + window_name: Identifier { + span: Some( + 19..20, + ), + name: "w", + quote: None, + }, + }, + ), ), - ), - lambda: None, + lambda: None, + }, }, alias: None, }, @@ -5384,37 +5494,41 @@ Query { span: Some( 61..62, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 61..62, - ), - name: "a", - quote: None, - }, - ), - }, - ], - order_by: [ - OrderByExpr { - expr: ColumnRef { - span: Some( - 72..73, - ), + column: ColumnRef { database: None, table: None, column: Name( Identifier { span: Some( - 72..73, + 61..62, ), - name: "b", + name: "a", quote: None, }, ), }, + }, + ], + order_by: [ + OrderByExpr { + expr: ColumnRef { + span: Some( + 72..73, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 72..73, + ), + name: "b", + quote: None, + }, + ), + }, + }, asc: None, nulls_first: None, }, @@ -5457,17 +5571,19 @@ Query { span: Some( 7..8, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 7..8, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 7..8, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -5476,47 +5592,51 @@ Query { span: Some( 10..23, ), - distinct: false, - name: Identifier { - span: Some( - 10..13, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 14..15, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 14..15, - ), - name: "a", - quote: None, - }, + 10..13, ), + name: "sum", + quote: None, }, - ], - params: [], - window: Some( - WindowReference( - WindowRef { - window_name: Identifier { - span: Some( - 22..23, + args: [ + ColumnRef { + span: Some( + 14..15, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 14..15, + ), + name: "a", + quote: None, + }, ), - name: "w", - quote: None, }, }, + ], + params: [], + window: Some( + WindowReference( + WindowRef { + window_name: Identifier { + span: Some( + 22..23, + ), + name: "w", + quote: None, + }, + }, + ), ), - ), - lambda: None, + lambda: None, + }, }, alias: None, }, @@ -5525,47 +5645,51 @@ Query { span: Some( 25..39, ), - distinct: false, - name: Identifier { - span: Some( - 25..28, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 29..30, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 29..30, - ), - name: "a", - quote: None, - }, + 25..28, ), + name: "sum", + quote: None, }, - ], - params: [], - window: Some( - WindowReference( - WindowRef { - window_name: Identifier { - span: Some( - 37..39, + args: [ + ColumnRef { + span: Some( + 29..30, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 29..30, + ), + name: "a", + quote: None, + }, ), - name: "w1", - quote: None, }, }, + ], + params: [], + window: Some( + WindowReference( + WindowRef { + window_name: Identifier { + span: Some( + 37..39, + ), + name: "w1", + quote: None, + }, + }, + ), ), - ), - lambda: None, + lambda: None, + }, }, alias: None, }, @@ -5574,47 +5698,51 @@ Query { span: Some( 41..55, ), - distinct: false, - name: Identifier { - span: Some( - 41..44, - ), - name: "sum", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 45..46, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 45..46, - ), - name: "a", - quote: None, - }, + 41..44, ), + name: "sum", + quote: None, }, - ], - params: [], - window: Some( - WindowReference( - WindowRef { - window_name: Identifier { - span: Some( - 53..55, + args: [ + ColumnRef { + span: Some( + 45..46, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 45..46, + ), + name: "a", + quote: None, + }, ), - name: "w2", - quote: None, }, }, + ], + params: [], + window: Some( + WindowReference( + WindowRef { + window_name: Identifier { + span: Some( + 53..55, + ), + name: "w2", + quote: None, + }, + }, + ), ), - ), - lambda: None, + lambda: None, + }, }, alias: None, }, @@ -5660,17 +5788,19 @@ Query { span: Some( 90..91, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 90..91, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 90..91, + ), + name: "a", + quote: None, + }, + ), + }, }, ], order_by: [], @@ -5731,17 +5861,19 @@ Query { span: Some( 141..142, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 141..142, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 141..142, + ), + name: "a", + quote: None, + }, + ), + }, }, asc: None, nulls_first: None, @@ -5761,17 +5893,19 @@ Query { span: Some( 153..154, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 153..154, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 153..154, + ), + name: "a", + quote: None, + }, + ), + }, }, asc: None, nulls_first: None, @@ -5876,17 +6010,19 @@ Query { span: Some( 43..44, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 43..44, - ), - name: "x", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 43..44, + ), + name: "x", + quote: None, + }, + ), + }, }, asc: None, nulls_first: None, @@ -5896,17 +6032,19 @@ Query { span: Some( 46..47, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 46..47, - ), - name: "y", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 46..47, + ), + name: "y", + quote: None, + }, + ), + }, }, asc: None, nulls_first: None, @@ -6164,17 +6302,19 @@ Query { span: Some( 42..46, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 42..46, - ), - name: "col0", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 42..46, + ), + name: "col0", + quote: None, + }, + ), + }, }, asc: None, nulls_first: None, @@ -6431,30 +6571,38 @@ Query { params: [], named_params: [ ( - "input", + Identifier { + span: Some( + 33..38, + ), + name: "input", + quote: None, + }, ColumnRef { span: Some( 42..43, ), - database: None, - table: Some( - Identifier { - span: Some( - 42..43, - ), - name: "u", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 44..47, - ), - name: "col", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 42..43, + ), + name: "u", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 44..47, + ), + name: "col", + quote: None, + }, + ), + }, }, ), ], diff --git a/src/query/ast/tests/it/testdata/statement.txt b/src/query/ast/tests/it/testdata/statement.txt index 798499a6ae654..965a97a120118 100644 --- a/src/query/ast/tests/it/testdata/statement.txt +++ b/src/query/ast/tests/it/testdata/statement.txt @@ -95,17 +95,19 @@ ShowDropTables( span: Some( 23..27, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..27, - ), - name: "name", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..27, + ), + name: "name", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -400,17 +402,19 @@ ShowProcessList { span: Some( 23..31, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..31, - ), - name: "database", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..31, + ), + name: "database", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -518,17 +522,19 @@ Explain { span: Some( 24..25, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 24..25, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 24..25, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -597,17 +603,19 @@ Explain { span: Some( 24..25, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 24..25, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 24..25, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -723,17 +731,19 @@ Explain { span: Some( 59..60, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 59..60, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 59..60, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -838,35 +848,39 @@ CreateIndex( span: Some( 40..46, ), - distinct: false, - name: Identifier { - span: Some( - 40..43, - ), - name: "SUM", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 44..45, + 40..43, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 44..45, + name: "SUM", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 44..45, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 44..45, + ), + name: "a", + quote: None, + }, ), - name: "a", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, alias: None, }, @@ -875,17 +889,19 @@ CreateIndex( span: Some( 48..49, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 48..49, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 48..49, + ), + name: "b", + quote: None, + }, + ), + }, }, alias: None, }, @@ -921,17 +937,19 @@ CreateIndex( span: Some( 64..65, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 64..65, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 64..65, + ), + name: "b", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -950,17 +968,19 @@ CreateIndex( span: Some( 79..80, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 79..80, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 79..80, + ), + name: "b", + quote: None, + }, + ), + }, }, ], ), @@ -1014,35 +1034,39 @@ CreateIndex( span: Some( 51..57, ), - distinct: false, - name: Identifier { - span: Some( - 51..54, - ), - name: "SUM", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 55..56, + 51..54, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 55..56, + name: "SUM", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 55..56, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 55..56, + ), + name: "a", + quote: None, + }, ), - name: "a", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, alias: None, }, @@ -1051,17 +1075,19 @@ CreateIndex( span: Some( 59..60, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 59..60, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 59..60, + ), + name: "b", + quote: None, + }, + ), + }, }, alias: None, }, @@ -1097,17 +1123,19 @@ CreateIndex( span: Some( 75..76, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 75..76, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 75..76, + ), + name: "b", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -1126,17 +1154,19 @@ CreateIndex( span: Some( 90..91, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 90..91, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 90..91, + ), + name: "b", + quote: None, + }, + ), + }, }, ], ), @@ -1708,59 +1738,65 @@ CreateTable( span: Some( 65..82, ), - distinct: false, - name: Identifier { - span: Some( - 65..71, - ), - name: "concat", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 72..73, + 65..71, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 72..73, + name: "concat", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 72..73, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 72..73, + ), + name: "a", + quote: None, + }, ), - name: "a", - quote: None, }, - ), - }, - Literal { - span: Some( - 75..78, - ), - lit: String( - " ", - ), - }, - ColumnRef { - span: Some( - 80..81, - ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 80..81, + }, + Literal { + span: Some( + 75..78, + ), + lit: String( + " ", + ), + }, + ColumnRef { + span: Some( + 80..81, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 80..81, + ), + name: "b", + quote: None, + }, ), - name: "b", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, ), ), @@ -1851,33 +1887,37 @@ CreateTable( span: Some( 73..74, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 73..74, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 73..74, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 77..78, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 77..78, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 77..78, + ), + name: "b", + quote: None, + }, + ), + }, }, }, ), @@ -2281,13 +2321,15 @@ CREATE DATABASE IF NOT EXISTS a CreateDatabase( CreateDatabaseStmt { create_option: CreateIfNotExists, - catalog: None, - database: Identifier { - span: Some( - 30..31, - ), - name: "a", - quote: None, + database: DatabaseRef { + catalog: None, + database: Identifier { + span: Some( + 30..31, + ), + name: "a", + quote: None, + }, }, engine: None, options: [], @@ -2304,21 +2346,23 @@ CREATE DATABASEctl.t ENGINE = DEFAULT CreateDatabase( CreateDatabaseStmt { create_option: None, - catalog: Some( - Identifier { + database: DatabaseRef { + catalog: Some( + Identifier { + span: Some( + 16..19, + ), + name: "ctl", + quote: None, + }, + ), + database: Identifier { span: Some( - 16..19, + 20..21, ), - name: "ctl", + name: "t", quote: None, }, - ), - database: Identifier { - span: Some( - 20..21, - ), - name: "t", - quote: None, }, engine: Some( Default, @@ -2337,13 +2381,15 @@ CREATE DATABASEt ENGINE = DEFAULT CreateDatabase( CreateDatabaseStmt { create_option: None, - catalog: None, - database: Identifier { - span: Some( - 16..17, - ), - name: "t", - quote: None, + database: DatabaseRef { + catalog: None, + database: Identifier { + span: Some( + 16..17, + ), + name: "t", + quote: None, + }, }, engine: Some( Default, @@ -2362,13 +2408,15 @@ CREATE DATABASEt FROM SHARE a.s CreateDatabase( CreateDatabaseStmt { create_option: None, - catalog: None, - database: Identifier { - span: Some( - 16..17, - ), - name: "t", - quote: None, + database: DatabaseRef { + catalog: None, + database: Identifier { + span: Some( + 16..17, + ), + name: "t", + quote: None, + }, }, engine: None, options: [], @@ -2390,13 +2438,15 @@ CREATE OR REPLACE DATABASEa CreateDatabase( CreateDatabaseStmt { create_option: CreateOrReplace, - catalog: None, - database: Identifier { - span: Some( - 27..28, - ), - name: "a", - quote: None, + database: DatabaseRef { + catalog: None, + database: Identifier { + span: Some( + 27..28, + ), + name: "a", + quote: None, + }, }, engine: None, options: [], @@ -2553,17 +2603,19 @@ CreateView( span: Some( 24..30, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 24..30, - ), - name: "number", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 24..30, + ), + name: "number", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -2668,21 +2720,23 @@ AlterView( span: Some( 23..29, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..29, - ), - name: "number", - quote: None, - }, - ), - }, - right: Literal { - span: Some( - 32..33, + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..29, + ), + name: "number", + quote: None, + }, + ), + }, + }, + right: Literal { + span: Some( + 32..33, ), lit: UInt64( 3, @@ -2813,17 +2867,19 @@ CreateView( span: Some( 29..35, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 29..35, - ), - name: "number", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 29..35, + ), + name: "number", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -2937,17 +2993,19 @@ CreateView( span: Some( 40..46, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 40..46, - ), - name: "number", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 40..46, + ), + name: "number", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -3060,17 +3118,19 @@ AlterView( span: Some( 28..34, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 28..34, - ), - name: "number", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 28..34, + ), + name: "number", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -4108,17 +4168,19 @@ Query( span: Some( 16..17, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 16..17, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 16..17, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -4168,17 +4230,19 @@ Query( span: Some( 41..42, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 41..42, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 41..42, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -4203,17 +4267,19 @@ Query( span: Some( 51..52, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 51..52, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 51..52, + ), + name: "b", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -4228,17 +4294,19 @@ Query( span: Some( 59..60, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 59..60, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 59..60, + ), + name: "a", + quote: None, + }, + ), + }, }, }, }, @@ -4250,17 +4318,19 @@ Query( span: Some( 70..71, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 70..71, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 70..71, + ), + name: "a", + quote: None, + }, + ), + }, }, ], ), @@ -4275,17 +4345,19 @@ Query( span: Some( 79..80, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 79..80, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 79..80, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -4655,39 +4727,41 @@ Query( span: Some( 31..35, ), - database: Some( - Identifier { - span: Some( - 31..35, - ), - name: "db", - quote: Some( - '"', - ), - }, - ), - table: Some( - Identifier { - span: Some( - 36..39, - ), - name: "a", - quote: Some( - '"', - ), - }, - ), - column: Name( - Identifier { - span: Some( - 40..44, - ), - name: "c1", - quote: Some( - '"', - ), - }, - ), + column: ColumnRef { + database: Some( + Identifier { + span: Some( + 31..35, + ), + name: "db", + quote: Some( + '"', + ), + }, + ), + table: Some( + Identifier { + span: Some( + 36..39, + ), + name: "a", + quote: Some( + '"', + ), + }, + ), + column: Name( + Identifier { + span: Some( + 40..44, + ), + name: "c1", + quote: Some( + '"', + ), + }, + ), + }, }, asc: None, nulls_first: None, @@ -4747,49 +4821,53 @@ Query( span: Some( 26..27, ), - database: None, - table: Some( - Identifier { - span: Some( - 26..27, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 28..29, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 26..27, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 28..29, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 32..33, ), - database: None, - table: Some( - Identifier { - span: Some( - 32..33, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 34..35, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 32..33, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 34..35, + ), + name: "a", + quote: None, + }, + ), + }, }, }, ), @@ -4896,49 +4974,53 @@ Query( span: Some( 37..38, ), - database: None, - table: Some( - Identifier { - span: Some( - 37..38, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 39..40, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 37..38, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 39..40, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 43..44, ), - database: None, - table: Some( - Identifier { - span: Some( - 43..44, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 45..46, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 43..44, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 45..46, + ), + name: "a", + quote: None, + }, + ), + }, }, }, ), @@ -5045,49 +5127,53 @@ Query( span: Some( 38..39, ), - database: None, - table: Some( - Identifier { - span: Some( - 38..39, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 40..41, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 38..39, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 40..41, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 44..45, ), - database: None, - table: Some( - Identifier { - span: Some( - 44..45, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 46..47, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 44..45, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 46..47, + ), + name: "a", + quote: None, + }, + ), + }, }, }, ), @@ -5194,65 +5280,69 @@ Query( span: Some( 36..37, ), - database: None, - table: Some( - Identifier { - span: Some( - 36..37, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 38..39, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 36..37, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 38..39, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 42..43, ), - database: None, - table: Some( - Identifier { - span: Some( - 42..43, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 44..45, - ), - name: "a", - quote: None, - }, - ), - }, - }, - ), - left: Table { - span: Some( - 14..15, - ), - catalog: None, - database: None, - table: Identifier { - span: Some( - 14..15, - ), - name: "a", - quote: None, - }, + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 42..43, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 44..45, + ), + name: "a", + quote: None, + }, + ), + }, + }, + }, + ), + left: Table { + span: Some( + 14..15, + ), + catalog: None, + database: None, + table: Identifier { + span: Some( + 14..15, + ), + name: "a", + quote: None, + }, alias: None, travel_point: None, since_point: None, @@ -5343,49 +5433,53 @@ Query( span: Some( 31..32, ), - database: None, - table: Some( - Identifier { - span: Some( - 31..32, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 33..34, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 31..32, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 33..34, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 37..38, ), - database: None, - table: Some( - Identifier { - span: Some( - 37..38, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 39..40, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 37..38, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 39..40, + ), + name: "a", + quote: None, + }, + ), + }, }, }, ), @@ -5492,49 +5586,53 @@ Query( span: Some( 36..37, ), - database: None, - table: Some( - Identifier { - span: Some( - 36..37, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 38..39, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 36..37, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 38..39, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 42..43, ), - database: None, - table: Some( - Identifier { - span: Some( - 42..43, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 44..45, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 42..43, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 44..45, + ), + name: "a", + quote: None, + }, + ), + }, }, }, ), @@ -5641,49 +5739,53 @@ Query( span: Some( 31..32, ), - database: None, - table: Some( - Identifier { - span: Some( - 31..32, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 33..34, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 31..32, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 33..34, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 37..38, ), - database: None, - table: Some( - Identifier { - span: Some( - 37..38, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 39..40, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 37..38, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 39..40, + ), + name: "a", + quote: None, + }, + ), + }, }, }, ), @@ -5790,49 +5892,53 @@ Query( span: Some( 37..38, ), - database: None, - table: Some( - Identifier { - span: Some( - 37..38, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 39..40, - ), - name: "a", - quote: None, - }, - ), - }, - right: ColumnRef { - span: Some( - 43..44, - ), - database: None, - table: Some( - Identifier { - span: Some( - 43..44, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 45..46, - ), - name: "a", - quote: None, - }, + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 37..38, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 39..40, + ), + name: "a", + quote: None, + }, + ), + }, + }, + right: ColumnRef { + span: Some( + 43..44, ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 43..44, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 45..46, + ), + name: "a", + quote: None, + }, + ), + }, }, }, ), @@ -5939,49 +6045,53 @@ Query( span: Some( 37..38, ), - database: None, - table: Some( - Identifier { - span: Some( - 37..38, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 39..40, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 37..38, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 39..40, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 43..44, ), - database: None, - table: Some( - Identifier { - span: Some( - 43..44, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 45..46, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 43..44, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 45..46, + ), + name: "a", + quote: None, + }, + ), + }, }, }, ), @@ -6088,49 +6198,53 @@ Query( span: Some( 37..38, ), - database: None, - table: Some( - Identifier { - span: Some( - 37..38, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 39..40, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 37..38, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 39..40, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 43..44, ), - database: None, - table: Some( - Identifier { - span: Some( - 43..44, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 45..46, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 43..44, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 45..46, + ), + name: "a", + quote: None, + }, + ), + }, }, }, ), @@ -6237,63 +6351,67 @@ Query( span: Some( 32..33, ), - database: None, - table: Some( - Identifier { - span: Some( - 32..33, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 34..35, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 32..33, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 34..35, + ), + name: "a", + quote: None, + }, + ), + }, }, right: ColumnRef { span: Some( 38..39, ), - database: None, - table: Some( - Identifier { - span: Some( - 38..39, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 40..41, - ), - name: "a", - quote: None, - }, - ), - }, - }, - ), - left: Table { - span: Some( - 14..15, - ), - catalog: None, - database: None, - table: Identifier { - span: Some( - 14..15, - ), - name: "a", + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 38..39, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 40..41, + ), + name: "a", + quote: None, + }, + ), + }, + }, + }, + ), + left: Table { + span: Some( + 14..15, + ), + catalog: None, + database: None, + table: Identifier { + span: Some( + 14..15, + ), + name: "a", quote: None, }, alias: None, @@ -6816,25 +6934,27 @@ Query( span: Some( 22..23, ), - database: None, - table: Some( - Identifier { - span: Some( - 22..23, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 24..25, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 22..23, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 24..25, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Subquery { span: Some( @@ -6861,25 +6981,27 @@ Query( span: Some( 40..41, ), - database: None, - table: Some( - Identifier { - span: Some( - 40..41, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 42..43, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 40..41, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 42..43, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -6995,25 +7117,27 @@ Query( span: Some( 22..23, ), - database: None, - table: Some( - Identifier { - span: Some( - 22..23, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 24..25, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 22..23, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 24..25, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Subquery { span: Some( @@ -7040,25 +7164,27 @@ Query( span: Some( 40..41, ), - database: None, - table: Some( - Identifier { - span: Some( - 40..41, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 42..43, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 40..41, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 42..43, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -7174,25 +7300,27 @@ Query( span: Some( 22..23, ), - database: None, - table: Some( - Identifier { - span: Some( - 22..23, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 24..25, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 22..23, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 24..25, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Subquery { span: Some( @@ -7219,25 +7347,27 @@ Query( span: Some( 41..42, ), - database: None, - table: Some( - Identifier { - span: Some( - 41..42, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 43..44, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 41..42, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 43..44, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -7353,25 +7483,27 @@ Query( span: Some( 22..23, ), - database: None, - table: Some( - Identifier { - span: Some( - 22..23, - ), - name: "a", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 24..25, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 22..23, + ), + name: "a", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 24..25, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Subquery { span: Some( @@ -7396,25 +7528,27 @@ Query( span: Some( 36..37, ), - database: None, - table: Some( - Identifier { - span: Some( - 36..37, - ), - name: "b", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 38..39, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 36..37, + ), + name: "b", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 38..39, + ), + name: "a", + quote: None, + }, + ), + }, }, alias: None, }, @@ -7650,7 +7784,13 @@ Query( ], named_params: [ ( - "prune_page", + Identifier { + span: Some( + 45..55, + ), + name: "prune_page", + quote: None, + }, Literal { span: Some( 59..63, @@ -7661,7 +7801,13 @@ Query( }, ), ( - "refresh_meta_cache", + Identifier { + span: Some( + 65..83, + ), + name: "refresh_meta_cache", + quote: None, + }, Literal { span: Some( 87..91, @@ -8123,27 +8269,29 @@ Query( span: Some( 7..38, ), - distinct: false, - name: Identifier { - span: Some( - 7..17, - ), - name: "parse_json", - quote: None, - }, - args: [ - Literal { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 18..37, - ), - lit: String( - "{\"k1\": [0, 1, 2]}", + 7..17, ), + name: "parse_json", + quote: None, }, - ], - params: [], - window: None, - lambda: None, + args: [ + Literal { + span: Some( + 18..37, + ), + lit: String( + "{\"k1\": [0, 1, 2]}", + ), + }, + ], + params: [], + window: None, + lambda: None, + }, }, accessor: Colon { key: Identifier { @@ -8662,17 +8810,19 @@ AlterTable( span: Some( 25..27, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 25..27, - ), - name: "c1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 25..27, + ), + name: "c1", + quote: None, + }, + ), + }, }, ], }, @@ -8751,17 +8901,19 @@ AlterTable( span: Some( 36..38, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 36..38, - ), - name: "c1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 36..38, + ), + name: "c1", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -11632,17 +11784,19 @@ ShowSettings { span: Some( 20..24, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 20..24, - ), - name: "name", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 20..24, + ), + name: "name", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -11703,17 +11857,19 @@ ShowFunctions { span: Some( 21..25, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 21..25, - ), - name: "name", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 21..25, + ), + name: "name", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -11774,17 +11930,19 @@ ShowEngines { span: Some( 19..25, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 19..25, - ), - name: "engine", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 19..25, + ), + name: "engine", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -11845,17 +12003,19 @@ ShowMetrics { span: Some( 19..25, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 19..25, - ), - name: "metric", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 19..25, + ), + name: "metric", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -11916,17 +12076,19 @@ ShowTableFunctions { span: Some( 27..31, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 27..31, - ), - name: "name", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 27..31, + ), + name: "name", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -11987,17 +12149,19 @@ ShowIndexes { span: Some( 19..23, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 19..23, - ), - name: "name", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 19..23, + ), + name: "name", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -12910,17 +13074,19 @@ Update( span: Some( 23..24, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..24, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..24, + ), + name: "a", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -12960,17 +13126,19 @@ Update( span: Some( 42..43, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 42..43, - ), - name: "c", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 42..43, + ), + name: "c", + quote: None, + }, + ), + }, }, right: Literal { span: Some( @@ -13123,17 +13291,19 @@ Query( span: Some( 7..9, ), - database: None, - table: None, - column: Position( - ColumnPosition { - span: Some( - 7..9, - ), - pos: 1, - name: "$1", - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Position( + ColumnPosition { + span: Some( + 7..9, + ), + pos: 1, + name: "$1", + }, + ), + }, }, alias: None, }, @@ -13195,25 +13365,27 @@ Query( span: Some( 7..8, ), - database: None, - table: Some( - Identifier { - span: Some( - 7..8, - ), - name: "t", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 9..11, - ), - name: "c1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 7..8, + ), + name: "t", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 9..11, + ), + name: "c1", + quote: None, + }, + ), + }, }, alias: None, }, @@ -13294,25 +13466,27 @@ Query( span: Some( 7..13, ), - database: None, - table: Some( - Identifier { - span: Some( - 7..13, - ), - name: "table0", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 14..16, - ), - name: "c1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 7..13, + ), + name: "table0", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 14..16, + ), + name: "c1", + quote: None, + }, + ), + }, }, alias: None, }, @@ -13321,25 +13495,27 @@ Query( span: Some( 18..24, ), - database: None, - table: Some( - Identifier { - span: Some( - 18..24, - ), - name: "table1", - quote: None, - }, - ), - column: Name( - Identifier { - span: Some( - 25..27, - ), - name: "c2", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: Some( + Identifier { + span: Some( + 18..24, + ), + name: "table1", + quote: None, + }, + ), + column: Name( + Identifier { + span: Some( + 25..27, + ), + name: "c2", + quote: None, + }, + ), + }, }, alias: None, }, @@ -13446,17 +13622,19 @@ Query( span: Some( 7..9, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 7..9, - ), - name: "c1", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 7..9, + ), + name: "c1", + quote: None, + }, + ), + }, }, alias: None, }, @@ -13636,17 +13814,19 @@ Query( span: Some( 40..41, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 40..41, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 40..41, + ), + name: "a", + quote: None, + }, + ), + }, }, ], [ @@ -13654,17 +13834,19 @@ Query( span: Some( 43..44, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 43..44, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 43..44, + ), + name: "b", + quote: None, + }, + ), + }, }, ], [ @@ -13672,17 +13854,19 @@ Query( span: Some( 46..47, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 46..47, - ), - name: "c", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 46..47, + ), + name: "c", + quote: None, + }, + ), + }, }, ], [ @@ -13690,17 +13874,19 @@ Query( span: Some( 49..50, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 49..50, - ), - name: "d", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 49..50, + ), + name: "d", + quote: None, + }, + ), + }, }, ], ], @@ -13779,17 +13965,19 @@ Query( span: Some( 40..41, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 40..41, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 40..41, + ), + name: "a", + quote: None, + }, + ), + }, }, ], [ @@ -13797,17 +13985,19 @@ Query( span: Some( 43..44, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 43..44, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 43..44, + ), + name: "b", + quote: None, + }, + ), + }, }, ], [ @@ -13815,33 +14005,37 @@ Query( span: Some( 47..48, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 47..48, - ), - name: "c", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 47..48, + ), + name: "c", + quote: None, + }, + ), + }, }, ColumnRef { span: Some( 50..51, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 50..51, - ), - name: "d", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 50..51, + ), + name: "d", + quote: None, + }, + ), + }, }, ], ], @@ -13920,33 +14114,37 @@ Query( span: Some( 41..42, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 41..42, - ), - name: "a", - quote: None, - }, - ), - }, - ColumnRef { - span: Some( + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 41..42, + ), + name: "a", + quote: None, + }, + ), + }, + }, + ColumnRef { + span: Some( 44..45, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 44..45, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 44..45, + ), + name: "b", + quote: None, + }, + ), + }, }, ], [ @@ -13954,17 +14152,19 @@ Query( span: Some( 49..50, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 49..50, - ), - name: "c", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 49..50, + ), + name: "c", + quote: None, + }, + ), + }, }, ], [ @@ -13972,33 +14172,37 @@ Query( span: Some( 54..55, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 54..55, - ), - name: "d", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 54..55, + ), + name: "d", + quote: None, + }, + ), + }, }, ColumnRef { span: Some( 57..58, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 57..58, - ), - name: "e", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 57..58, + ), + name: "e", + quote: None, + }, + ), + }, }, ], ], @@ -14077,33 +14281,37 @@ Query( span: Some( 41..42, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 41..42, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 41..42, + ), + name: "a", + quote: None, + }, + ), + }, }, ColumnRef { span: Some( 44..45, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 44..45, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 44..45, + ), + name: "b", + quote: None, + }, + ), + }, }, ], [], @@ -14112,33 +14320,37 @@ Query( span: Some( 53..54, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 53..54, - ), - name: "d", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 53..54, + ), + name: "d", + quote: None, + }, + ), + }, }, ColumnRef { span: Some( 56..57, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 56..57, - ), - name: "e", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 56..57, + ), + name: "e", + quote: None, + }, + ), + }, }, ], ], @@ -14216,49 +14428,55 @@ Query( span: Some( 31..32, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 31..32, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 31..32, + ), + name: "a", + quote: None, + }, + ), + }, }, ColumnRef { span: Some( 34..35, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 34..35, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 34..35, + ), + name: "b", + quote: None, + }, + ), + }, }, ColumnRef { span: Some( 37..38, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 37..38, - ), - name: "c", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 37..38, + ), + name: "c", + quote: None, + }, + ), + }, }, ], ), @@ -14335,49 +14553,55 @@ Query( span: Some( 33..34, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 33..34, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 33..34, + ), + name: "a", + quote: None, + }, + ), + }, }, ColumnRef { span: Some( 36..37, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 36..37, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 36..37, + ), + name: "b", + quote: None, + }, + ), + }, }, ColumnRef { span: Some( 39..40, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 39..40, - ), - name: "c", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 39..40, + ), + name: "c", + quote: None, + }, + ), + }, }, ], ), @@ -14426,18 +14650,20 @@ CreateDatamaskPolicy( span: Some( 77..91, ), - distinct: false, - name: Identifier { - span: Some( - 77..89, - ), - name: "current_role", - quote: None, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 77..89, + ), + name: "current_role", + quote: None, + }, + args: [], + params: [], + window: None, + lambda: None, }, - args: [], - params: [], - window: None, - lambda: None, }, list: [ Literal { @@ -14457,17 +14683,19 @@ CreateDatamaskPolicy( span: Some( 112..115, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 112..115, - ), - name: "VAL", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 112..115, + ), + name: "VAL", + quote: None, + }, + ), + }, }, ], else_result: Some( @@ -14520,18 +14748,20 @@ CreateDatamaskPolicy( span: Some( 88..102, ), - distinct: false, - name: Identifier { - span: Some( - 88..100, - ), - name: "current_role", - quote: None, + func: FunctionCall { + distinct: false, + name: Identifier { + span: Some( + 88..100, + ), + name: "current_role", + quote: None, + }, + args: [], + params: [], + window: None, + lambda: None, }, - args: [], - params: [], - window: None, - lambda: None, }, list: [ Literal { @@ -14551,17 +14781,19 @@ CreateDatamaskPolicy( span: Some( 123..126, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 123..126, - ), - name: "VAL", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 123..126, + ), + name: "VAL", + quote: None, + }, + ), + }, }, ], else_result: Some( @@ -14638,17 +14870,19 @@ CreateVirtualColumn( span: Some( 23..24, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 23..24, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 23..24, + ), + name: "a", + quote: None, + }, + ), + }, }, accessor: Bracket { key: Literal { @@ -14684,17 +14918,19 @@ CreateVirtualColumn( span: Some( 38..39, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 38..39, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 38..39, + ), + name: "b", + quote: None, + }, + ), + }, }, accessor: Bracket { key: Literal { @@ -14753,17 +14989,19 @@ CreateVirtualColumn( span: Some( 34..35, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 34..35, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 34..35, + ), + name: "a", + quote: None, + }, + ), + }, }, accessor: Bracket { key: Literal { @@ -14799,17 +15037,19 @@ CreateVirtualColumn( span: Some( 49..50, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 49..50, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 49..50, + ), + name: "b", + quote: None, + }, + ), + }, }, accessor: Bracket { key: Literal { @@ -14868,17 +15108,19 @@ AlterVirtualColumn( span: Some( 22..23, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 22..23, - ), - name: "a", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 22..23, + ), + name: "a", + quote: None, + }, + ), + }, }, accessor: Bracket { key: Literal { @@ -14914,17 +15156,19 @@ AlterVirtualColumn( span: Some( 37..38, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 37..38, - ), - name: "b", - quote: None, - }, - ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 37..38, + ), + name: "b", + quote: None, + }, + ), + }, }, accessor: Bracket { key: Literal { @@ -16171,35 +16415,39 @@ CreateUDF( span: Some( 54..64, ), - distinct: false, - name: Identifier { - span: Some( - 54..61, - ), - name: "is_null", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 62..63, + 54..61, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 62..63, + name: "is_null", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 62..63, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 62..63, + ), + name: "p", + quote: None, + }, ), - name: "p", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, }, }, @@ -16244,35 +16492,39 @@ CreateUDF( span: Some( 64..74, ), - distinct: false, - name: Identifier { - span: Some( - 64..71, - ), - name: "is_null", - quote: None, - }, - args: [ - ColumnRef { + func: FunctionCall { + distinct: false, + name: Identifier { span: Some( - 72..73, + 64..71, ), - database: None, - table: None, - column: Name( - Identifier { - span: Some( - 72..73, + name: "is_null", + quote: None, + }, + args: [ + ColumnRef { + span: Some( + 72..73, + ), + column: ColumnRef { + database: None, + table: None, + column: Name( + Identifier { + span: Some( + 72..73, + ), + name: "p", + quote: None, + }, ), - name: "p", - quote: None, }, - ), - }, - ], - params: [], - window: None, - lambda: None, + }, + ], + params: [], + window: None, + lambda: None, + }, }, }, }, diff --git a/src/query/constraint/tests/it/parser.rs b/src/query/constraint/tests/it/parser.rs index ce14f597d1d43..4b7f288c29f2b 100644 --- a/src/query/constraint/tests/it/parser.rs +++ b/src/query/constraint/tests/it/parser.rs @@ -16,7 +16,9 @@ use std::collections::HashMap; use databend_common_ast::ast::BinaryOperator as ASTBinaryOperator; use databend_common_ast::ast::ColumnID; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr as ASTExpr; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Literal; use databend_common_ast::ast::UnaryOperator as ASTUnaryOperator; @@ -52,11 +54,15 @@ fn sql_ast_to_mir(ast: ASTExpr, variables: &HashMap) -> Opt Some(MirExpr::Constant(constant)) } ASTExpr::ColumnRef { - database: None, - table: None, - column: ColumnID::Name(Identifier { - name, quote: None, .. - }), + column: + ColumnRef { + database: None, + table: None, + column: + ColumnID::Name(Identifier { + name, quote: None, .. + }), + }, .. } => Some(MirExpr::Variable { data_type: variables[&name], @@ -154,13 +160,15 @@ fn mir_to_sql_ast(expr: &MirExpr) -> ASTExpr { } MirExpr::Variable { name, .. } => ASTExpr::ColumnRef { span: None, - database: None, - table: None, - column: ColumnID::Name(Identifier { - span: None, - name: name.clone(), - quote: None, - }), + column: ColumnRef { + database: None, + table: None, + column: ColumnID::Name(Identifier { + span: None, + name: name.clone(), + quote: None, + }), + }, }, MirExpr::UnaryOperator { op, arg } => { let op = match op { @@ -189,16 +197,18 @@ fn mir_to_sql_ast(expr: &MirExpr) -> ASTExpr { MirUnaryOperator::RemoveNullable => { return ASTExpr::FunctionCall { span: None, - distinct: false, - name: Identifier { - name: "remove_nullable".to_string(), - quote: None, - span: None, + func: FunctionCall { + distinct: false, + name: Identifier { + name: "remove_nullable".to_string(), + quote: None, + span: None, + }, + args: vec![mir_to_sql_ast(arg)], + params: vec![], + window: None, + lambda: None, }, - args: vec![mir_to_sql_ast(arg)], - params: vec![], - window: None, - lambda: None, }; } }; diff --git a/src/query/functions/tests/it/scalars/parser.rs b/src/query/functions/tests/it/scalars/parser.rs index 9cab98300df62..56f8c843d496b 100644 --- a/src/query/functions/tests/it/scalars/parser.rs +++ b/src/query/functions/tests/it/scalars/parser.rs @@ -13,7 +13,9 @@ // limitations under the License. use databend_common_ast::ast::BinaryOperator; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr as AExpr; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::IntervalKind; use databend_common_ast::ast::Literal as ASTLiteral; use databend_common_ast::ast::MapAccessor; @@ -100,9 +102,12 @@ pub fn transform_expr(ast: AExpr, columns: &[(&str, DataType)]) -> RawExpr { }, AExpr::ColumnRef { span, - database: None, - table: None, - column, + column: + ColumnRef { + database: None, + table: None, + column, + }, } => { let col_id = columns .iter() @@ -139,9 +144,9 @@ pub fn transform_expr(ast: AExpr, columns: &[(&str, DataType)]) -> RawExpr { }, AExpr::FunctionCall { span, - name, - args, - params, + func: FunctionCall { + name, args, params, .. + }, .. } => RawExpr::FunctionCall { span, diff --git a/src/query/sql/src/planner/binder/aggregate.rs b/src/query/sql/src/planner/binder/aggregate.rs index 0676bd526463e..128187bd86eb3 100644 --- a/src/query/sql/src/planner/binder/aggregate.rs +++ b/src/query/sql/src/planner/binder/aggregate.rs @@ -17,6 +17,7 @@ use std::collections::HashMap; use std::collections::HashSet; use std::sync::Arc; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr; use databend_common_ast::ast::GroupBy; use databend_common_ast::ast::Literal; @@ -774,9 +775,12 @@ impl Binder { // Alias of the select item let col_name = column_binding.column_name.as_str(); if let Expr::ColumnRef { - column, - database: None, - table: None, + column: + ColumnRef { + database: None, + table: None, + column, + }, .. } = expr { diff --git a/src/query/sql/src/planner/binder/copy_into_table.rs b/src/query/sql/src/planner/binder/copy_into_table.rs index 136f96c58f8c4..f31f1d17e91a7 100644 --- a/src/query/sql/src/planner/binder/copy_into_table.rs +++ b/src/query/sql/src/planner/binder/copy_into_table.rs @@ -17,6 +17,7 @@ use std::str::FromStr; use std::sync::Arc; use databend_common_ast::ast::ColumnID as AstColumnID; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::CopyIntoTableSource; use databend_common_ast::ast::CopyIntoTableStmt; use databend_common_ast::ast::Expr; @@ -186,9 +187,13 @@ impl<'a> Binder { for dest_field in plan.required_source_schema.fields().iter() { let column = Expr::ColumnRef { span: None, - database: None, - table: None, - column: AstColumnID::Name(Identifier::from_name(dest_field.name().to_string())), + column: ColumnRef { + database: None, + table: None, + column: AstColumnID::Name(Identifier::from_name( + dest_field.name().to_string(), + )), + }, }; // cast types to variant, tuple will be rewrite as `json_object_keep_null` let expr = if dest_field.data_type().remove_nullable() == DataType::Variant { diff --git a/src/query/sql/src/planner/binder/ddl/database.rs b/src/query/sql/src/planner/binder/ddl/database.rs index 6d871b8408f80..5d7b8d22d9c3b 100644 --- a/src/query/sql/src/planner/binder/ddl/database.rs +++ b/src/query/sql/src/planner/binder/ddl/database.rs @@ -18,6 +18,7 @@ use databend_common_ast::ast::AlterDatabaseAction; use databend_common_ast::ast::AlterDatabaseStmt; use databend_common_ast::ast::CreateDatabaseStmt; use databend_common_ast::ast::DatabaseEngine; +use databend_common_ast::ast::DatabaseRef; use databend_common_ast::ast::DropDatabaseStmt; use databend_common_ast::ast::SQLProperty; use databend_common_ast::ast::ShowCreateDatabaseStmt; @@ -208,8 +209,7 @@ impl Binder { ) -> Result { let CreateDatabaseStmt { create_option, - catalog, - database, + database: DatabaseRef { catalog, database }, engine, options, from_share, diff --git a/src/query/sql/src/planner/binder/ddl/virtual_column.rs b/src/query/sql/src/planner/binder/ddl/virtual_column.rs index 4d2bfc40e496a..330fa572abe5a 100644 --- a/src/query/sql/src/planner/binder/ddl/virtual_column.rs +++ b/src/query/sql/src/planner/binder/ddl/virtual_column.rs @@ -228,14 +228,14 @@ impl Binder { )); } if let Expr::ColumnRef { column, .. } = expr { - if let Ok(field) = schema.field_with_name(column.name()) { + if let Ok(field) = schema.field_with_name(column.column.name()) { if field.data_type().remove_nullable() != TableDataType::Variant { return Err(ErrorCode::SemanticError( "Virtual Column only support Variant data type", )); } let mut virtual_name = String::new(); - virtual_name.push_str(column.name()); + virtual_name.push_str(column.column.name()); for path in paths { virtual_name.push('['); match path { diff --git a/src/query/sql/src/planner/binder/project.rs b/src/query/sql/src/planner/binder/project.rs index 64d3ab9d32ead..53758152c6967 100644 --- a/src/query/sql/src/planner/binder/project.rs +++ b/src/query/sql/src/planner/binder/project.rs @@ -19,7 +19,9 @@ use std::sync::Arc; use databend_common_ast::ast::walk_expr_mut; use databend_common_ast::ast::ColumnFilter; use databend_common_ast::ast::ColumnID; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Indirection; use databend_common_ast::ast::Literal; @@ -260,7 +262,11 @@ impl Binder { let expr_name = match (expr.as_ref(), alias) { ( Expr::ColumnRef { - column: ColumnID::Name(column), + column: + ColumnRef { + column: ColumnID::Name(column), + .. + }, .. }, None, @@ -474,13 +480,15 @@ impl Binder { }; let expr = Expr::FunctionCall { - name: Identifier::from_name("array_apply"), - args: vec![input_array], - lambda: lambda.cloned(), span, - distinct: false, - params: vec![], - window: None, + func: FunctionCall { + name: Identifier::from_name("array_apply"), + args: vec![input_array], + lambda: lambda.cloned(), + distinct: false, + params: vec![], + window: None, + }, }; let mut temp_ctx = BindContext::new(); diff --git a/src/query/sql/src/planner/binder/project_set.rs b/src/query/sql/src/planner/binder/project_set.rs index b14199b131783..f09b62f3a8bce 100644 --- a/src/query/sql/src/planner/binder/project_set.rs +++ b/src/query/sql/src/planner/binder/project_set.rs @@ -15,6 +15,7 @@ use std::sync::Arc; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::FunctionCall as ASTFunctionCall; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Lambda; use databend_common_ast::ast::Visitor; @@ -63,12 +64,14 @@ impl<'a> Visitor<'a> for SrfCollector { // Collect the srf self.srfs.push(Expr::FunctionCall { span, - distinct, - name: name.clone(), - args: args.to_vec(), - params: params.to_vec(), - window: over.clone(), - lambda: lambda.clone(), + func: ASTFunctionCall { + distinct, + name: name.clone(), + args: args.to_vec(), + params: params.to_vec(), + window: over.clone(), + lambda: lambda.clone(), + }, }); } else { for arg in args.iter() { @@ -110,7 +113,10 @@ impl Binder { let mut items = Vec::with_capacity(srfs.len()); for srf in srfs { let (name, srf_scalar) = match srf { - Expr::FunctionCall { name, args, .. } => { + Expr::FunctionCall { + func: ASTFunctionCall { name, args, .. }, + .. + } => { let name = normalize_identifier(name, &self.name_resolution_ctx).to_string(); let original_context = bind_context.expr_context.clone(); diff --git a/src/query/sql/src/planner/binder/select.rs b/src/query/sql/src/planner/binder/select.rs index 7c435a66b7b33..d9313ebc31730 100644 --- a/src/query/sql/src/planner/binder/select.rs +++ b/src/query/sql/src/planner/binder/select.rs @@ -20,8 +20,10 @@ use async_recursion::async_recursion; use databend_common_ast::ast::BinaryOperator; use databend_common_ast::ast::ColumnID; use databend_common_ast::ast::ColumnPosition; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr; use databend_common_ast::ast::Expr::Array; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::GroupBy; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Join; @@ -943,7 +945,10 @@ impl<'a> SelectRewriter<'a> { } fn parse_aggregate_function(expr: &Expr) -> Result<(&Identifier, &[Expr])> { match expr { - Expr::FunctionCall { name, args, .. } => Ok((name, args)), + Expr::FunctionCall { + func: FunctionCall { name, args, .. }, + .. + } => Ok((name, args)), _ => Err(ErrorCode::SyntaxException("Aggregate function is required")), } } @@ -960,10 +965,12 @@ impl<'a> SelectRewriter<'a> { Expr::BinaryOp { span: None, left: Box::new(Expr::ColumnRef { - column: ColumnID::Name(col), span: None, - database: None, - table: None, + column: ColumnRef { + database: None, + table: None, + column: ColumnID::Name(col), + }, }), op: BinaryOperator::Eq, right: Box::new(value), @@ -978,12 +985,14 @@ impl<'a> SelectRewriter<'a> { SelectTarget::AliasedExpr { expr: Box::new(Expr::FunctionCall { span: Span::default(), - distinct: false, - name, - args, - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name, + args, + params: vec![], + window: None, + lambda: None, + }, }), alias, } @@ -1009,9 +1018,11 @@ impl<'a> SelectRewriter<'a> { .into_iter() .map(|expr| Expr::ColumnRef { span: None, - column: ColumnID::Name(expr), - database: None, - table: None, + column: ColumnRef { + database: None, + table: None, + column: ColumnID::Name(expr), + }, }) .collect(), } @@ -1060,7 +1071,7 @@ impl<'a> SelectRewriter<'a> { .ok_or_else(|| ErrorCode::SyntaxException("Aggregate column not found"))?; let aggregate_column_names = aggregate_columns .iter() - .map(|col| col.name()) + .map(|col| col.column.name()) .collect::>(); let new_group_by = stmt.group_by.clone().unwrap_or_else(|| { GroupBy::Normal( @@ -1085,7 +1096,7 @@ impl<'a> SelectRewriter<'a> { if let Some(star) = new_select_list.iter_mut().find(|target| target.is_star()) { let mut exclude_columns: Vec<_> = aggregate_columns .iter() - .map(|c| Identifier::from_name(c.name())) + .map(|c| Identifier::from_name(c.column.name())) .collect(); exclude_columns.push(pivot.value_column.clone()); star.exclude(exclude_columns); diff --git a/src/query/sql/src/planner/binder/stage.rs b/src/query/sql/src/planner/binder/stage.rs index d18c31ff48b5b..221b1e4b39218 100644 --- a/src/query/sql/src/planner/binder/stage.rs +++ b/src/query/sql/src/planner/binder/stage.rs @@ -69,7 +69,7 @@ impl BindContext { for (i, expr) in exprs.iter().enumerate() { // `DEFAULT` in insert values will be parsed as `Expr::ColumnRef`. if let AExpr::ColumnRef { column, .. } = expr { - if column.name().eq_ignore_ascii_case("default") { + if column.column.name().eq_ignore_ascii_case("default") { let field = schema.field(i); map_exprs.push(scalar_binder.get_default_value(field, schema).await?); continue; diff --git a/src/query/sql/src/planner/binder/table.rs b/src/query/sql/src/planner/binder/table.rs index 65c7d409eadae..3a492b3dea1bb 100644 --- a/src/query/sql/src/planner/binder/table.rs +++ b/src/query/sql/src/planner/binder/table.rs @@ -25,6 +25,7 @@ use dashmap::DashMap; use databend_common_ast::ast::Connection; use databend_common_ast::ast::Expr; use databend_common_ast::ast::FileLocation; +use databend_common_ast::ast::FunctionCall as ASTFunctionCall; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Indirection; use databend_common_ast::ast::Join; @@ -578,12 +579,14 @@ impl Binder { // convert lateral join table function to srf function let srf = Expr::FunctionCall { span: *span, - distinct: false, - name: func_name.clone(), - args, - params: vec![], - window: None, - lambda: None, + func: ASTFunctionCall { + distinct: false, + name: func_name.clone(), + args, + params: vec![], + window: None, + lambda: None, + }, }; let srfs = vec![srf.clone()]; let srf_expr = self @@ -662,7 +665,7 @@ impl Binder { span: &Span, name: &Identifier, params: &[Expr], - named_params: &[(String, Expr)], + named_params: &[(Identifier, Expr)], alias: &Option, ) -> Result<(SExpr, BindContext)> { let func_name = normalize_identifier(name, &self.name_resolution_ctx); @@ -682,16 +685,18 @@ impl Binder { select_list: vec![SelectTarget::AliasedExpr { expr: Box::new(databend_common_ast::ast::Expr::FunctionCall { span: *span, - distinct: false, - name: databend_common_ast::ast::Identifier { - span: *span, - name: func_name.name.clone(), - quote: None, + func: ASTFunctionCall { + distinct: false, + name: databend_common_ast::ast::Identifier { + span: *span, + name: func_name.name.clone(), + quote: None, + }, + params: vec![], + args, + window: None, + lambda: None, }, - params: vec![], - args, - window: None, - lambda: None, }), alias: None, }], @@ -1519,13 +1524,13 @@ fn parse_table_function_args( span: &Span, func_name: &Identifier, params: &[Expr], - named_params: &[(String, Expr)], + named_params: &[(Identifier, Expr)], ) -> Result> { if func_name.name.eq_ignore_ascii_case("flatten") { // build flatten function arguments. let mut named_args: HashMap = named_params .iter() - .map(|(name, value)| (name.to_lowercase(), value.clone())) + .map(|(name, value)| (name.name.to_lowercase(), value.clone())) .collect::>(); let mut args = Vec::with_capacity(named_args.len() + params.len()); @@ -1559,7 +1564,7 @@ fn parse_table_function_args( if !named_params.is_empty() { let invalid_names = named_params .iter() - .map(|(name, _)| name.clone()) + .map(|(name, _)| name.name.clone()) .collect::>() .join(", "); return Err(ErrorCode::InvalidArgument(format!( diff --git a/src/query/sql/src/planner/binder/table_args.rs b/src/query/sql/src/planner/binder/table_args.rs index 8693f1a5a65c5..8cc8375e75f24 100644 --- a/src/query/sql/src/planner/binder/table_args.rs +++ b/src/query/sql/src/planner/binder/table_args.rs @@ -15,6 +15,7 @@ use std::collections::HashMap; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::Identifier; use databend_common_catalog::table_args::TableArgs; use databend_common_exception::ErrorCode; use databend_common_exception::Result; @@ -30,7 +31,7 @@ use crate::ScalarExpr; pub async fn bind_table_args( scalar_binder: &mut ScalarBinder<'_>, params: &[Expr], - named_params: &[(String, Expr)], + named_params: &[(Identifier, Expr)], ) -> Result { let mut args = Vec::with_capacity(params.len()); for arg in params.iter() { @@ -61,7 +62,7 @@ pub async fn bind_table_args( let named_args: HashMap = named_args .into_iter() .map(|(name, scalar)| match scalar { - ScalarExpr::ConstantExpr(ConstantExpr { value, .. }) => Ok((name, value)), + ScalarExpr::ConstantExpr(ConstantExpr { value, .. }) => Ok((name.name.clone(), value)), _ => Err(ErrorCode::Unimplemented(format!( "Unsupported table named argument type: {:?}", scalar diff --git a/src/query/sql/src/planner/dataframe.rs b/src/query/sql/src/planner/dataframe.rs index b8ab7726dece4..ea449136b0083 100644 --- a/src/query/sql/src/planner/dataframe.rs +++ b/src/query/sql/src/planner/dataframe.rs @@ -15,7 +15,9 @@ use std::sync::Arc; use databend_common_ast::ast::ColumnID; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::GroupBy; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Join; @@ -176,12 +178,14 @@ impl Dataframe { let select_list = [SelectTarget::AliasedExpr { expr: Box::new(Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("count"), - args: vec![], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("count"), + args: vec![], + params: vec![], + window: None, + lambda: None, + }, }), alias: None, }]; @@ -575,9 +579,11 @@ fn parse_cols(schema: DataSchemaRef, columns: &[&str]) -> Result { match name.name.to_ascii_lowercase().to_lowercase().as_str() { diff --git a/src/query/sql/src/planner/semantic/aggregating_index_visitor.rs b/src/query/sql/src/planner/semantic/aggregating_index_visitor.rs index 5c19d749d8a9f..dce62932ef884 100644 --- a/src/query/sql/src/planner/semantic/aggregating_index_visitor.rs +++ b/src/query/sql/src/planner/semantic/aggregating_index_visitor.rs @@ -19,7 +19,9 @@ use databend_common_ast::ast::walk_expr_mut; use databend_common_ast::ast::walk_select_target; use databend_common_ast::ast::walk_select_target_mut; use databend_common_ast::ast::ColumnID; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::GroupBy; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Lambda; @@ -57,11 +59,15 @@ impl VisitorMut for AggregatingIndexRewriter { match expr { Expr::FunctionCall { - distinct, - name, - args, - window, - lambda, + func: + FunctionCall { + distinct, + name, + args, + window, + lambda, + .. + }, .. } if !*distinct && SUPPORTED_AGGREGATING_INDEX_FUNCTIONS @@ -316,9 +322,13 @@ impl VisitorMut for RefreshAggregatingIndexRewriter { fn visit_expr(&mut self, expr: &mut Expr) { match expr { Expr::FunctionCall { - distinct, - name, - window, + func: + FunctionCall { + distinct, + name, + window, + .. + }, .. } if !*distinct && SUPPORTED_AGGREGATING_INDEX_FUNCTIONS @@ -332,16 +342,18 @@ impl VisitorMut for RefreshAggregatingIndexRewriter { self.has_agg_function = true; *expr = Expr::FunctionCall { span: None, - distinct: false, - name: Identifier { - name: "COUNT_STATE".to_string(), - quote: None, - span: None, + func: FunctionCall { + distinct: false, + name: Identifier { + name: "COUNT_STATE".to_string(), + quote: None, + span: None, + }, + args: vec![], + params: vec![], + window: None, + lambda: None, }, - args: vec![], - params: vec![], - window: None, - lambda: None, }; } _ => {} @@ -370,17 +382,20 @@ impl VisitorMut for RefreshAggregatingIndexRewriter { let block_name_expr = Expr::ColumnRef { span: None, - database: None, - table: Some(table), - column: ColumnID::Name(Identifier::from_name(BLOCK_NAME_COL_NAME)), + column: ColumnRef { + database: None, + table: Some(table), + column: ColumnID::Name(Identifier::from_name(BLOCK_NAME_COL_NAME)), + }, }; // if select list already contains `BLOCK_NAME_COL_NAME` if select_list.iter().any(|target| match target { SelectTarget::AliasedExpr { expr, .. } => match (*expr).clone().as_ref() { - Expr::ColumnRef { column, .. } => { - column.name().eq_ignore_ascii_case(BLOCK_NAME_COL_NAME) - } + Expr::ColumnRef { column, .. } => column + .column + .name() + .eq_ignore_ascii_case(BLOCK_NAME_COL_NAME), _ => false, }, @@ -398,9 +413,10 @@ impl VisitorMut for RefreshAggregatingIndexRewriter { Some(group_by) => match group_by { GroupBy::Normal(groups) => { if !groups.iter().any(|expr| match (*expr).clone() { - Expr::ColumnRef { column, .. } => { - column.name().eq_ignore_ascii_case(BLOCK_NAME_COL_NAME) - } + Expr::ColumnRef { column, .. } => column + .column + .name() + .eq_ignore_ascii_case(BLOCK_NAME_COL_NAME), _ => false, }) { groups.extend_one(block_name_expr) diff --git a/src/query/sql/src/planner/semantic/distinct_to_groupby.rs b/src/query/sql/src/planner/semantic/distinct_to_groupby.rs index 6c9cf3a71c864..5928e9b221bd1 100644 --- a/src/query/sql/src/planner/semantic/distinct_to_groupby.rs +++ b/src/query/sql/src/planner/semantic/distinct_to_groupby.rs @@ -13,7 +13,9 @@ // limitations under the License. use databend_common_ast::ast::ColumnID; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::GroupBy; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Query; @@ -45,10 +47,13 @@ impl VisitorMut for DistinctToGroupBy { expr: box Expr::FunctionCall { span, - distinct, - name, - args, - .. + func: + FunctionCall { + distinct, + name, + args, + .. + }, }, alias, } = &select_list[0] @@ -92,21 +97,25 @@ impl VisitorMut for DistinctToGroupBy { select_list: vec![databend_common_ast::ast::SelectTarget::AliasedExpr { expr: Box::new(Expr::FunctionCall { span: None, - distinct: false, - name: Identifier { - name: "count".to_string(), - quote: None, - span: *span, + func: FunctionCall { + distinct: false, + name: Identifier { + name: "count".to_string(), + quote: None, + span: *span, + }, + args: vec![Expr::ColumnRef { + span: None, + column: ColumnRef { + database: None, + table: None, + column: ColumnID::Name(Identifier::from_name("_1")), + }, + }], + params: vec![], + window: None, + lambda: None, }, - args: vec![Expr::ColumnRef { - span: None, - database: None, - table: None, - column: ColumnID::Name(Identifier::from_name("_1")), - }], - params: vec![], - window: None, - lambda: None, }), alias: alias.clone(), }], diff --git a/src/query/sql/src/planner/semantic/type_check.rs b/src/query/sql/src/planner/semantic/type_check.rs index 500fdd9c8c5b1..91ce6e9551ff8 100644 --- a/src/query/sql/src/planner/semantic/type_check.rs +++ b/src/query/sql/src/planner/semantic/type_check.rs @@ -20,7 +20,9 @@ use std::vec; use databend_common_ast::ast::contain_agg_func; use databend_common_ast::ast::BinaryOperator; use databend_common_ast::ast::ColumnID; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::FunctionCall as ASTFunctionCall; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::IntervalKind as ASTIntervalKind; use databend_common_ast::ast::Lambda; @@ -220,9 +222,12 @@ impl<'a> TypeChecker<'a> { let box (scalar, data_type): Box<(ScalarExpr, DataType)> = match expr { Expr::ColumnRef { span, - database, - table, - column: ident, + column: + ColumnRef { + database, + table, + column: ident, + }, } => { let database = database .as_ref() @@ -395,27 +400,31 @@ impl<'a> TypeChecker<'a> { // Deduplicate the array. let array_expr = Expr::FunctionCall { span: *span, - name: Identifier::from_name("array_distinct"), - args: vec![array_expr], - params: vec![], - window: None, - lambda: None, - distinct: false, + func: ASTFunctionCall { + name: Identifier::from_name("array_distinct"), + args: vec![array_expr], + params: vec![], + window: None, + lambda: None, + distinct: false, + }, }; let args = vec![&array_expr, expr.as_ref()]; if *not { self.resolve_unary_op(*span, &UnaryOperator::Not, &Expr::FunctionCall { span: *span, - distinct: false, - name: Identifier { - name: "contains".to_string(), - quote: None, - span: *span, + func: ASTFunctionCall { + distinct: false, + name: Identifier { + name: "contains".to_string(), + quote: None, + span: *span, + }, + args: args.iter().copied().cloned().collect(), + params: vec![], + window: None, + lambda: None, }, - args: args.iter().copied().cloned().collect(), - params: vec![], - window: None, - lambda: None, }) .await? } else { @@ -656,16 +665,18 @@ impl<'a> TypeChecker<'a> { // compare case operand with each conditions until one of them is equal let equal_expr = Expr::FunctionCall { span: *span, - distinct: false, - name: Identifier { - name: "eq".to_string(), - quote: None, - span: *span, + func: ASTFunctionCall { + distinct: false, + name: Identifier { + name: "eq".to_string(), + quote: None, + span: *span, + }, + args: vec![*operand.clone(), c.clone()], + params: vec![], + window: None, + lambda: None, }, - args: vec![*operand.clone(), c.clone()], - params: vec![], - window: None, - lambda: None, }; arguments.push(equal_expr) } @@ -708,12 +719,15 @@ impl<'a> TypeChecker<'a> { Expr::FunctionCall { span, - distinct, - name, - args, - params, - window, - lambda, + func: + ASTFunctionCall { + distinct, + name, + args, + params, + window, + lambda, + }, } => { let func_name = normalize_identifier(name, self.name_resolution_ctx).to_string(); let func_name = func_name.as_str(); @@ -2544,16 +2558,18 @@ impl<'a> TypeChecker<'a> { Some( self.resolve_unary_op(span, &UnaryOperator::Not, &Expr::FunctionCall { span, - distinct: false, - name: Identifier { - name: "is_not_null".to_string(), - quote: None, - span, + func: ASTFunctionCall { + distinct: false, + name: Identifier { + name: "is_not_null".to_string(), + quote: None, + span, + }, + args: vec![arg_x.clone()], + params: vec![], + window: None, + lambda: None, }, - args: vec![arg_x.clone()], - params: vec![], - window: None, - lambda: None, }) .await, ) @@ -2581,16 +2597,18 @@ impl<'a> TypeChecker<'a> { let assume_not_null_expr = Expr::FunctionCall { span, - distinct: false, - name: Identifier { - name: "assume_not_null".to_string(), - quote: None, - span, + func: ASTFunctionCall { + distinct: false, + name: Identifier { + name: "assume_not_null".to_string(), + quote: None, + span, + }, + args: vec![(*arg).clone()], + params: vec![], + window: None, + lambda: None, }, - args: vec![(*arg).clone()], - params: vec![], - window: None, - lambda: None, }; new_args.push(is_not_null_expr); @@ -3053,7 +3071,7 @@ impl<'a> TypeChecker<'a> { let udf_expr = self .clone_expr_with_replacement(&expr, &|nest_expr| { if let Expr::ColumnRef { column, .. } = nest_expr { - if let Some(arg) = args_map.get(&column.name().to_string()) { + if let Some(arg) = args_map.get(&column.column.name().to_string()) { return Ok(Some(arg.clone())); } } @@ -3675,23 +3693,28 @@ impl<'a> TypeChecker<'a> { }), Expr::FunctionCall { span, - distinct, - name, - args, - params, - window, - lambda, + func: + ASTFunctionCall { + distinct, + name, + args, + params, + window, + lambda, + }, } => Ok(Expr::FunctionCall { span: *span, - distinct: *distinct, - name: name.clone(), - args: args - .iter() - .map(|arg| self.clone_expr_with_replacement(arg, replacement_fn)) - .collect::>>()?, - params: params.clone(), - window: window.clone(), - lambda: lambda.clone(), + func: ASTFunctionCall { + distinct: *distinct, + name: name.clone(), + args: args + .iter() + .map(|arg| self.clone_expr_with_replacement(arg, replacement_fn)) + .collect::>>()?, + params: params.clone(), + window: window.clone(), + lambda: lambda.clone(), + }, }), Expr::Case { span, diff --git a/src/tests/sqlsmith/src/sql_gen/expr.rs b/src/tests/sqlsmith/src/sql_gen/expr.rs index 5e22ef91c83ed..3f2cbf7127999 100644 --- a/src/tests/sqlsmith/src/sql_gen/expr.rs +++ b/src/tests/sqlsmith/src/sql_gen/expr.rs @@ -15,7 +15,9 @@ use databend_common_ast::ast::BinaryOperator; use databend_common_ast::ast::ColumnID; use databend_common_ast::ast::ColumnPosition; +use databend_common_ast::ast::ColumnRef; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::IntervalKind; use databend_common_ast::ast::Literal; @@ -96,9 +98,11 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { return Expr::ColumnRef { span: None, // TODO - database: None, - table, - column, + column: ColumnRef { + database: None, + table, + column, + }, }; } } @@ -143,12 +147,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { }; Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("to_date".to_string()), - args: vec![arg], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("to_date".to_string()), + args: vec![arg], + params: vec![], + window: None, + lambda: None, + }, } } DataType::Timestamp => { @@ -158,12 +164,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { }; Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("to_timestamp".to_string()), - args: vec![arg], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("to_timestamp".to_string()), + args: vec![arg], + params: vec![], + window: None, + lambda: None, + }, } } DataType::Nullable(box inner_ty) => { @@ -213,12 +221,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { }; Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("to_bitmap".to_string()), - args: vec![arg], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("to_bitmap".to_string()), + args: vec![arg], + params: vec![], + window: None, + lambda: None, + }, } } DataType::Variant => { @@ -229,12 +239,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { }; Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("parse_json".to_string()), - args: vec![arg], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("parse_json".to_string()), + args: vec![arg], + params: vec![], + window: None, + lambda: None, + }, } } DataType::Binary => { @@ -244,12 +256,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { }; Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("to_binary".to_string()), - args: vec![arg], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("to_binary".to_string()), + args: vec![arg], + params: vec![], + window: None, + lambda: None, + }, } } DataType::Geometry => { @@ -261,12 +275,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { }; Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("to_geometry".to_string()), - args: vec![arg], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("to_geometry".to_string()), + args: vec![arg], + params: vec![], + window: None, + lambda: None, + }, } } _ => Expr::Literal { @@ -587,12 +603,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { let arg = self.gen_expr(&arg_ty); Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("to_binary"), - args: vec![arg], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("to_binary"), + args: vec![arg], + params: vec![], + window: None, + lambda: None, + }, } } DataType::Geometry => { @@ -623,12 +641,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { }; Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name(func_name), - args, - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name(func_name), + args, + params: vec![], + window: None, + lambda: None, + }, } } _ => { diff --git a/src/tests/sqlsmith/src/sql_gen/func.rs b/src/tests/sqlsmith/src/sql_gen/func.rs index 9b62b59023f6a..1a867f6f1d744 100644 --- a/src/tests/sqlsmith/src/sql_gen/func.rs +++ b/src/tests/sqlsmith/src/sql_gen/func.rs @@ -15,6 +15,7 @@ use std::mem; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Lambda; use databend_common_ast::ast::Literal; @@ -770,12 +771,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { let name = Identifier::from_name(name); Expr::FunctionCall { span: None, - distinct, - name, - args, - params, - window, - lambda, + func: FunctionCall { + distinct, + name, + args, + params, + window, + lambda, + }, } } } diff --git a/src/tests/sqlsmith/src/sql_gen/query.rs b/src/tests/sqlsmith/src/sql_gen/query.rs index eba5ac6c4a93c..59e3e47b88bf7 100644 --- a/src/tests/sqlsmith/src/sql_gen/query.rs +++ b/src/tests/sqlsmith/src/sql_gen/query.rs @@ -15,6 +15,7 @@ use std::mem; use databend_common_ast::ast::Expr; +use databend_common_ast::ast::FunctionCall; use databend_common_ast::ast::GroupBy; use databend_common_ast::ast::Identifier; use databend_common_ast::ast::Join; @@ -533,12 +534,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { }; (TableDataType::Timestamp, Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("to_timestamp".to_string()), - args: vec![arg], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("to_timestamp".to_string()), + args: vec![arg], + params: vec![], + window: None, + lambda: None, + }, }) } 1 => { @@ -548,12 +551,14 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { }; (TableDataType::Date, Expr::FunctionCall { span: None, - distinct: false, - name: Identifier::from_name("to_date".to_string()), - args: vec![arg], - params: vec![], - window: None, - lambda: None, + func: FunctionCall { + distinct: false, + name: Identifier::from_name("to_date".to_string()), + args: vec![arg], + params: vec![], + window: None, + lambda: None, + }, }) } 2 => (