iffyio commented on code in PR #2009:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2009#discussion_r2291067419
##########
src/parser/mod.rs:
##########
@@ -17869,4 +17954,18 @@ mod tests {
assert!(Parser::parse_sql(&GenericDialect, &sql).is_err());
}
}
+
+ #[test]
+ fn test_parse_semantic_view() {
+ let sql = r#"SEMANTIC_VIEW(model DIMENSIONS a.b METRICS c.d WHERE x >
0) AS sm"#;
+ let mut parser = Parser::new(&GenericDialect {})
+ .try_with_sql(sql)
+ .expect("failed to create parser");
+
+ let ast = parser
+ .parse_semantic_view_table_factor()
+ .expect("should parse SEMANTIC_VIEW");
+
+ assert!(matches!(ast, TableFactor::SemanticView { .. }));
+ }
Review Comment:
Oh actually maybe we can move the existing test in snowflake over here
instead, since we don't have any snowflake specific construct. Then here we can
do `let dialect = all_dialects_where(|d|
d.supports_semantic_view_table_factor());`
##########
src/parser/mod.rs:
##########
@@ -4241,17 +4241,33 @@ impl<'a> Parser<'a> {
/// not be efficient as it does a loop on the tokens with `peek_nth_token`
/// each time.
pub fn parse_keyword_with_tokens(&mut self, expected: Keyword, tokens:
&[Token]) -> bool {
+ self.keyword_with_tokens(expected, tokens, true)
+ }
+
+ /// Peeks to see if the current token is the `expected` keyword followed
by specified tokens
+ /// without consuming them.
+ ///
+ /// Note that if the length of `tokens` is too long, this function will
not be efficient as it
+ /// does a loop on the tokens with `peek_nth_token` each time.
Review Comment:
```suggestion
/// See [Self::parse_keyword_with_tokens] for details.
```
##########
src/dialect/mod.rs:
##########
@@ -1182,6 +1182,20 @@ pub trait Dialect: Debug + Any {
fn supports_create_table_like_parenthesized(&self) -> bool {
false
}
+
+ /// Returns true if the dialect supports `SEMANTIC_VIEW()` table functions.
+ ///
+ /// ```sql
+ /// SELECT * FROM SEMANTIC_VIEW(
+ /// model_name
+ /// DIMENSIONS customer.name, customer.region
+ /// METRICS orders.revenue, orders.count
+ /// WHERE customer.active = true
+ /// )
+ /// ```
+ fn supports_semantic_view(&self) -> bool {
Review Comment:
```suggestion
fn supports_semantic_view_table_factor()(&self) -> bool {
```
##########
src/parser/mod.rs:
##########
@@ -4241,17 +4241,33 @@ impl<'a> Parser<'a> {
/// not be efficient as it does a loop on the tokens with `peek_nth_token`
/// each time.
pub fn parse_keyword_with_tokens(&mut self, expected: Keyword, tokens:
&[Token]) -> bool {
+ self.keyword_with_tokens(expected, tokens, true)
+ }
+
+ /// Peeks to see if the current token is the `expected` keyword followed
by specified tokens
+ /// without consuming them.
+ ///
+ /// Note that if the length of `tokens` is too long, this function will
not be efficient as it
+ /// does a loop on the tokens with `peek_nth_token` each time.
+ pub fn peek_keyword_with_tokens(&mut self, expected: Keyword, tokens:
&[Token]) -> bool {
Review Comment:
```suggestion
pub(crate) fn peek_keyword_with_tokens(&mut self, expected: Keyword,
tokens: &[Token]) -> bool {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]