Skip to content

Commit 63af80b

Browse files
update counts api to include group by clauses (#1601)
* update counts api to include group by clauses * default instead of new
1 parent 0aaf25a commit 63af80b

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/query/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,27 @@ impl CountsRequest {
681681
)
682682
};
683683

684+
let group_by_cols = count_conditions
685+
.group_by
686+
.as_ref()
687+
.map(|cols| cols.iter().map(|c| format!("\"{c}\"")).collect::<Vec<_>>())
688+
.unwrap_or_default();
689+
690+
let group_clause = if group_by_cols.is_empty() {
691+
String::default()
692+
} else {
693+
format!(", {}", group_by_cols.join(", "))
694+
};
695+
684696
let query = if let Some(conditions) = &count_conditions.conditions {
685697
let f = get_filter_string(conditions).map_err(QueryError::CustomError)?;
686698
format!(
687-
"SELECT {date_bin}, COUNT(*) as count FROM \"{table_name}\" WHERE {} GROUP BY {end_time_col_name},{start_time_col_name} ORDER BY {end_time_col_name}",
699+
"SELECT {date_bin}{group_clause}, COUNT(*) as count FROM \"{table_name}\" WHERE {} GROUP BY {end_time_col_name},{start_time_col_name}{group_clause} ORDER BY {end_time_col_name}{group_clause}",
688700
f
689701
)
690702
} else {
691703
format!(
692-
"SELECT {date_bin}, COUNT(*) as count FROM \"{table_name}\" GROUP BY {end_time_col_name},{start_time_col_name} ORDER BY {end_time_col_name}",
704+
"SELECT {date_bin}{group_clause}, COUNT(*) as count FROM \"{table_name}\" GROUP BY {end_time_col_name},{start_time_col_name}{group_clause} ORDER BY {end_time_col_name}{group_clause}",
693705
)
694706
};
695707
Ok(query)

0 commit comments

Comments
 (0)