File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -761,6 +761,11 @@ pub enum TableFactor {
761761 /// [Partition selection](https://dev.mysql.com/doc/refman/8.0/en/partitioning-selection.html), supported by MySQL.
762762 partitions : Vec < Ident > ,
763763 } ,
764+ /// A reference to an element in a Sigma workbook.
765+ SigmaElement {
766+ element : Ident ,
767+ alias : Option < TableAlias > ,
768+ } ,
764769 Derived {
765770 lateral : bool ,
766771 subquery : Box < Query > ,
@@ -887,6 +892,13 @@ impl fmt::Display for TableFactor {
887892 }
888893 Ok ( ( ) )
889894 }
895+ TableFactor :: SigmaElement { element, alias } => {
896+ write ! ( f, "@sigma.{element}" ) ?;
897+ if let Some ( alias) = alias {
898+ write ! ( f, " AS {alias}" ) ?;
899+ }
900+ Ok ( ( ) )
901+ }
890902 TableFactor :: Derived {
891903 lateral,
892904 subquery,
Original file line number Diff line number Diff line change @@ -612,6 +612,7 @@ define_keywords!(
612612 SETS ,
613613 SHARE ,
614614 SHOW ,
615+ SIGMA ,
615616 SIMILAR ,
616617 SKIP ,
617618 SLOW ,
Original file line number Diff line number Diff line change @@ -7985,6 +7985,7 @@ impl<'a> Parser<'a> {
79857985 match & mut table_and_joins. relation {
79867986 TableFactor :: Derived { alias, .. }
79877987 | TableFactor :: Table { alias, .. }
7988+ | TableFactor :: SigmaElement { alias, .. }
79887989 | TableFactor :: Function { alias, .. }
79897990 | TableFactor :: UNNEST { alias, .. }
79907991 | TableFactor :: JsonTable { alias, .. }
@@ -8062,6 +8063,18 @@ impl<'a> Parser<'a> {
80628063 columns,
80638064 alias,
80648065 } )
8066+ } else if self
8067+ . maybe_parse ( |p| {
8068+ p. expect_token ( & Token :: AtSign ) ?;
8069+ p. expect_keyword ( Keyword :: SIGMA ) ?;
8070+ Ok ( ( ) )
8071+ } )
8072+ . is_some ( )
8073+ {
8074+ self . expect_token ( & Token :: Period ) ?;
8075+ let element = self . parse_identifier ( true ) ?;
8076+ let alias = self . parse_optional_table_alias ( keywords:: RESERVED_FOR_TABLE_ALIAS ) ?;
8077+ Ok ( TableFactor :: SigmaElement { element, alias } )
80658078 } else {
80668079 let name = self . parse_object_name ( true ) ?;
80678080
Original file line number Diff line number Diff line change 1+ #![ warn( clippy:: all) ]
2+
3+ use sqlparser:: ast:: * ;
4+ use sqlparser:: dialect:: SnowflakeDialect ;
5+ use test_utils:: * ;
6+
7+ #[ macro_use]
8+ mod test_utils;
9+
10+ fn snowflake ( ) -> TestedDialects {
11+ TestedDialects {
12+ dialects : vec ! [ Box :: new( SnowflakeDialect { } ) ] ,
13+ options : None ,
14+ }
15+ }
16+ #[ test]
17+ fn parse_sigma ( ) {
18+ let sql = "SELECT my_column FROM @sigma.my_element" ;
19+ let select = snowflake ( ) . verified_only_select ( sql) ;
20+ assert_eq ! (
21+ select. from,
22+ vec![ TableWithJoins {
23+ relation: TableFactor :: SigmaElement {
24+ element: Ident :: new( "my_element" ) ,
25+ alias: None
26+ } ,
27+ joins: vec![ ]
28+ } ]
29+ )
30+ }
You can’t perform that action at this time.
0 commit comments