Parse filter values for possible integers and floats (#2263)

This commit is contained in:
vera-liu 2017-02-24 17:21:28 -08:00 committed by Alanna Scott
parent 4d900c9ee1
commit ec1f0221cd
2 changed files with 10 additions and 0 deletions

View File

@ -1393,6 +1393,7 @@ class SqlaTable(Model, Datasource, AuditMixinNullable, ImportMixin):
col_obj = cols[col]
if op in ('in', 'not in'):
values = [types.strip("'").strip('"') for types in eq]
values = [utils.js_string_to_num(s) for s in values]
cond = col_obj.sqla_col.in_(values)
if op == 'not in':
cond = ~cond
@ -2574,6 +2575,7 @@ class DruidDatasource(Model, AuditMixinNullable, Datasource, ImportMixin):
fields = []
# Distinguish quoted values with regular value types
values = [types.replace("'", '') for types in eq]
values = [utils.js_string_to_num(s) for s in values]
if len(values) > 1:
for s in values:
s = s.strip()

View File

@ -126,6 +126,14 @@ class memoized(object): # noqa
def js_string_to_python(item):
return None if item in ('null', 'undefined') else item
def js_string_to_num(item):
if item.isdigit():
return int(item)
s = item
try:
s = float(item)
except ValueError:
return s
class DimSelector(Having):
def __init__(self, **args):