Do not prefix with '_' template context
This commit is contained in:
parent
c7ed3d34e8
commit
419b29e609
@ -2,32 +2,32 @@ const BaseDataview = require('./base');
|
|||||||
const debug = require('debug')('windshaft:dataview:formula');
|
const debug = require('debug')('windshaft:dataview:formula');
|
||||||
|
|
||||||
const countInfinitiesQueryTpl = ctx => `
|
const countInfinitiesQueryTpl = ctx => `
|
||||||
SELECT count(1) FROM (${ctx._query}) __cdb_formula_infinities
|
SELECT count(1) FROM (${ctx.query}) __cdb_formula_infinities
|
||||||
WHERE ${ctx._column} = 'infinity'::float OR ${ctx._column} = '-infinity'::float
|
WHERE ${ctx.column} = 'infinity'::float OR ${ctx.column} = '-infinity'::float
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const countNansQueryTpl = ctx => `
|
const countNansQueryTpl = ctx => `
|
||||||
SELECT count(1) FROM (${ctx._query}) __cdb_formula_nans
|
SELECT count(1) FROM (${ctx.query}) __cdb_formula_nans
|
||||||
WHERE ${ctx._column} = 'NaN'::float
|
WHERE ${ctx.column} = 'NaN'::float
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const filterOutSpecialNumericValuesTpl = ctx => `
|
const filterOutSpecialNumericValuesTpl = ctx => `
|
||||||
WHERE
|
WHERE
|
||||||
${ctx._column} != 'infinity'::float
|
${ctx.column} != 'infinity'::float
|
||||||
AND
|
AND
|
||||||
${ctx._column} != '-infinity'::float
|
${ctx.column} != '-infinity'::float
|
||||||
AND
|
AND
|
||||||
${ctx._column} != 'NaN'::float
|
${ctx.column} != 'NaN'::float
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const formulaQueryTpl = ctx => `
|
const formulaQueryTpl = ctx => `
|
||||||
SELECT
|
SELECT
|
||||||
${ctx._operation}(${ctx._column}) AS result,
|
${ctx.operation}(${ctx.column}) AS result,
|
||||||
(SELECT count(1) FROM (${ctx._query}) _cdb_formula_nulls WHERE ${ctx._column} IS NULL) AS nulls_count
|
(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 ? `,(${countInfinitiesQueryTpl(ctx)}) AS infinities_count` : ''}
|
||||||
${ctx._isFloatColumn ? `,(${countNansQueryTpl(ctx)}) AS nans_count` : ''}
|
${ctx.isFloatColumn ? `,(${countNansQueryTpl(ctx)}) AS nans_count` : ''}
|
||||||
FROM (${ctx._query}) __cdb_formula
|
FROM (${ctx.query}) __cdb_formula
|
||||||
${ctx._isFloatColumn && ctx._operation !== 'count' ? `${filterOutSpecialNumericValuesTpl(ctx)}` : ''}
|
${ctx.isFloatColumn && ctx.operation !== 'count' ? `${filterOutSpecialNumericValuesTpl(ctx)}` : ''}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const VALID_OPERATIONS = {
|
const VALID_OPERATIONS = {
|
||||||
@ -93,10 +93,10 @@ module.exports = class Formula extends BaseDataview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formulaSql = formulaQueryTpl({
|
const formulaSql = formulaQueryTpl({
|
||||||
_isFloatColumn: this._isFloatColumn,
|
isFloatColumn: this._isFloatColumn,
|
||||||
_query: this.query,
|
query: this.query,
|
||||||
_operation: this.operation,
|
operation: this.operation,
|
||||||
_column: this.column
|
column: this.column
|
||||||
});
|
});
|
||||||
|
|
||||||
debug(formulaSql);
|
debug(formulaSql);
|
||||||
|
Loading…
Reference in New Issue
Block a user