Rename BaseWidget by BaseDataview
This commit is contained in:
parent
6b2e2b2241
commit
dcb9b8ec52
@ -1,26 +1,35 @@
|
|||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var BaseWidget = require('./base');
|
var BaseDataview = require('./base');
|
||||||
var debug = require('debug')('windshaft:widget:formula');
|
var debug = require('debug')('windshaft:widget:formula');
|
||||||
|
|
||||||
var dot = require('dot');
|
const countInfinitiesQueryTpl = ctx => `
|
||||||
dot.templateSettings.strip = false;
|
SELECT count(1) FROM (${ctx._query}) __cdb_formula_infinities
|
||||||
|
WHERE ${ctx._column} = 'infinity'::float OR ${ctx._column} = '-infinity'::float
|
||||||
|
`;
|
||||||
|
|
||||||
var formulaQueryTpl = dot.template([
|
const countNansQueryTpl = ctx => `
|
||||||
'SELECT',
|
SELECT count(1) FROM (${ctx._query}) __cdb_formula_nans
|
||||||
' {{=it._operation}}({{=it._column}}) AS result,',
|
WHERE ${ctx._column} = 'NaN'::float
|
||||||
' (SELECT count(1) FROM ({{=it._query}}) _cdb_formula_nulls WHERE {{=it._column}} IS NULL) AS nulls_count',
|
`;
|
||||||
' {{?it._isFloatColumn}},(SELECT count(1) FROM ({{=it._query}}) _cdb_formula_nulls',
|
|
||||||
' WHERE {{=it._column}} = \'infinity\'::float OR {{=it._column}} = \'-infinity\'::float) AS infinities_count',
|
const filterOutSpecialNumericValuesTpl = ctx => `
|
||||||
' ,(SELECT count(1) FROM ({{=it._query}}) _cdb_formula_nulls',
|
WHERE
|
||||||
' WHERE {{=it._column}} = \'NaN\'::float) AS nans_count{{?}}',
|
${ctx._column} != 'infinity'::float
|
||||||
'FROM ({{=it._query}}) _cdb_formula',
|
AND
|
||||||
'{{?it._isFloatColumn && it._operation !== \'count\'}}WHERE',
|
${ctx._column} != '-infinity'::float
|
||||||
' {{=it._column}} != \'infinity\'::float',
|
AND
|
||||||
'AND',
|
${ctx._column} != 'NaN'::float
|
||||||
' {{=it._column}} != \'-infinity\'::float',
|
`;
|
||||||
'AND',
|
|
||||||
' {{=it._column}} != \'NaN\'::float{{?}}'
|
const formulaQueryTpl = ctx => `
|
||||||
].join('\n'));
|
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)}` : ''}
|
||||||
|
`;
|
||||||
|
|
||||||
var VALID_OPERATIONS = {
|
var VALID_OPERATIONS = {
|
||||||
count: true,
|
count: true,
|
||||||
@ -54,7 +63,7 @@ function Formula(query, options, queries) {
|
|||||||
throw new Error('Formula expects `column` in widget options');
|
throw new Error('Formula expects `column` in widget options');
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseWidget.apply(this);
|
BaseDataview.apply(this);
|
||||||
|
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.queries = queries;
|
this.queries = queries;
|
||||||
@ -63,7 +72,7 @@ function Formula(query, options, queries) {
|
|||||||
this._isFloatColumn = null;
|
this._isFloatColumn = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Formula.prototype = new BaseWidget();
|
Formula.prototype = new BaseDataview();
|
||||||
Formula.prototype.constructor = Formula;
|
Formula.prototype.constructor = Formula;
|
||||||
|
|
||||||
module.exports = Formula;
|
module.exports = Formula;
|
||||||
|
Loading…
Reference in New Issue
Block a user