rename field to column

This commit is contained in:
Sven Klemm 2018-03-03 20:57:00 +01:00
parent 1a051ce320
commit fd518846b1
3 changed files with 27 additions and 33 deletions

View File

@ -24,7 +24,7 @@ export default class PostgresQuery {
target.orderByTime = target.orderByTime || 'ASC';
target.groupBy = target.groupBy || [];
target.where = target.where || [];
target.select = target.select || [[{ type: 'field', params: ['value'] }]];
target.select = target.select || [[{ type: 'column', params: ['value'] }]];
this.updateProjection();
}
@ -88,8 +88,6 @@ export default class PostgresQuery {
var categories = queryPart.getCategories();
if (part.def.type === 'time') {
// remove fill
this.target.groupBy = _.filter(this.target.groupBy, (g: any) => g.type !== 'fill');
// remove aggregations
this.target.select = _.map(this.target.select, (s: any) => {
return _.filter(s, (part: any) => {
@ -113,7 +111,7 @@ export default class PostgresQuery {
removeSelectPart(selectParts, part) {
// if we remove the field remove the whole statement
if (part.def.type === 'field') {
if (part.def.type === 'column') {
if (this.selectModels.length > 1) {
var modelsIndex = _.indexOf(this.selectModels, selectParts);
this.selectModels.splice(modelsIndex, 1);
@ -189,7 +187,12 @@ export default class PostgresQuery {
}
var query = 'SELECT ';
query += this.quoteIdentifier(target.timeColumn) + ' AS time,';
if (this.hasGroupByTime()) {
query += '$__timeGroup(' + this.quoteIdentifier(target.timeColumn) + ',1m),';
} else {
query += this.quoteIdentifier(target.timeColumn) + ' AS time,';
}
var i, y;
for (i = 0; i < this.selectModels.length; i++) {
@ -221,10 +224,13 @@ export default class PostgresQuery {
for (i = 0; i < this.groupByParts.length; i++) {
var part = this.groupByParts[i];
if (i > 0) {
// for some reason fill has no seperator
groupBySection += part.def.type === 'fill' ? ' ' : ', ';
groupBySection += ', ';
}
if (part.def.type === 'time') {
groupBySection += 'time';
} else {
groupBySection += part.render('');
}
groupBySection += part.render('');
}
if (groupBySection.length) {

View File

@ -92,7 +92,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
this.removeWhereFilterSegment = uiSegmentSrv.newSegment({
fake: true,
value: '-- remove tag filter --',
value: '-- remove filter --',
});
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
@ -390,9 +390,6 @@ export class PostgresQueryCtrl extends QueryCtrl {
.metricFindQuery(this.queryBuilder.buildColumnQuery())
.then(tags => {
var options = [];
if (!this.queryModel.hasFill()) {
options.push(this.uiSegmentSrv.newSegment({ value: 'fill(null)' }));
}
if (!this.target.limit) {
options.push(this.uiSegmentSrv.newSegment({ value: 'LIMIT' }));
}
@ -400,7 +397,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
options.push(this.uiSegmentSrv.newSegment({ value: 'time($interval)' }));
}
for (let tag of tags) {
options.push(this.uiSegmentSrv.newSegment({ value: 'tag(' + tag.text + ')' }));
options.push(this.uiSegmentSrv.newSegment({ value: tag.text }));
}
return options;
})

View File

@ -6,7 +6,7 @@ var categories = {
Aggregations: [],
Math: [],
Aliasing: [],
Fields: [],
Columns: [],
};
function createPart(part): any {
@ -29,7 +29,7 @@ function aliasRenderer(part, innerExpr) {
return innerExpr + ' AS ' + '"' + part.params[0] + '"';
}
function fieldRenderer(part, innerExpr) {
function columnRenderer(part, innerExpr) {
return '"' + part.params[0] + '"';
}
@ -92,7 +92,7 @@ function addAliasStrategy(selectParts, partModel) {
selectParts.push(partModel);
}
function addFieldStrategy(selectParts, partModel, query) {
function addColumnStrategy(selectParts, partModel, query) {
// copy all parts
var parts = _.map(selectParts, function(part: any) {
return createPart({ type: part.def.type, params: _.clone(part.params) });
@ -102,12 +102,12 @@ function addFieldStrategy(selectParts, partModel, query) {
}
register({
type: 'field',
addStrategy: addFieldStrategy,
category: categories.Fields,
params: [{ type: 'field', dynamicLookup: true }],
type: 'column',
addStrategy: addColumnStrategy,
category: categories.Columns,
params: [{ type: 'column', dynamicLookup: true }],
defaultParams: ['value'],
renderer: fieldRenderer,
renderer: columnRenderer,
});
// Aggregations
@ -170,25 +170,16 @@ register({
params: [
{
name: 'interval',
type: 'time',
type: 'interval',
options: ['$__interval', '1s', '10s', '1m', '5m', '10m', '15m', '1h'],
},
],
defaultParams: ['$__interval'],
renderer: functionRenderer,
});
register({
type: 'fill',
category: groupByTimeFunctions,
params: [
{
name: 'fill',
type: 'string',
options: ['none', 'null', '0', 'previous', 'linear'],
options: ['none', 'null', '0'],
},
],
defaultParams: ['null'],
defaultParams: ['$__interval','none'],
renderer: functionRenderer,
});