mirror of
https://github.com/apache/superset.git
synced 2024-09-17 11:09:47 -04:00
* Alternate fix for #2665 * Addressing comments * Fix doctest
This commit is contained in:
parent
0bdc3010d8
commit
1922225042
@ -980,9 +980,9 @@ class DruidDatasource(Model, BaseDatasource):
|
|||||||
eq = eq[0] if len(eq) > 0 else ''
|
eq = eq[0] if len(eq) > 0 else ''
|
||||||
if col in self.num_cols:
|
if col in self.num_cols:
|
||||||
if op in ('in', 'not in'):
|
if op in ('in', 'not in'):
|
||||||
eq = [utils.js_string_to_num(v) for v in eq]
|
eq = [utils.string_to_num(v) for v in eq]
|
||||||
else:
|
else:
|
||||||
eq = utils.js_string_to_num(eq)
|
eq = utils.string_to_num(eq)
|
||||||
if op == '==':
|
if op == '==':
|
||||||
cond = Dimension(col) == eq
|
cond = Dimension(col) == eq
|
||||||
elif op == '!=':
|
elif op == '!=':
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
import sqlparse
|
import sqlparse
|
||||||
|
from past.builtins import basestring
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
@ -467,9 +468,19 @@ class SqlaTable(Model, BaseDatasource):
|
|||||||
col_obj = cols.get(col)
|
col_obj = cols.get(col)
|
||||||
if col_obj:
|
if col_obj:
|
||||||
if op in ('in', 'not in'):
|
if op in ('in', 'not in'):
|
||||||
values = [types.strip("'").strip('"') for types in eq]
|
values = []
|
||||||
|
for v in eq:
|
||||||
|
# For backwards compatibility and edge cases
|
||||||
|
# where a column data type might have changed
|
||||||
|
if isinstance(v, basestring):
|
||||||
|
v = v.strip("'").strip('"')
|
||||||
if col_obj.is_num:
|
if col_obj.is_num:
|
||||||
values = [utils.js_string_to_num(s) for s in values]
|
v = utils.string_to_num(v)
|
||||||
|
|
||||||
|
# Removing empty strings and non numeric values
|
||||||
|
# targeting numeric columns
|
||||||
|
if v is not None:
|
||||||
|
values.append(v)
|
||||||
cond = col_obj.sqla_col.in_(values)
|
cond = col_obj.sqla_col.in_(values)
|
||||||
if op == 'not in':
|
if op == 'not in':
|
||||||
cond = ~cond
|
cond = ~cond
|
||||||
|
@ -128,14 +128,32 @@ class memoized(object): # noqa
|
|||||||
def js_string_to_python(item):
|
def js_string_to_python(item):
|
||||||
return None if item in ('null', 'undefined') else item
|
return None if item in ('null', 'undefined') else item
|
||||||
|
|
||||||
def js_string_to_num(item):
|
|
||||||
if item.isdigit():
|
def string_to_num(s):
|
||||||
return int(item)
|
"""Converts a string to an int/float
|
||||||
s = item
|
|
||||||
try:
|
Returns ``None`` if it can't be converted
|
||||||
s = float(item)
|
|
||||||
except ValueError:
|
>>> string_to_num('5')
|
||||||
|
5
|
||||||
|
>>> string_to_num('5.2')
|
||||||
|
5.2
|
||||||
|
>>> string_to_num(10)
|
||||||
|
10
|
||||||
|
>>> string_to_num(10.1)
|
||||||
|
10.1
|
||||||
|
>>> string_to_num('this is not a string') is None
|
||||||
|
True
|
||||||
|
"""
|
||||||
|
if isinstance(s, (int, float)):
|
||||||
return s
|
return s
|
||||||
|
if s.isdigit():
|
||||||
|
return int(s)
|
||||||
|
try:
|
||||||
|
return float(s)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class DimSelector(Having):
|
class DimSelector(Having):
|
||||||
def __init__(self, **args):
|
def __init__(self, **args):
|
||||||
|
Loading…
Reference in New Issue
Block a user