Skip to content

Commit b1a60fb

Browse files
committed
Replace Expr::Method and Expr::CompositeAccess with Expr::CompoundfieldAccess
1 parent cad4923 commit b1a60fb

File tree

9 files changed

+347
-263
lines changed

9 files changed

+347
-263
lines changed

src/ast/mod.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,6 @@ pub enum Expr {
659659
/// The path to the data to extract.
660660
path: JsonPath,
661661
},
662-
/// CompositeAccess eg: SELECT foo(bar).z, (information_schema._pg_expandarray(array['i','i'])).n
663-
CompositeAccess {
664-
expr: Box<Expr>,
665-
key: Ident,
666-
},
667662
/// `IS FALSE` operator
668663
IsFalse(Box<Expr>),
669664
/// `IS NOT FALSE` operator
@@ -913,23 +908,6 @@ pub enum Expr {
913908
},
914909
/// Scalar function call e.g. `LEFT(foo, 5)`
915910
Function(Function),
916-
/// Arbitrary expr method call
917-
///
918-
/// Syntax:
919-
///
920-
/// `<arbitrary-expr>.<function-call>.<function-call-expr>...`
921-
///
922-
/// > `arbitrary-expr` can be any expression including a function call.
923-
///
924-
/// Example:
925-
///
926-
/// ```sql
927-
/// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
928-
/// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
929-
/// ```
930-
///
931-
/// (mssql): <https://learn.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-ver16>
932-
Method(Method),
933911
/// `CASE [<operand>] WHEN <condition> THEN <result> ... [ELSE <result>] END`
934912
///
935913
/// Note we only recognize a complete single expression as `<condition>`,
@@ -1629,7 +1607,6 @@ impl fmt::Display for Expr {
16291607
write!(f, " {value}")
16301608
}
16311609
Expr::Function(fun) => write!(f, "{fun}"),
1632-
Expr::Method(method) => write!(f, "{method}"),
16331610
Expr::Case {
16341611
operand,
16351612
conditions,
@@ -1787,9 +1764,6 @@ impl fmt::Display for Expr {
17871764
Expr::JsonAccess { value, path } => {
17881765
write!(f, "{value}{path}")
17891766
}
1790-
Expr::CompositeAccess { expr, key } => {
1791-
write!(f, "{expr}.{key}")
1792-
}
17931767
Expr::AtTimeZone {
17941768
timestamp,
17951769
time_zone,

src/ast/spans.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,6 @@ impl Spanned for Expr {
12861286
match self {
12871287
Expr::Identifier(ident) => ident.span,
12881288
Expr::CompoundIdentifier(vec) => union_spans(vec.iter().map(|i| i.span)),
1289-
Expr::CompositeAccess { expr, key } => expr.span().union(&key.span),
12901289
Expr::CompoundFieldAccess { root, access_chain } => {
12911290
union_spans(iter::once(root.span()).chain(access_chain.iter().map(|i| i.span())))
12921291
}
@@ -1476,7 +1475,6 @@ impl Spanned for Expr {
14761475
Expr::OuterJoin(expr) => expr.span(),
14771476
Expr::Prior(expr) => expr.span(),
14781477
Expr::Lambda(_) => Span::empty(),
1479-
Expr::Method(_) => Span::empty(),
14801478
}
14811479
}
14821480
}

src/dialect/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ pub trait Dialect: Debug + Any {
245245
false
246246
}
247247

248+
/// Returns true if the dialect supports the `(+)` syntax for OUTER JOIN.
249+
fn supports_outer_join_operator(&self) -> bool {
250+
false
251+
}
252+
248253
/// Returns true if the dialect supports CONNECT BY.
249254
fn supports_connect_by(&self) -> bool {
250255
false
@@ -346,15 +351,6 @@ pub trait Dialect: Debug + Any {
346351
false
347352
}
348353

349-
/// Returns true if the dialect supports method calls, for example:
350-
///
351-
/// ```sql
352-
/// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
353-
/// ```
354-
fn supports_methods(&self) -> bool {
355-
false
356-
}
357-
358354
/// Returns true if the dialect supports multiple variable assignment
359355
/// using parentheses in a `SET` variable declaration.
360356
///
@@ -559,6 +555,7 @@ pub trait Dialect: Debug + Any {
559555
Token::Word(w) if w.keyword == Keyword::SIMILAR => Ok(p!(Like)),
560556
Token::Word(w) if w.keyword == Keyword::OPERATOR => Ok(p!(Between)),
561557
Token::Word(w) if w.keyword == Keyword::DIV => Ok(p!(MulDivModOp)),
558+
Token::Period => Ok(p!(Period)),
562559
Token::Eq
563560
| Token::Lt
564561
| Token::LtEq
@@ -632,6 +629,7 @@ pub trait Dialect: Debug + Any {
632629
/// Uses (APPROXIMATELY) <https://www.postgresql.org/docs/7.0/operators.htm#AEN2026> as a reference
633630
fn prec_value(&self, prec: Precedence) -> u8 {
634631
match prec {
632+
Precedence::Period => 100,
635633
Precedence::DoubleColon => 50,
636634
Precedence::AtTz => 41,
637635
Precedence::MulDivModOp => 40,
@@ -903,6 +901,7 @@ pub trait Dialect: Debug + Any {
903901
/// higher number -> higher precedence
904902
#[derive(Debug, Clone, Copy)]
905903
pub enum Precedence {
904+
Period,
906905
DoubleColon,
907906
AtTz,
908907
MulDivModOp,

src/dialect/mssql.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ impl Dialect for MsSqlDialect {
4646
true
4747
}
4848

49+
fn supports_outer_join_operator(&self) -> bool {
50+
true
51+
}
52+
4953
fn supports_connect_by(&self) -> bool {
5054
true
5155
}
@@ -63,10 +67,6 @@ impl Dialect for MsSqlDialect {
6367
false
6468
}
6569

66-
fn supports_methods(&self) -> bool {
67-
true
68-
}
69-
7070
fn supports_named_fn_args_with_colon_operator(&self) -> bool {
7171
true
7272
}

src/dialect/postgresql.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use crate::tokenizer::Token;
3838
#[derive(Debug)]
3939
pub struct PostgreSqlDialect {}
4040

41+
const PERIOD_PREC: u8 = 200;
4142
const DOUBLE_COLON_PREC: u8 = 140;
4243
const BRACKET_PREC: u8 = 130;
4344
const COLLATE_PREC: u8 = 120;
@@ -154,6 +155,7 @@ impl Dialect for PostgreSqlDialect {
154155

155156
fn prec_value(&self, prec: Precedence) -> u8 {
156157
match prec {
158+
Precedence::Period => PERIOD_PREC,
157159
Precedence::DoubleColon => DOUBLE_COLON_PREC,
158160
Precedence::AtTz => AT_TZ_PREC,
159161
Precedence::MulDivModOp => MUL_DIV_MOD_OP_PREC,

src/dialect/snowflake.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ impl Dialect for SnowflakeDialect {
8787
true
8888
}
8989

90+
/// See <https://docs.snowflake.com/en/sql-reference/constructs/where#joins-in-the-where-clause>
91+
fn supports_outer_join_operator(&self) -> bool {
92+
true
93+
}
94+
9095
fn supports_connect_by(&self) -> bool {
9196
true
9297
}

0 commit comments

Comments
 (0)