postgres: add char format for itemid

This commit is contained in:
Alexander Zobnin
2017-10-17 19:36:24 +03:00
parent 3341b8f1f9
commit 1ad2333907
4 changed files with 16 additions and 15 deletions

View File

@@ -3,7 +3,7 @@
System.register(['angular', 'lodash'], function (_export, _context) {
"use strict";
var angular, _, _createClass, DEFAULT_QUERY_LIMIT, HISTORY_TO_TABLE_MAP, TREND_TO_TABLE_MAP, consolidateByFunc, consolidateByTrendColumns, TEST_MYSQL_QUERY, TEST_POSTGRES_QUERY;
var angular, _, _createClass, DEFAULT_QUERY_LIMIT, HISTORY_TO_TABLE_MAP, TREND_TO_TABLE_MAP, consolidateByFunc, consolidateByTrendColumns, TEST_MYSQL_QUERY, itemid_format, TEST_POSTGRES_QUERY;
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
@@ -226,19 +226,15 @@ System.register(['angular', 'lodash'], function (_export, _context) {
return query;
}
////////////////
// PostgreSQL //
////////////////
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
var query = '\n SELECT DISTINCT to_char(itemid, \'FM9999999999999\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(value) OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, value\n ORDER BY time ASC\n ';
var query = '\n SELECT DISTINCT to_char(itemid, \'' + itemid_format + '\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(value) OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, value\n ORDER BY time ASC\n ';
return query;
}
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
var query = '\n SELECT DISTINCT to_char(itemid, \'FM9999999999999\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(' + valueColumn + ') OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, ' + valueColumn + '\n ORDER BY time ASC\n ';
var query = '\n SELECT DISTINCT to_char(itemid, \'' + itemid_format + '\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(' + valueColumn + ') OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, ' + valueColumn + '\n ORDER BY time ASC\n ';
return query;
}
@@ -292,7 +288,8 @@ System.register(['angular', 'lodash'], function (_export, _context) {
'max': 'value_max'
};
angular.module('grafana.services').factory('ZabbixDBConnector', ZabbixDBConnectorFactory);TEST_MYSQL_QUERY = 'SELECT itemid AS metric, clock AS time_sec, value_avg AS value FROM trends_uint LIMIT 1';
TEST_POSTGRES_QUERY = '\n SELECT to_char(itemid, \'FM9999999999999\') AS metric, clock AS time, value_avg AS value\n FROM trends_uint LIMIT 1\n';
itemid_format = 'FM99999999999999999999';
TEST_POSTGRES_QUERY = '\n SELECT to_char(itemid, \'' + itemid_format + '\') AS metric, clock AS time, value_avg AS value\n FROM trends_uint LIMIT 1\n';
}
};
});

File diff suppressed because one or more lines are too long

View File

@@ -270,16 +270,18 @@ var TEST_MYSQL_QUERY = 'SELECT itemid AS metric, clock AS time_sec, value_avg AS
// PostgreSQL //
////////////////
var itemid_format = 'FM99999999999999999999';
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
var query = '\n SELECT DISTINCT to_char(itemid, \'FM9999999999999\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(value) OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, value\n ORDER BY time ASC\n ';
var query = '\n SELECT DISTINCT to_char(itemid, \'' + itemid_format + '\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(value) OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, value\n ORDER BY time ASC\n ';
return query;
}
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
var time_expression = 'clock / ' + intervalSec + ' * ' + intervalSec;
var query = '\n SELECT DISTINCT to_char(itemid, \'FM9999999999999\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(' + valueColumn + ') OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, ' + valueColumn + '\n ORDER BY time ASC\n ';
var query = '\n SELECT DISTINCT to_char(itemid, \'' + itemid_format + '\') AS metric,\n ' + time_expression + ' AS time,\n ' + aggFunction + '(' + valueColumn + ') OVER (PARTITION BY clock / ' + intervalSec + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY metric, clock, ' + valueColumn + '\n ORDER BY time ASC\n ';
return query;
}
var TEST_POSTGRES_QUERY = '\n SELECT to_char(itemid, \'FM9999999999999\') AS metric, clock AS time, value_avg AS value\n FROM trends_uint LIMIT 1\n';
var TEST_POSTGRES_QUERY = '\n SELECT to_char(itemid, \'' + itemid_format + '\') AS metric, clock AS time, value_avg AS value\n FROM trends_uint LIMIT 1\n';

View File

@@ -241,10 +241,12 @@ const TEST_MYSQL_QUERY = `SELECT itemid AS metric, clock AS time_sec, value_avg
// PostgreSQL //
////////////////
const itemid_format = 'FM99999999999999999999';
function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction) {
let time_expression = `clock / ${intervalSec} * ${intervalSec}`;
let query = `
SELECT DISTINCT to_char(itemid, 'FM9999999999999') AS metric,
SELECT DISTINCT to_char(itemid, '${itemid_format}') AS metric,
${time_expression} AS time,
${aggFunction}(value) OVER (PARTITION BY clock / ${intervalSec}) AS value
FROM ${table}
@@ -259,7 +261,7 @@ function buildPostgresHistoryQuery(itemids, table, timeFrom, timeTill, intervalS
function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSec, aggFunction, valueColumn) {
let time_expression = `clock / ${intervalSec} * ${intervalSec}`;
let query = `
SELECT DISTINCT to_char(itemid, 'FM9999999999999') AS metric,
SELECT DISTINCT to_char(itemid, '${itemid_format}') AS metric,
${time_expression} AS time,
${aggFunction}(${valueColumn}) OVER (PARTITION BY clock / ${intervalSec}) AS value
FROM ${table}
@@ -272,6 +274,6 @@ function buildPostgresTrendsQuery(itemids, table, timeFrom, timeTill, intervalSe
}
const TEST_POSTGRES_QUERY = `
SELECT to_char(itemid, 'FM9999999999999') AS metric, clock AS time, value_avg AS value
SELECT to_char(itemid, '${itemid_format}') AS metric, clock AS time, value_avg AS value
FROM trends_uint LIMIT 1
`;