Skip to content

Commit 2128e6a

Browse files
bombsimonayman-sigma
authored andcommitted
Support wildcard metrics for SEMANTIC_VIEW (apache#2016)
1 parent fc735de commit 2128e6a

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/ast/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ pub enum TableFactor {
14351435
/// List of dimensions or expression referring to dimensions (e.g. DATE_PART('year', col))
14361436
dimensions: Vec<Expr>,
14371437
/// List of metrics (references to objects like orders.value, value, orders.*)
1438-
metrics: Vec<ObjectName>,
1438+
metrics: Vec<Expr>,
14391439
/// List of facts or expressions referring to facts or dimensions.
14401440
facts: Vec<Expr>,
14411441
/// WHERE clause for filtering

src/parser/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13990,7 +13990,7 @@ impl<'a> Parser<'a> {
1399013990
"METRICS clause can only be specified once".to_string(),
1399113991
));
1399213992
}
13993-
metrics = self.parse_comma_separated(|parser| parser.parse_object_name(true))?;
13993+
metrics = self.parse_comma_separated(Parser::parse_wildcard_expr)?;
1399413994
} else if self.parse_keyword(Keyword::FACTS) {
1399513995
if !facts.is_empty() {
1399613996
return Err(ParserError::ParserError(
@@ -14007,7 +14007,10 @@ impl<'a> Parser<'a> {
1400714007
where_clause = Some(self.parse_expr()?);
1400814008
} else {
1400914009
return parser_err!(
14010-
"Expected one of DIMENSIONS, METRICS, FACTS or WHERE",
14010+
format!(
14011+
"Expected one of DIMENSIONS, METRICS, FACTS or WHERE, got {}",
14012+
self.peek_token().token
14013+
),
1401114014
self.peek_token().span.start
1401214015
)?;
1401314016
}

tests/sqlparser_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16977,6 +16977,7 @@ fn test_parse_semantic_view_table_factor() {
1697716977
"SELECT * FROM SEMANTIC_VIEW(model METRICS orders.col, orders.col2)",
1697816978
None,
1697916979
),
16980+
("SELECT * FROM SEMANTIC_VIEW(model METRICS orders.*)", None),
1698016981
// We can parse in any order but will always produce a result in a fixed order.
1698116982
(
1698216983
"SELECT * FROM SEMANTIC_VIEW(model WHERE x > 0 DIMENSIONS dim1)",
@@ -17006,7 +17007,6 @@ fn test_parse_semantic_view_table_factor() {
1700617007
let invalid_sqls = [
1700717008
"SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 INVALID inv1)",
1700817009
"SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 DIMENSIONS dim2)",
17009-
"SELECT * FROM SEMANTIC_VIEW(model METRICS SUM(met1.avg))",
1701017010
];
1701117011

1701217012
for sql in invalid_sqls {

0 commit comments

Comments
 (0)