Skip to content

Commit 2730712

Browse files
committed
sigma element table factor
1 parent 4d6ff63 commit 2730712

4 files changed

Lines changed: 56 additions & 0 deletions

File tree

src/ast/query.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ define_keywords!(
612612
SETS,
613613
SHARE,
614614
SHOW,
615+
SIGMA,
615616
SIMILAR,
616617
SKIP,
617618
SLOW,

src/parser/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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

tests/sqlparser_sigma.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

0 commit comments

Comments
 (0)