Skip to content

Commit

Permalink
Merge branch 'master' of github.com:grafana/grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelo committed Sep 10, 2018
2 parents 34567bc + 7e0637a commit 17e99bb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion public/app/features/dashboard/dashgrid/DashboardGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
for (const panel of this.dashboard.panels) {
const panelClasses = classNames({ panel: true, 'panel--fullscreen': panel.fullscreen });
panelElements.push(
<div key={panel.id.toString()} className={panelClasses}>
/** panel-id is set for html bookmarks */
<div key={panel.id.toString()} className={panelClasses} id={`panel-${panel.id.toString()}`}>
<DashboardPanel panel={panel} getPanelContainer={this.props.getPanelContainer} />
</div>
);
Expand Down
15 changes: 10 additions & 5 deletions public/app/plugins/datasource/postgres/postgres_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ export default class PostgresQuery {
}

quoteIdentifier(value) {
return '"' + value.replace(/"/g, '""') + '"';
return '"' + String(value).replace(/"/g, '""') + '"';
}

quoteLiteral(value) {
return "'" + value.replace(/'/g, "''") + "'";
return "'" + String(value).replace(/'/g, "''") + "'";
}

escapeLiteral(value) {
return value.replace(/'/g, "''");
return String(value).replace(/'/g, "''");
}

hasTimeGroup() {
Expand Down Expand Up @@ -187,7 +187,8 @@ export default class PostgresQuery {
case 'increase':
curr = query;
prev = 'lag(' + curr + ') OVER (' + over + ')';
query = '(CASE WHEN ' + curr + ' >= ' + prev + ' THEN ' + curr + ' - ' + prev + ' ELSE ' + curr + ' END)';
query = '(CASE WHEN ' + curr + ' >= ' + prev + ' THEN ' + curr + ' - ' + prev;
query += ' WHEN ' + prev + ' IS NULL THEN NULL ELSE ' + curr + ' END)';
break;
case 'rate':
let timeColumn = this.target.timeColumn;
Expand All @@ -197,7 +198,8 @@ export default class PostgresQuery {

curr = query;
prev = 'lag(' + curr + ') OVER (' + over + ')';
query = '(CASE WHEN ' + curr + ' >= ' + prev + ' THEN ' + curr + ' - ' + prev + ' ELSE ' + curr + ' END)';
query = '(CASE WHEN ' + curr + ' >= ' + prev + ' THEN ' + curr + ' - ' + prev;
query += ' WHEN ' + prev + ' IS NULL THEN NULL ELSE ' + curr + ' END)';
query += '/extract(epoch from ' + timeColumn + ' - lag(' + timeColumn + ') OVER (' + over + '))';
break;
default:
Expand Down Expand Up @@ -279,6 +281,9 @@ export default class PostgresQuery {
query += this.buildGroupClause();

query += '\nORDER BY 1';
if (this.hasMetricColumn()) {
query += ',2';
}

return query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ describe('PostgresQuery', () => {
{ type: 'window', params: ['increase'] },
];
expect(query.buildValueColumn(column)).toBe(
'(CASE WHEN v >= lag(v) OVER (ORDER BY time) THEN v - lag(v) OVER (ORDER BY time) ELSE v END) AS "a"'
'(CASE WHEN v >= lag(v) OVER (ORDER BY time) ' +
'THEN v - lag(v) OVER (ORDER BY time) ' +
'WHEN lag(v) OVER (ORDER BY time) IS NULL THEN NULL ELSE v END) AS "a"'
);
});

Expand All @@ -96,7 +98,9 @@ describe('PostgresQuery', () => {
{ type: 'window', params: ['increase'] },
];
expect(query.buildValueColumn(column)).toBe(
'(CASE WHEN v >= lag(v) OVER (PARTITION BY host ORDER BY time) THEN v - lag(v) OVER (PARTITION BY host ORDER BY time) ELSE v END) AS "a"'
'(CASE WHEN v >= lag(v) OVER (PARTITION BY host ORDER BY time) ' +
'THEN v - lag(v) OVER (PARTITION BY host ORDER BY time) ' +
'WHEN lag(v) OVER (PARTITION BY host ORDER BY time) IS NULL THEN NULL ELSE v END) AS "a"'
);
column = [
{ type: 'column', params: ['v'] },
Expand All @@ -106,7 +110,8 @@ describe('PostgresQuery', () => {
];
expect(query.buildValueColumn(column)).toBe(
'(CASE WHEN max(v) >= lag(max(v)) OVER (PARTITION BY host ORDER BY time) ' +
'THEN max(v) - lag(max(v)) OVER (PARTITION BY host ORDER BY time) ELSE max(v) END) AS "a"'
'THEN max(v) - lag(max(v)) OVER (PARTITION BY host ORDER BY time) ' +
'WHEN lag(max(v)) OVER (PARTITION BY host ORDER BY time) IS NULL THEN NULL ELSE max(v) END) AS "a"'
);
});

Expand Down Expand Up @@ -149,7 +154,7 @@ describe('PostgresQuery', () => {
expect(query.buildQuery()).toBe(result);

query.target.metricColumn = 'm';
result = 'SELECT\n t AS "time",\n m AS metric,\n value\nFROM table\nORDER BY 1';
result = 'SELECT\n t AS "time",\n m AS metric,\n value\nFROM table\nORDER BY 1,2';
expect(query.buildQuery()).toBe(result);
});
});

0 comments on commit 17e99bb

Please sign in to comment.