Skip to content

Replace Method and CompositeAccess with CompoundFieldAccess #1716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,6 @@ pub enum Expr {
/// The path to the data to extract.
path: JsonPath,
},
/// CompositeAccess eg: SELECT foo(bar).z, (information_schema._pg_expandarray(array['i','i'])).n
CompositeAccess {
expr: Box<Expr>,
key: Ident,
},
/// `IS FALSE` operator
IsFalse(Box<Expr>),
/// `IS NOT FALSE` operator
Expand Down Expand Up @@ -915,23 +910,6 @@ pub enum Expr {
},
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
/// Arbitrary expr method call
///
/// Syntax:
///
/// `<arbitrary-expr>.<function-call>.<function-call-expr>...`
///
/// > `arbitrary-expr` can be any expression including a function call.
///
/// Example:
///
/// ```sql
/// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
/// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
/// ```
///
/// (mssql): <https://learn.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-ver16>
Method(Method),
/// `CASE [<operand>] WHEN <condition> THEN <result> ... [ELSE <result>] END`
///
/// Note we only recognize a complete single expression as `<condition>`,
Expand Down Expand Up @@ -1631,7 +1609,6 @@ impl fmt::Display for Expr {
write!(f, " {value}")
}
Expr::Function(fun) => write!(f, "{fun}"),
Expr::Method(method) => write!(f, "{method}"),
Expr::Case {
operand,
conditions,
Expand Down Expand Up @@ -1789,9 +1766,6 @@ impl fmt::Display for Expr {
Expr::JsonAccess { value, path } => {
write!(f, "{value}{path}")
}
Expr::CompositeAccess { expr, key } => {
write!(f, "{expr}.{key}")
}
Expr::AtTimeZone {
timestamp,
time_zone,
Expand Down
2 changes: 0 additions & 2 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,6 @@ impl Spanned for Expr {
match self {
Expr::Identifier(ident) => ident.span,
Expr::CompoundIdentifier(vec) => union_spans(vec.iter().map(|i| i.span)),
Expr::CompositeAccess { expr, key } => expr.span().union(&key.span),
Expr::CompoundFieldAccess { root, access_chain } => {
union_spans(iter::once(root.span()).chain(access_chain.iter().map(|i| i.span())))
}
Expand Down Expand Up @@ -1478,7 +1477,6 @@ impl Spanned for Expr {
Expr::OuterJoin(expr) => expr.span(),
Expr::Prior(expr) => expr.span(),
Expr::Lambda(_) => Span::empty(),
Expr::Method(_) => Span::empty(),
}
}
}
Expand Down
17 changes: 8 additions & 9 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ pub trait Dialect: Debug + Any {
false
}

/// Returns true if the dialect supports the `(+)` syntax for OUTER JOIN.
fn supports_outer_join_operator(&self) -> bool {
false
}

/// Returns true if the dialect supports CONNECT BY.
fn supports_connect_by(&self) -> bool {
false
Expand Down Expand Up @@ -352,15 +357,6 @@ pub trait Dialect: Debug + Any {
false
}

/// Returns true if the dialect supports method calls, for example:
///
/// ```sql
/// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
/// ```
fn supports_methods(&self) -> bool {
false
}

/// Returns true if the dialect supports multiple variable assignment
/// using parentheses in a `SET` variable declaration.
///
Expand Down Expand Up @@ -581,6 +577,7 @@ pub trait Dialect: Debug + Any {
Token::Word(w) if w.keyword == Keyword::SIMILAR => Ok(p!(Like)),
Token::Word(w) if w.keyword == Keyword::OPERATOR => Ok(p!(Between)),
Token::Word(w) if w.keyword == Keyword::DIV => Ok(p!(MulDivModOp)),
Token::Period => Ok(p!(Period)),
Token::Eq
| Token::Lt
| Token::LtEq
Expand Down Expand Up @@ -654,6 +651,7 @@ pub trait Dialect: Debug + Any {
/// Uses (APPROXIMATELY) <https://www.postgresql.org/docs/7.0/operators.htm#AEN2026> as a reference
fn prec_value(&self, prec: Precedence) -> u8 {
match prec {
Precedence::Period => 100,
Precedence::DoubleColon => 50,
Precedence::AtTz => 41,
Precedence::MulDivModOp => 40,
Expand Down Expand Up @@ -925,6 +923,7 @@ pub trait Dialect: Debug + Any {
/// higher number -> higher precedence
#[derive(Debug, Clone, Copy)]
pub enum Precedence {
Period,
DoubleColon,
AtTz,
MulDivModOp,
Expand Down
8 changes: 4 additions & 4 deletions src/dialect/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl Dialect for MsSqlDialect {
true
}

fn supports_outer_join_operator(&self) -> bool {
true
}

fn supports_connect_by(&self) -> bool {
true
}
Expand All @@ -63,10 +67,6 @@ impl Dialect for MsSqlDialect {
false
}

fn supports_methods(&self) -> bool {
true
}

fn supports_named_fn_args_with_colon_operator(&self) -> bool {
true
}
Expand Down
2 changes: 2 additions & 0 deletions src/dialect/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::tokenizer::Token;
#[derive(Debug)]
pub struct PostgreSqlDialect {}

const PERIOD_PREC: u8 = 200;
const DOUBLE_COLON_PREC: u8 = 140;
const BRACKET_PREC: u8 = 130;
const COLLATE_PREC: u8 = 120;
Expand Down Expand Up @@ -144,6 +145,7 @@ impl Dialect for PostgreSqlDialect {

fn prec_value(&self, prec: Precedence) -> u8 {
match prec {
Precedence::Period => PERIOD_PREC,
Precedence::DoubleColon => DOUBLE_COLON_PREC,
Precedence::AtTz => AT_TZ_PREC,
Precedence::MulDivModOp => MUL_DIV_MOD_OP_PREC,
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ impl Dialect for SnowflakeDialect {
true
}

/// See <https://docs.snowflake.com/en/sql-reference/constructs/where#joins-in-the-where-clause>
fn supports_outer_join_operator(&self) -> bool {
true
}

fn supports_connect_by(&self) -> bool {
true
}
Expand Down
Loading