camel case
This commit is contained in:
@@ -83,7 +83,7 @@ module.exports = class AggregationMapConfig extends MapConfig {
|
||||
}
|
||||
|
||||
getAggregatedQuery (index) {
|
||||
const { sql_raw, sql } = this.getLayer(index).options;
|
||||
const { sql_raw: sqlRaw, sql } = this.getLayer(index).options;
|
||||
const {
|
||||
// The default aggregation has no placement, columns or dimensions;
|
||||
// this enables the special "full-sample" aggregation.
|
||||
@@ -96,7 +96,7 @@ module.exports = class AggregationMapConfig extends MapConfig {
|
||||
} = this.getAggregation(index);
|
||||
|
||||
return aggregationQuery({
|
||||
query: sql_raw || sql,
|
||||
query: sqlRaw || sql,
|
||||
resolution,
|
||||
threshold,
|
||||
placement,
|
||||
|
||||
@@ -51,22 +51,22 @@ module.exports.infoForOptions = (options) => {
|
||||
|
||||
const SUPPORTED_AGGREGATE_FUNCTIONS = {
|
||||
count: {
|
||||
sql: (column_name, params) => `count(${params.aggregated_column || '*'})`
|
||||
sql: (columnName, params) => `count(${params.aggregated_column || '*'})`
|
||||
},
|
||||
avg: {
|
||||
sql: (column_name, params) => `avg(${params.aggregated_column || column_name})`
|
||||
sql: (columnName, params) => `avg(${params.aggregated_column || columnName})`
|
||||
},
|
||||
sum: {
|
||||
sql: (column_name, params) => `sum(${params.aggregated_column || column_name})`
|
||||
sql: (columnName, params) => `sum(${params.aggregated_column || columnName})`
|
||||
},
|
||||
min: {
|
||||
sql: (column_name, params) => `min(${params.aggregated_column || column_name})`
|
||||
sql: (columnName, params) => `min(${params.aggregated_column || columnName})`
|
||||
},
|
||||
max: {
|
||||
sql: (column_name, params) => `max(${params.aggregated_column || column_name})`
|
||||
sql: (columnName, params) => `max(${params.aggregated_column || columnName})`
|
||||
},
|
||||
mode: {
|
||||
sql: (column_name, params) => `mode() WITHIN GROUP (ORDER BY ${params.aggregated_column || column_name})`
|
||||
sql: (columnName, params) => `mode() WITHIN GROUP (ORDER BY ${params.aggregated_column || columnName})`
|
||||
}
|
||||
};
|
||||
|
||||
@@ -85,20 +85,20 @@ const aggregateColumns = ctx => {
|
||||
}, ctx.columns || {});
|
||||
};
|
||||
|
||||
const aggregateExpression = (column_name, column_parameters) => {
|
||||
const aggregate_function = column_parameters.aggregate_function || 'count';
|
||||
const aggregate_definition = SUPPORTED_AGGREGATE_FUNCTIONS[aggregate_function];
|
||||
if (!aggregate_definition) {
|
||||
throw new Error("Invalid Aggregate function: '" + aggregate_function + "'");
|
||||
const aggregateExpression = (columnName, columnParameters) => {
|
||||
const aggregateFunction = columnParameters.aggregate_function || 'count';
|
||||
const aggregateDefinition = SUPPORTED_AGGREGATE_FUNCTIONS[aggregateFunction];
|
||||
if (!aggregateDefinition) {
|
||||
throw new Error("Invalid Aggregate function: '" + aggregateFunction + "'");
|
||||
}
|
||||
return aggregate_definition.sql(column_name, column_parameters);
|
||||
return aggregateDefinition.sql(columnName, columnParameters);
|
||||
};
|
||||
|
||||
const aggregateColumnDefs = ctx => {
|
||||
const columns = aggregateColumns(ctx);
|
||||
return sep(Object.keys(columns).map(column_name => {
|
||||
const aggregate_expression = aggregateExpression(column_name, columns[column_name]);
|
||||
return `${aggregate_expression} AS ${column_name}`;
|
||||
return sep(Object.keys(columns).map(columnName => {
|
||||
const aggregate = aggregateExpression(columnName, columns[columnName]);
|
||||
return `${aggregate} AS ${columnName}`;
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -241,17 +241,17 @@ const filterConditions = ctx => {
|
||||
const columns = aggregateColumns(ctx);
|
||||
const dimensions = aggregateDimensions(ctx);
|
||||
const filters = aggregateFilters(ctx);
|
||||
return Object.keys(filters).map(filtered_column => {
|
||||
let filtered_expr;
|
||||
if (columns[filtered_column]) {
|
||||
filtered_expr = aggregateExpression(filtered_column, columns[filtered_column]);
|
||||
} else if (dimensions[filtered_column]) {
|
||||
filtered_expr = dimensions[filtered_column];
|
||||
return Object.keys(filters).map(filteredColumn => {
|
||||
let filteredExpr;
|
||||
if (columns[filteredColumn]) {
|
||||
filteredExpr = aggregateExpression(filteredColumn, columns[filteredColumn]);
|
||||
} else if (dimensions[filteredColumn]) {
|
||||
filteredExpr = dimensions[filteredColumn];
|
||||
}
|
||||
if (!filtered_expr) {
|
||||
throw new Error("Invalid filtered column: '" + filtered_column + "'");
|
||||
if (!filteredExpr) {
|
||||
throw new Error("Invalid filtered column: '" + filteredColumn + "'");
|
||||
}
|
||||
return filterConditionSQL(filtered_expr, filters[filtered_column]);
|
||||
return filterConditionSQL(filteredExpr, filters[filteredColumn]);
|
||||
}).join(' AND ');
|
||||
};
|
||||
|
||||
|
||||
@@ -90,10 +90,10 @@ function createAggregationColumnNamesValidator (mapconfig) {
|
||||
function createAggregateFunctionValidator (mapconfig, validAggregatedFunctions) {
|
||||
return function validateAggregateFunction (value, key, index) {
|
||||
Object.keys(value).forEach((columnName) => {
|
||||
const { aggregate_function } = value[columnName];
|
||||
const { aggregate_function: aggregateFunction } = value[columnName];
|
||||
|
||||
if (!validAggregatedFunctions.includes(aggregate_function)) {
|
||||
const message = `Unsupported aggregation function ${aggregate_function},` +
|
||||
if (!validAggregatedFunctions.includes(aggregateFunction)) {
|
||||
const message = `Unsupported aggregation function ${aggregateFunction},` +
|
||||
` valid ones: ${validAggregatedFunctions.join(', ')}`;
|
||||
throw createLayerError(message, mapconfig, index);
|
||||
}
|
||||
@@ -104,9 +104,9 @@ function createAggregateFunctionValidator (mapconfig, validAggregatedFunctions)
|
||||
function createAggregatedColumnValidator (mapconfig) {
|
||||
return function validateAggregatedColumn (value, key, index) {
|
||||
Object.keys(value).forEach((columnName) => {
|
||||
const { aggregated_column } = value[columnName];
|
||||
const { aggregated_column: aggregatedColumn } = value[columnName];
|
||||
|
||||
if (typeof aggregated_column !== 'string' || aggregated_column <= 0) {
|
||||
if (typeof aggregatedColumn !== 'string' || aggregatedColumn <= 0) {
|
||||
const message = 'Invalid aggregated column, should be a non empty string';
|
||||
throw createLayerError(message, mapconfig, index);
|
||||
}
|
||||
|
||||
@@ -187,12 +187,12 @@ function validateParameters (params, checker) {
|
||||
if (missingParams.length) {
|
||||
errors.push(`Missing parameters: ${missingParams.join(', ')}`);
|
||||
}
|
||||
const params_errors = checker(params);
|
||||
errors.push(...params_errors.errors);
|
||||
const paramsErrors = checker(params);
|
||||
errors.push(...paramsErrors.errors);
|
||||
if (errors.length) {
|
||||
throw new Error(`Invalid time dimension:\n${errors.join('\n')}`);
|
||||
}
|
||||
return params_errors.params;
|
||||
return paramsErrors.params;
|
||||
}
|
||||
|
||||
const VALID_CYCLIC_UNITS = Object.keys(cyclicParts);
|
||||
|
||||
@@ -91,16 +91,16 @@ module.exports = class Formula extends BaseDataview {
|
||||
const {
|
||||
result = 0,
|
||||
nulls_count = 0,
|
||||
nans_count,
|
||||
infinities_count
|
||||
nans_count: nansCount,
|
||||
infinities_count: infinitiesCount
|
||||
} = res.rows[0] || {};
|
||||
|
||||
return {
|
||||
operation: this.operation,
|
||||
result,
|
||||
nulls: nulls_count,
|
||||
nans: nans_count,
|
||||
infinities: infinities_count
|
||||
nans: nansCount,
|
||||
infinities: infinitiesCount
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,16 +32,16 @@ WITH __wd_tz AS
|
||||
* our timezone so when calling date_trunc it falls into the correct bin
|
||||
*/
|
||||
function dataBucketsQuery (ctx) {
|
||||
var condition_str = '';
|
||||
var conditionStr = '';
|
||||
|
||||
if (ctx.start !== 0) {
|
||||
condition_str = `WHERE ${ctx.column} >= to_timestamp(${ctx.start})`;
|
||||
conditionStr = `WHERE ${ctx.column} >= to_timestamp(${ctx.start})`;
|
||||
}
|
||||
if (ctx.end !== 0) {
|
||||
if (condition_str === '') {
|
||||
condition_str = `WHERE ${ctx.column} <= to_timestamp(${ctx.end})`;
|
||||
if (conditionStr === '') {
|
||||
conditionStr = `WHERE ${ctx.column} <= to_timestamp(${ctx.end})`;
|
||||
} else {
|
||||
condition_str += ` and ${ctx.column} <= to_timestamp(${ctx.end})`;
|
||||
conditionStr += ` and ${ctx.column} <= to_timestamp(${ctx.end})`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ __wd_buckets AS
|
||||
(
|
||||
${ctx.query}
|
||||
) __source, __wd_tz
|
||||
${condition_str}
|
||||
${conditionStr}
|
||||
GROUP BY 1, __wd_tz.name
|
||||
),`;
|
||||
}
|
||||
@@ -67,22 +67,22 @@ __wd_buckets AS
|
||||
* the dataBucketsQuery
|
||||
*/
|
||||
function allBucketsArrayQuery (ctx) {
|
||||
var extra_from = '';
|
||||
var series_start = '';
|
||||
var series_end = '';
|
||||
var extraFrom = '';
|
||||
var seriesStart = '';
|
||||
var seriesEnd = '';
|
||||
|
||||
if (ctx.start === 0) {
|
||||
extra_from = ', __wd_buckets GROUP BY __wd_tz.name';
|
||||
series_start = 'min(__wd_buckets.timestamp)';
|
||||
extraFrom = ', __wd_buckets GROUP BY __wd_tz.name';
|
||||
seriesStart = 'min(__wd_buckets.timestamp)';
|
||||
} else {
|
||||
series_start = `date_trunc('${ctx.aggregation}', timezone(__wd_tz.name, to_timestamp(${ctx.start})))`;
|
||||
seriesStart = `date_trunc('${ctx.aggregation}', timezone(__wd_tz.name, to_timestamp(${ctx.start})))`;
|
||||
}
|
||||
|
||||
if (ctx.end === 0) {
|
||||
extra_from = ', __wd_buckets GROUP BY __wd_tz.name';
|
||||
series_end = 'max(__wd_buckets.timestamp)';
|
||||
extraFrom = ', __wd_buckets GROUP BY __wd_tz.name';
|
||||
seriesEnd = 'max(__wd_buckets.timestamp)';
|
||||
} else {
|
||||
series_end = `date_trunc('${ctx.aggregation}', timezone(__wd_tz.name, to_timestamp(${ctx.end})))`;
|
||||
seriesEnd = `date_trunc('${ctx.aggregation}', timezone(__wd_tz.name, to_timestamp(${ctx.end})))`;
|
||||
}
|
||||
|
||||
return `
|
||||
@@ -91,10 +91,10 @@ __wd_all_buckets AS
|
||||
SELECT ARRAY(
|
||||
SELECT
|
||||
generate_series(
|
||||
${series_start},
|
||||
${series_end},
|
||||
${seriesStart},
|
||||
${seriesEnd},
|
||||
interval '${ctx.interval}') as bin_start
|
||||
FROM __wd_tz${extra_from}
|
||||
FROM __wd_tz${extraFrom}
|
||||
) as bins
|
||||
)`;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
|
||||
},
|
||||
batch: {
|
||||
username: this.user,
|
||||
apiKey: apiKey
|
||||
apiKey
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user