Skip to content

Commit ee707c7

Browse files
authored
Support wildcard metrics for SEMANTIC_VIEW (#2016)
1 parent bc478b0 commit ee707c7

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/ast/query.rs

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

src/parser/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13958,7 +13958,7 @@ impl<'a> Parser<'a> {
1395813958
"METRICS clause can only be specified once".to_string(),
1395913959
));
1396013960
}
13961-
metrics = self.parse_comma_separated(|parser| parser.parse_object_name(true))?;
13961+
metrics = self.parse_comma_separated(Parser::parse_wildcard_expr)?;
1396213962
} else if self.parse_keyword(Keyword::FACTS) {
1396313963
if !facts.is_empty() {
1396413964
return Err(ParserError::ParserError(
@@ -13975,7 +13975,10 @@ impl<'a> Parser<'a> {
1397513975
where_clause = Some(self.parse_expr()?);
1397613976
} else {
1397713977
return parser_err!(
13978-
"Expected one of DIMENSIONS, METRICS, FACTS or WHERE",
13978+
format!(
13979+
"Expected one of DIMENSIONS, METRICS, FACTS or WHERE, got {}",
13980+
self.peek_token().token
13981+
),
1397913982
self.peek_token().span.start
1398013983
)?;
1398113984
}

tests/sqlparser_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16951,6 +16951,7 @@ fn test_parse_semantic_view_table_factor() {
1695116951
"SELECT * FROM SEMANTIC_VIEW(model METRICS orders.col, orders.col2)",
1695216952
None,
1695316953
),
16954+
("SELECT * FROM SEMANTIC_VIEW(model METRICS orders.*)", None),
1695416955
// We can parse in any order but will always produce a result in a fixed order.
1695516956
(
1695616957
"SELECT * FROM SEMANTIC_VIEW(model WHERE x > 0 DIMENSIONS dim1)",
@@ -16980,7 +16981,6 @@ fn test_parse_semantic_view_table_factor() {
1698016981
let invalid_sqls = [
1698116982
"SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 INVALID inv1)",
1698216983
"SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 DIMENSIONS dim2)",
16983-
"SELECT * FROM SEMANTIC_VIEW(model METRICS SUM(met1.avg))",
1698416984
];
1698516985

1698616986
for sql in invalid_sqls {

0 commit comments

Comments
 (0)