File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -374,6 +374,8 @@ pub enum Expr {
374374 Identifier ( Ident ) ,
375375 /// Multi-part identifier, e.g. `table_alias.column` or `schema.table.col`
376376 CompoundIdentifier ( Vec < Ident > ) ,
377+ /// A reference to a Sigma scalar value, e.g. `@sigma.my_parameter`.
378+ SigmaParameter ( Ident ) ,
377379 /// JSON access (postgres) eg: data->'tags'
378380 JsonAccess {
379381 left : Box < Expr > ,
@@ -752,6 +754,7 @@ impl fmt::Display for Expr {
752754 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
753755 match self {
754756 Expr :: Identifier ( s) => write ! ( f, "{s}" ) ,
757+ Expr :: SigmaParameter ( s) => write ! ( f, "@sigma.{s}" ) ,
755758 Expr :: MapAccess { column, keys } => {
756759 write ! ( f, "{column}" ) ?;
757760 for k in keys {
Original file line number Diff line number Diff line change @@ -1050,6 +1050,10 @@ impl<'a> Parser<'a> {
10501050 } , // End of Token::Word
10511051 // array `[1, 2, 3]`
10521052 Token :: LBracket => self . parse_array_expr ( false ) ,
1053+ Token :: AtSign if self . parse_keyword ( Keyword :: SIGMA ) => {
1054+ self . expect_token ( & Token :: Period ) ?;
1055+ Ok ( Expr :: SigmaParameter ( self . parse_identifier ( false ) ?) )
1056+ }
10531057 tok @ Token :: Minus | tok @ Token :: Plus => {
10541058 let op = if tok == Token :: Plus {
10551059 UnaryOperator :: Plus
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ fn snowflake() -> TestedDialects {
1515}
1616#[ test]
1717fn parse_sigma ( ) {
18- let sql = "SELECT my_column FROM @sigma.my_element" ;
18+ let sql = "SELECT my_column FROM @sigma.my_element WHERE my_column <> @sigma.param_filter " ;
1919 let select = snowflake ( ) . verified_only_select ( sql) ;
2020 assert_eq ! (
2121 select. from,
@@ -26,5 +26,13 @@ fn parse_sigma() {
2626 } ,
2727 joins: vec![ ]
2828 } ]
29+ ) ;
30+ assert_eq ! (
31+ select. selection,
32+ Some ( Expr :: BinaryOp {
33+ left: Box :: new( Expr :: Identifier ( Ident :: new( "my_column" ) ) ) ,
34+ op: BinaryOperator :: NotEq ,
35+ right: Box :: new( Expr :: SigmaParameter ( Ident :: new( "param_filter" ) ) ) ,
36+ } )
2937 )
3038}
You can’t perform that action at this time.
0 commit comments