Skip to content

Commit 50ce569

Browse files
committed
Fix aggregate whitespace handling
1 parent 6001370 commit 50ce569

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

yardstick-rs/src/sql/measures.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3767,10 +3767,10 @@ fn extract_dimension_columns_from_select(sql: &str) -> Vec<String> {
37673767

37683768
// Filter out AGGREGATE() calls and extract column names
37693769
for item in items {
3770-
let item_upper = item.to_uppercase();
3771-
if item_upper.contains("AGGREGATE(") {
3770+
if has_aggregate_function(&item) {
37723771
continue;
37733772
}
3773+
let item_upper = item.to_uppercase();
37743774
// Handle "col AS alias" - use the column name, not alias
37753775
let col = if let Some(as_pos) = item_upper.find(" AS ") {
37763776
item[..as_pos].trim()
@@ -3807,9 +3807,28 @@ mod tests {
38073807
#[test]
38083808
fn test_has_aggregate_function() {
38093809
assert!(has_aggregate_function("SELECT AGGREGATE(revenue) FROM foo"));
3810+
assert!(has_aggregate_function("SELECT AGGREGATE (revenue) FROM foo"));
38103811
assert!(!has_aggregate_function("SELECT SUM(amount) FROM foo"));
38113812
}
38123813

3814+
#[test]
3815+
fn test_extract_dimension_columns_ignores_aggregate_with_space() {
3816+
let cols = extract_dimension_columns_from_select(
3817+
"SELECT region, AGGREGATE (revenue) FROM sales_v",
3818+
);
3819+
assert_eq!(cols, vec!["region".to_string()]);
3820+
3821+
let cols = extract_dimension_columns_from_select(
3822+
"SELECT region, AGGREGATE (revenue) AT (ALL region) FROM sales_v",
3823+
);
3824+
assert_eq!(cols, vec!["region".to_string()]);
3825+
3826+
let cols = extract_dimension_columns_from_select(
3827+
"SELECT AGGREGATE (revenue) FROM sales_v",
3828+
);
3829+
assert!(cols.is_empty());
3830+
}
3831+
38133832
#[test]
38143833
#[serial]
38153834
fn test_process_create_view_basic() {

0 commit comments

Comments
 (0)