소스 검색

Refactor group by query generation

Sven Klemm 7 년 전
부모
커밋
a86e77fc68
1개의 변경된 파일22개의 추가작업 그리고 16개의 파일을 삭제
  1. 22 16
      public/app/plugins/datasource/postgres/postgres_query.ts

+ 22 - 16
public/app/plugins/datasource/postgres/postgres_query.ts

@@ -242,22 +242,10 @@ export default class PostgresQuery {
     return query;
     return query;
   }
   }
 
 
-  buildQuery(target) {
-    var 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);
+  buildGroupByClause(target) {
+    let query = '';
+    let groupBySection = '';
 
 
-    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';