From c5806005908b3bbe471d9d863ca145f434adbb6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 5 Sep 2017 10:36:18 +0200 Subject: [PATCH] Extract template to filter out special numeric values --- lib/cartodb/models/dataview/histogram.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/cartodb/models/dataview/histogram.js b/lib/cartodb/models/dataview/histogram.js index 60e10418..3f31bea8 100644 --- a/lib/cartodb/models/dataview/histogram.js +++ b/lib/cartodb/models/dataview/histogram.js @@ -51,22 +51,23 @@ var MAX_INTERVAL_VALUE = 366; var BIN_MIN_NUMBER = 6; var BIN_MAX_NUMBER = 48; +const filterOutSpecialNumericValues = ctx => ` + ${ctx._column} != 'infinity'::float + AND + ${ctx._column} != '-infinity'::float + AND + ${ctx._column} != 'NaN'::float +`; + const filteredQueryTpl = ctx => ` __cdb_filtered_source AS ( SELECT * FROM (${ctx._query}) __cdb_filtered_source_query - WHERE - ${ctx._column} IS NOT NULL - ${ctx._isFloatColumn ? ` - AND - ${ctx._column} != 'infinity'::float - AND - ${ctx._column} != '-infinity'::float - AND - ${ctx._column} != 'NaN'::float - ` : ''} + WHERE ${ctx._column} IS NOT NULL + ${ctx._isFloatColumn ? `AND ${filterOutSpecialNumericValues(ctx)}` : ''} ) -` +`; + var basicsQueryTpl = dot.template([ '__cdb_basics AS (', ' SELECT',