Move aggragation query to its own query template

This commit is contained in:
Daniel García Aubert
2017-09-14 12:18:03 +02:00
parent 3682740f08
commit 65dca454f4
+38 -27
View File
@@ -165,6 +165,36 @@ const categoriesCTESqlTpl = ctx => `
const aggregationFnQueryTpl = ctx => `${ctx.aggregation}(${ctx.aggregationColumn})`;
const aggregationSqlTpl = ctx => `
${categoriesCTESqlTpl({
query: ctx.query,
column: ctx.column,
aggregation: ctx.aggregation,
aggregationColumn: ctx.aggregationColumn,
isFloatColumn: ctx.isFloatColumn
})}
${!!ctx.override.ownFilter ?
`${aggregationQueryTpl({
_isFloatColumn: ctx.isFloatColumn,
_query: ctx.query,
_column: ctx.column,
_aggregation: aggregationFnQueryTpl({
aggregation: ctx.aggregation,
aggregationColumn: ctx.aggregationColumn || 1
}),
_limit: CATEGORIES_LIMIT
})
}` :
`${rankedAggregationQueryTpl({
_isFloatColumn: ctx.isFloatColumn,
_query: ctx.query,
_column: ctx.column,
_aggregationFn: ctx.aggregation !== 'count' ? ctx.aggregation : 'sum',
_limit: CATEGORIES_LIMIT
})}
`}
`;
const CATEGORIES_LIMIT = 6;
const VALID_OPERATIONS = {
@@ -240,33 +270,14 @@ Aggregation.prototype.sql = function(psql, override, callback) {
return null;
}
var aggregationSql = `
${categoriesCTESqlTpl({
query: this.query,
column: this.column,
aggregation: this.aggregation,
aggregationColumn: this.aggregationColumn,
isFloatColumn: this._isFloatColumn
})}
${!!override.ownFilter ?
`${aggregationQueryTpl({
_isFloatColumn: this._isFloatColumn,
_query: this.query,
_column: this.column,
_aggregation: aggregationFnQueryTpl({
aggregation: this.aggregation,
aggregationColumn: this.aggregationColumn || 1
}),
_limit: CATEGORIES_LIMIT
})}` :
`${rankedAggregationQueryTpl({
_isFloatColumn: this._isFloatColumn,
_query: this.query,
_column: this.column,
_aggregationFn: this.aggregation !== 'count' ? this.aggregation : 'sum',
_limit: CATEGORIES_LIMIT
})}`}
`;
var aggregationSql = aggregationSqlTpl({
override: override,
query: this.query,
column: this.column,
aggregation: this.aggregation,
aggregationColumn: this.aggregationColumn,
isFloatColumn: this._isFloatColumn
});
debug(aggregationSql);