Skip to content

Commit 48f8828

Browse files
committed
fix(cubesql): Allow any aggregation for number measure as it can be a wildcard
1 parent dbd8ef2 commit 48f8828

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,28 @@ mod tests {
17071707
);
17081708
}
17091709

1710+
#[tokio::test]
1711+
async fn test_select_number() {
1712+
let query_plan = convert_select_to_query_plan(
1713+
"SELECT MEASURE(someNumber) as s1, SUM(someNumber) as s2, MIN(someNumber) as s3, MAX(someNumber) as s4, COUNT(someNumber) as s5 FROM NumberCube".to_string(),
1714+
DatabaseProtocol::PostgreSQL).await;
1715+
1716+
let logical_plan = query_plan.as_logical_plan();
1717+
assert_eq!(
1718+
logical_plan.find_cube_scan().request,
1719+
V1LoadRequestQuery {
1720+
measures: Some(vec!["NumberCube.someNumber".to_string(),]),
1721+
segments: Some(vec![]),
1722+
dimensions: Some(vec![]),
1723+
time_dimensions: None,
1724+
order: None,
1725+
limit: None,
1726+
offset: None,
1727+
filters: None
1728+
}
1729+
);
1730+
}
1731+
17101732
#[tokio::test]
17111733
async fn test_select_null_if_measure_diff() {
17121734
let query_plan = convert_select_to_query_plan(
@@ -3748,10 +3770,6 @@ ORDER BY \"COUNT(count)\" DESC"
37483770
"SELECT AVG(maxPrice) FROM KibanaSampleDataEcommerce".to_string(),
37493771
CompilationError::user("Error during rewrite: Measure aggregation type doesn't match. The aggregation type for 'maxPrice' is 'MAX()' but 'AVG()' was provided. Please check logs for additional information.".to_string()),
37503772
),
3751-
(
3752-
"SELECT AVG(someNumber) FROM NumberCube".to_string(),
3753-
CompilationError::user("Error during rewrite: Measure aggregation type doesn't match. The aggregation type for 'someNumber' is 'MEASURE()' but 'AVG()' was provided. Please check logs for additional information.".to_string()),
3754-
),
37553773
];
37563774

37573775
for (input_query, expected_error) in variants.iter() {

rust/cubesql/cubesql/src/transport/ext.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl V1CubeMetaMeasureExt for V1CubeMetaMeasure {
2525

2626
agg_type.eq(&"countDistinct".to_string())
2727
|| agg_type.eq(&"countDistinctApprox".to_string())
28+
|| agg_type.eq(&"number".to_string())
2829
} else if expect_agg_type.eq(&"sum".to_string()) {
2930
let agg_type = self.agg_type.as_ref().unwrap();
3031

@@ -42,7 +43,9 @@ impl V1CubeMetaMeasureExt for V1CubeMetaMeasure {
4243
|| agg_type.eq(&"boolean".to_string())
4344
|| agg_type.eq(expect_agg_type)
4445
} else {
45-
self.agg_type.as_ref().unwrap().eq(expect_agg_type)
46+
let agg_type = self.agg_type.as_ref().unwrap();
47+
48+
agg_type.eq(&"number".to_string()) || agg_type.eq(expect_agg_type)
4649
}
4750
} else {
4851
false

0 commit comments

Comments
 (0)