Browse Source

filter datatype for groupby suggestions

Sven Klemm 7 years ago
parent
commit
2fcb09b23d

+ 11 - 6
public/app/plugins/datasource/postgres/query_builder.ts

@@ -1,6 +1,11 @@
 export class PostgresQueryBuilder {
 export class PostgresQueryBuilder {
   constructor(private target, private queryModel) {}
   constructor(private target, private queryModel) {}
 
 
+  // quote identifier as literal to use in metadata queries
+  quoteIdentAsLiteral(value) {
+    return this.queryModel.quoteLiteral(this.queryModel.unquoteIdentifier(value));
+  }
+
   buildSchemaQuery() {
   buildSchemaQuery() {
     let query = 'SELECT quote_ident(schema_name) FROM information_schema.schemata WHERE';
     let query = 'SELECT quote_ident(schema_name) FROM information_schema.schemata WHERE';
     query += " schema_name NOT LIKE 'pg_%' AND schema_name NOT LIKE '\\_%' AND schema_name <> 'information_schema';";
     query += " schema_name NOT LIKE 'pg_%' AND schema_name NOT LIKE '\\_%' AND schema_name <> 'information_schema';";
@@ -14,11 +19,6 @@ export class PostgresQueryBuilder {
     return query;
     return query;
   }
   }
 
 
-  // quote identifier as literal to use in metadata queries
-  quoteIdentAsLiteral(value) {
-    return this.queryModel.quoteLiteral(this.queryModel.unquoteIdentifier(value));
-  }
-
   buildColumnQuery(type?: string) {
   buildColumnQuery(type?: string) {
     let query = 'SELECT quote_ident(column_name) FROM information_schema.columns WHERE ';
     let query = 'SELECT quote_ident(column_name) FROM information_schema.columns WHERE ';
     query += 'table_schema = ' + this.quoteIdentAsLiteral(this.target.schema);
     query += 'table_schema = ' + this.quoteIdentAsLiteral(this.target.schema);
@@ -31,11 +31,16 @@ export class PostgresQueryBuilder {
         break;
         break;
       }
       }
       case 'metric': {
       case 'metric': {
-        query += " AND data_type IN ('text','char','varchar','integer','bigint')";
+        query += " AND data_type IN ('text','char','varchar')";
         break;
         break;
       }
       }
       case 'value': {
       case 'value': {
         query += " AND data_type IN ('bigint','integer','double precision','real')";
         query += " AND data_type IN ('bigint','integer','double precision','real')";
+        query += ' AND column_name <> ' + this.quoteIdentAsLiteral(this.target.timeColumn);
+        break;
+      }
+      case 'groupby': {
+        query += " AND data_type IN ('text','char','varchar')";
         break;
         break;
       }
       }
     }
     }

+ 1 - 1
public/app/plugins/datasource/postgres/query_ctrl.ts

@@ -442,7 +442,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
 
 
   getGroupByOptions() {
   getGroupByOptions() {
     return this.datasource
     return this.datasource
-      .metricFindQuery(this.queryBuilder.buildColumnQuery())
+      .metricFindQuery(this.queryBuilder.buildColumnQuery('groupby'))
       .then(tags => {
       .then(tags => {
         var options = [];
         var options = [];
         if (!this.queryModel.hasGroupByTime()) {
         if (!this.queryModel.hasGroupByTime()) {