mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Refactor group by query generation
This commit is contained in:
parent
b9edc3c611
commit
a86e77fc68
@ -242,22 +242,10 @@ export default class PostgresQuery {
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildQuery(target) {
|
buildGroupByClause(target) {
|
||||||
var query = 'SELECT ';
|
let query = '';
|
||||||
|
let groupBySection = '';
|
||||||
|
|
||||||
query += this.buildTimeColumn(target);
|
|
||||||
|
|
||||||
if (this.target.metricColumn !== 'None') {
|
|
||||||
query += ',' + this.target.metricColumn + ' AS metric';
|
|
||||||
}
|
|
||||||
|
|
||||||
query += this.buildValueColumns(target);
|
|
||||||
|
|
||||||
query += ' FROM ' + target.schema + '.' + target.table;
|
|
||||||
|
|
||||||
query += this.buildWhereClause(target);
|
|
||||||
|
|
||||||
var groupBySection = '';
|
|
||||||
for (let i = 0; i < this.groupByParts.length; i++) {
|
for (let i = 0; i < this.groupByParts.length; i++) {
|
||||||
var part = this.groupByParts[i];
|
var part = this.groupByParts[i];
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
@ -271,11 +259,29 @@ export default class PostgresQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (groupBySection.length) {
|
if (groupBySection.length) {
|
||||||
query += ' GROUP BY ' + groupBySection;
|
query = ' GROUP BY ' + groupBySection;
|
||||||
if (this.target.metricColumn !== 'None') {
|
if (this.target.metricColumn !== 'None') {
|
||||||
query += ',2';
|
query += ',2';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildQuery(target) {
|
||||||
|
let query = 'SELECT ';
|
||||||
|
|
||||||
|
query += this.buildTimeColumn(target);
|
||||||
|
|
||||||
|
if (this.target.metricColumn !== 'None') {
|
||||||
|
query += ',' + this.target.metricColumn + ' AS metric';
|
||||||
|
}
|
||||||
|
|
||||||
|
query += this.buildValueColumns(target);
|
||||||
|
|
||||||
|
query += ' FROM ' + target.schema + '.' + target.table;
|
||||||
|
|
||||||
|
query += this.buildWhereClause(target);
|
||||||
|
query += this.buildGroupByClause(target);
|
||||||
|
|
||||||
query += ' ORDER BY 1';
|
query += ' ORDER BY 1';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user