Do not prefix with '_' template context

This commit is contained in:
Daniel García Aubert 2017-09-15 11:39:06 +02:00
parent c7ed3d34e8
commit 419b29e609

View File

@ -2,32 +2,32 @@ const BaseDataview = require('./base');
const debug = require('debug')('windshaft:dataview:formula');
const countInfinitiesQueryTpl = ctx => `
SELECT count(1) FROM (${ctx._query}) __cdb_formula_infinities
WHERE ${ctx._column} = 'infinity'::float OR ${ctx._column} = '-infinity'::float
SELECT count(1) FROM (${ctx.query}) __cdb_formula_infinities
WHERE ${ctx.column} = 'infinity'::float OR ${ctx.column} = '-infinity'::float
`;
const countNansQueryTpl = ctx => `
SELECT count(1) FROM (${ctx._query}) __cdb_formula_nans
WHERE ${ctx._column} = 'NaN'::float
SELECT count(1) FROM (${ctx.query}) __cdb_formula_nans
WHERE ${ctx.column} = 'NaN'::float
`;
const filterOutSpecialNumericValuesTpl = ctx => `
WHERE
${ctx._column} != 'infinity'::float
${ctx.column} != 'infinity'::float
AND
${ctx._column} != '-infinity'::float
${ctx.column} != '-infinity'::float
AND
${ctx._column} != 'NaN'::float
${ctx.column} != 'NaN'::float
`;
const formulaQueryTpl = ctx => `
SELECT
${ctx._operation}(${ctx._column}) AS result,
(SELECT count(1) FROM (${ctx._query}) _cdb_formula_nulls WHERE ${ctx._column} IS NULL) AS nulls_count
${ctx._isFloatColumn ? `,(${countInfinitiesQueryTpl(ctx)}) AS infinities_count` : ''}
${ctx._isFloatColumn ? `,(${countNansQueryTpl(ctx)}) AS nans_count` : ''}
FROM (${ctx._query}) __cdb_formula
${ctx._isFloatColumn && ctx._operation !== 'count' ? `${filterOutSpecialNumericValuesTpl(ctx)}` : ''}
${ctx.operation}(${ctx.column}) AS result,
(SELECT count(1) FROM (${ctx.query}) _cdb_formula_nulls WHERE ${ctx.column} IS NULL) AS nulls_count
${ctx.isFloatColumn ? `,(${countInfinitiesQueryTpl(ctx)}) AS infinities_count` : ''}
${ctx.isFloatColumn ? `,(${countNansQueryTpl(ctx)}) AS nans_count` : ''}
FROM (${ctx.query}) __cdb_formula
${ctx.isFloatColumn && ctx.operation !== 'count' ? `${filterOutSpecialNumericValuesTpl(ctx)}` : ''}
`;
const VALID_OPERATIONS = {
@ -93,10 +93,10 @@ module.exports = class Formula extends BaseDataview {
}
const formulaSql = formulaQueryTpl({
_isFloatColumn: this._isFloatColumn,
_query: this.query,
_operation: this.operation,
_column: this.column
isFloatColumn: this._isFloatColumn,
query: this.query,
operation: this.operation,
column: this.column
});
debug(formulaSql);