Skip to content

Commit 3e90a18

Browse files
authored
Replace Method and CompositeAccess with CompoundFieldAccess (#1716)
1 parent c75a992 commit 3e90a18

File tree

9 files changed

+347
-263
lines changed

9 files changed

+347
-263
lines changed

src/ast/mod.rs

-26
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,6 @@ pub enum Expr {
661661
/// The path to the data to extract.
662662
path: JsonPath,
663663
},
664-
/// CompositeAccess eg: SELECT foo(bar).z, (information_schema._pg_expandarray(array['i','i'])).n
665-
CompositeAccess {
666-
expr: Box<Expr>,
667-
key: Ident,
668-
},
669664
/// `IS FALSE` operator
670665
IsFalse(Box<Expr>),
671666
/// `IS NOT FALSE` operator
@@ -915,23 +910,6 @@ pub enum Expr {
915910
},
916911
/// Scalar function call e.g. `LEFT(foo, 5)`
917912
Function(Function),
918-
/// Arbitrary expr method call
919-
///
920-
/// Syntax:
921-
///
922-
/// `<arbitrary-expr>.<function-call>.<function-call-expr>...`
923-
///
924-
/// > `arbitrary-expr` can be any expression including a function call.
925-
///
926-
/// Example:
927-
///
928-
/// ```sql
929-
/// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
930-
/// SELECT CONVERT(XML,'<Book>abc</Book>').value('.','NVARCHAR(MAX)').value('.','NVARCHAR(MAX)')
931-
/// ```
932-
///
933-
/// (mssql): <https://learn.microsoft.com/en-us/sql/t-sql/xml/xml-data-type-methods?view=sql-server-ver16>
934-
Method(Method),
935913
/// `CASE [<operand>] WHEN <condition> THEN <result> ... [ELSE <result>] END`
936914
///
937915
/// Note we only recognize a complete single expression as `<condition>`,
@@ -1631,7 +1609,6 @@ impl fmt::Display for Expr {
16311609
write!(f, " {value}")
16321610
}
16331611
Expr::Function(fun) => write!(f, "{fun}"),
1634-
Expr::Method(method) => write!(f, "{method}"),
16351612
Expr::Case {
16361613
operand,
16371614
conditions,
@@ -1789,9 +1766,6 @@ impl fmt::Display for Expr {
17891766
Expr::JsonAccess { value, path } => {
17901767
write!(f, "{value}{path}")
17911768
}
1792-
Expr::CompositeAccess { expr, key } => {
1793-
write!(f, "{expr}.{key}")
1794-
}
17951769
Expr::AtTimeZone {
17961770
timestamp,
17971771
time_zone,

src/ast/spans.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,6 @@ impl Spanned for Expr {
12881288
match self {
12891289
Expr::Identifier(ident) => ident.span,
12901290
Expr::CompoundIdentifier(vec) => union_spans(vec.iter().map(|i| i.span)),
1291-
Expr::CompositeAccess { expr, key } => expr.span().union(&key.span),
12921291
Expr::CompoundFieldAccess { root, access_chain } => {
12931292
union_spans(iter::once(root.span()).chain(access_chain.iter().map(|i| i.span())))
12941293
}
@@ -1478,7 +1477,6 @@ impl Spanned for Expr {
14781477
Expr::OuterJoin(expr) => expr.span(),
14791478
Expr::Prior(expr) => expr.span(),
14801479
Expr::Lambda(_) => Span::empty(),
1481-
Expr::Method(_) => Span::empty(),
14821480
}
14831481
}
14841482
}

src/dialect/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ pub trait Dialect: Debug + Any {
251251
false
252252
}
253253

254+
/// Returns true if the dialect supports the `(+)` syntax for OUTER JOIN.
255+
fn supports_outer_join_operator(&self) -> bool {
256+
false
257+
}
258+
254259
/// Returns true if the dialect supports CONNECT BY.
255260
fn supports_connect_by(&self) -> bool {
256261
false
@@ -352,15 +357,6 @@ pub trait Dialect: Debug + Any {
352357
false
353358
}
354359

355-
/// Returns true if the dialect supports method calls, for example:
356-
///
357-
/// ```sql
358-
/// SELECT (SELECT ',' + name FROM sys.objects FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)')
359-
/// ```
360-
fn supports_methods(&self) -> bool {
361-
false
362-
}
363-
364360
/// Returns true if the dialect supports multiple variable assignment
365361
/// using parentheses in a `SET` variable declaration.
366362
///
@@ -581,6 +577,7 @@ pub trait Dialect: Debug + Any {
581577
Token::Word(w) if w.keyword == Keyword::SIMILAR => Ok(p!(Like)),
582578
Token::Word(w) if w.keyword == Keyword::OPERATOR => Ok(p!(Between)),
583579
Token::Word(w) if w.keyword == Keyword::DIV => Ok(p!(MulDivModOp)),
580+
Token::Period => Ok(p!(Period)),
584581
Token::Eq
585582
| Token::Lt
586583
| Token::LtEq
@@ -654,6 +651,7 @@ pub trait Dialect: Debug + Any {
654651
/// Uses (APPROXIMATELY) <https://www.postgresql.org/docs/7.0/operators.htm#AEN2026> as a reference
655652
fn prec_value(&self, prec: Precedence) -> u8 {
656653
match prec {
654+
Precedence::Period => 100,
657655
Precedence::DoubleColon => 50,
658656
Precedence::AtTz => 41,
659657
Precedence::MulDivModOp => 40,
@@ -925,6 +923,7 @@ pub trait Dialect: Debug + Any {
925923
/// higher number -> higher precedence
926924
#[derive(Debug, Clone, Copy)]
927925
pub enum Precedence {
926+
Period,
928927
DoubleColon,
929928
AtTz,
930929
MulDivModOp,

src/dialect/mssql.rs

+4-4
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

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::tokenizer::Token;
3737
#[derive(Debug)]
3838
pub struct PostgreSqlDialect {}
3939

40+
const PERIOD_PREC: u8 = 200;
4041
const DOUBLE_COLON_PREC: u8 = 140;
4142
const BRACKET_PREC: u8 = 130;
4243
const COLLATE_PREC: u8 = 120;
@@ -144,6 +145,7 @@ impl Dialect for PostgreSqlDialect {
144145

145146
fn prec_value(&self, prec: Precedence) -> u8 {
146147
match prec {
148+
Precedence::Period => PERIOD_PREC,
147149
Precedence::DoubleColon => DOUBLE_COLON_PREC,
148150
Precedence::AtTz => AT_TZ_PREC,
149151
Precedence::MulDivModOp => MUL_DIV_MOD_OP_PREC,

src/dialect/snowflake.rs

+5
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)