moving 'other' outside of the query allowing queries of different types

This commit is contained in:
Simon Martín 2018-01-26 15:24:21 +01:00
parent bc7a556297
commit 99421b613c

View File

@ -87,7 +87,7 @@ const rankedAggregationQueryTpl = ctx => `
WHERE rank < ${ctx.limit} WHERE rank < ${ctx.limit}
UNION ALL UNION ALL
SELECT SELECT
'Other' category, null category,
${ctx.aggregation !== 'count' ? ctx.aggregation : 'sum'}(value) as value, ${ctx.aggregation !== 'count' ? ctx.aggregation : 'sum'}(value) as value,
true as agg, true as agg,
nulls_count, nulls_count,
@ -282,7 +282,7 @@ module.exports = class Aggregation extends BaseDataview {
max_val = 0, max_val = 0,
categories_count = 0 categories_count = 0
} = result.rows[0] || {}; } = result.rows[0] || {};
return { return {
aggregation: this.aggregation, aggregation: this.aggregation,
count: count, count: count,
@ -292,7 +292,13 @@ module.exports = class Aggregation extends BaseDataview {
min: min_val, min: min_val,
max: max_val, max: max_val,
categoriesCount: categories_count, categoriesCount: categories_count,
categories: result.rows.map(({ category, value, agg }) => ({ category, value, agg })) categories: result.rows.map(({ category, value, agg }) => {
return {
category: agg ? 'Others' : category,
value,
agg
};
})
}; };
} }