Postgres: Fix aggregate dropdown when TimescaleDB is enabled (#45993)

* add timescaleDB checker function

* use existing fn findAggregateIndex

* build options from empty list

* refactor fn and handle state for existing elem

* remove newline
This commit is contained in:
matt abrams 2022-03-02 22:29:37 -10:00 committed by GitHub
parent 1fef87fbcc
commit c863676b65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -111,10 +111,27 @@ export class PostgresQueryCtrl extends QueryCtrl {
this.panelCtrl.refresh();
}
timescaleAggCheck() {
const aggIndex = this.findAggregateIndex(this.selectParts[0]);
// add or remove TimescaleDB aggregate functions as needed
if (aggIndex !== -1) {
const baseOpts = this.selectParts[0][aggIndex].def.params[0].baseOptions;
const timescaleOpts = baseOpts.concat(this.selectParts[0][aggIndex].def.params[0].timescaleOptions);
if (this.datasource.jsonData.timescaledb === true) {
this.selectParts[0][aggIndex].def.params[0].options = timescaleOpts;
} else {
this.selectParts[0][aggIndex].def.params[0].options = baseOpts;
}
}
}
updateProjection() {
this.selectParts = map(this.target.select, (parts: any) => {
return map(parts, sqlPart.create).filter((n) => n);
});
this.timescaleAggCheck();
this.whereParts = map(this.target.where, sqlPart.create).filter((n) => n);
this.groupParts = map(this.target.group, sqlPart.create).filter((n) => n);
}
@ -125,6 +142,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
return { type: part.def.type, datatype: part.datatype, params: part.params };
});
});
this.timescaleAggCheck();
this.target.where = map(this.whereParts, (part: any) => {
return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params };
});

View File

@ -49,7 +49,9 @@ register({
{
name: 'name',
type: 'string',
options: ['avg', 'count', 'min', 'max', 'sum', 'stddev', 'variance'],
options: [],
baseOptions: ['avg', 'count', 'min', 'max', 'sum', 'stddev', 'variance'],
timescaleOptions: ['first', 'last'],
},
],
defaultParams: ['avg'],