|
|
|
@ -2,7 +2,6 @@ const BaseDataview = require('./base');
|
|
|
|
|
const debug = require('debug')('windshaft:dataview:aggregation');
|
|
|
|
|
|
|
|
|
|
const filteredQueryTpl = ctx => `
|
|
|
|
|
filtered_source AS (
|
|
|
|
|
SELECT *
|
|
|
|
|
FROM (${ctx.query}) _cdb_filtered_source
|
|
|
|
|
${ctx.aggregationColumn && ctx.isFloatColumn ? `
|
|
|
|
@ -14,7 +13,6 @@ const filteredQueryTpl = ctx => `
|
|
|
|
|
${ctx.aggregationColumn} != 'NaN'::float` :
|
|
|
|
|
''
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const summaryQueryTpl = ctx => `
|
|
|
|
@ -43,7 +41,7 @@ const rankedCategoriesQueryTpl = ctx => `
|
|
|
|
|
${ctx.column} AS category,
|
|
|
|
|
${ctx.aggregationFn} AS value,
|
|
|
|
|
row_number() OVER (ORDER BY ${ctx.aggregationFn} desc) as rank
|
|
|
|
|
FROM filtered_source
|
|
|
|
|
FROM (${filteredQueryTpl(ctx)}) filtered_source
|
|
|
|
|
${ctx.aggregationColumn !== null ? `WHERE ${ctx.aggregationColumn} IS NOT NULL` : ''}
|
|
|
|
|
GROUP BY ${ctx.column}
|
|
|
|
|
ORDER BY 2 DESC
|
|
|
|
@ -134,7 +132,6 @@ const aggregationFnQueryTpl = ctx => `${ctx.aggregation}(${ctx.aggregationColumn
|
|
|
|
|
|
|
|
|
|
const aggregationDataviewQueryTpl = ctx => `
|
|
|
|
|
WITH
|
|
|
|
|
${filteredQueryTpl(ctx)},
|
|
|
|
|
${summaryQueryTpl(ctx)},
|
|
|
|
|
${rankedCategoriesQueryTpl(ctx)},
|
|
|
|
|
${categoriesSummaryMinMaxQueryTpl(ctx)},
|
|
|
|
|