Skip to content

Commit

Permalink
Addressing more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 18, 2018
1 parent ffe30a1 commit 01aa3a2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
13 changes: 7 additions & 6 deletions superset/connectors/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,20 @@ def filter_values_handler(
def handle_single_value(v):
# backward compatibility with previous <select> components
if isinstance(v, basestring):
v = v.strip().strip("'").strip('"')
v = v.strip('\t\n \'"')
if target_column_is_numeric:
# For backwards compatibility and edge cases
# where a column data type might have changed
v = utils.string_to_num(v)
if v == '<NULL>':
return None
elif v == '<empty string>':
return ''
if v == '<NULL>':
return None
elif v == '<empty string>':
return ''
return v
if isinstance(values, (list, tuple)):
values = [handle_single_value(v) for v in values]
values = handle_single_value(values)
else:
values = handle_single_value(values)
if is_list_target and not isinstance(values, (tuple, list)):
values = [values]
elif not is_list_target and isinstance(values, (tuple, list)):
Expand Down
3 changes: 2 additions & 1 deletion superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,9 @@ def get_filters(cls, raw_filters, num_cols): # noqa
continue
cond = None
is_numeric_col = col in num_cols
is_list_target = op in ('in', 'not in')
eq = cls.filter_values_handler(
eq, is_list_target=op in ('in', 'not in'),
eq, is_list_target=is_list_target,
target_column_is_numeric=is_numeric_col)
if op == '==':
cond = Dimension(col) == eq
Expand Down
3 changes: 2 additions & 1 deletion superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,11 @@ def get_sqla_query( # sqla
col = flt['col']
op = flt['op']
col_obj = cols.get(col)
is_list_target = op in ('in', 'not in')
eq = self.filter_values_handler(
flt.get('val'),
target_column_is_numeric=col_obj.is_num,
is_list_target=op in ('in', 'not in'))
is_list_target=is_list_target)
if col_obj:
if op in ('in', 'not in'):
cond = col_obj.sqla_col.in_(eq)
Expand Down
2 changes: 0 additions & 2 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1700,8 +1700,6 @@ def run_extra_queries(self):
for flt in filters:
qry['groupby'] = [flt]
df = self.get_df_payload(query_obj=qry).get('df')
print(df)
print(df.dtypes)
self.dataframes[flt] = df

def filter_query_obj(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/druid_func_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DruidFuncTestCase(unittest.TestCase):
def test_get_filters_ignores_invalid_filter_objects(self):
filtr = {'col': 'col1', 'op': '=='}
filters = [filtr]
self.assertEqual(None, DruidDatasource.get_filters(filters, []))
self.assertIsNone(DruidDatasource.get_filters(filters, []))

def test_get_filters_constructs_filter_in(self):
filtr = {'col': 'A', 'op': 'in', 'val': ['a', 'b', 'c']}
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_get_filters_ignores_in_not_in_with_empty_value(self):
filtr1 = {'col': 'A', 'op': 'in', 'val': []}
filtr2 = {'col': 'A', 'op': 'not in', 'val': []}
res = DruidDatasource.get_filters([filtr1, filtr2], [])
self.assertEqual(None, res)
self.assertIsNone(res)

def test_get_filters_constructs_equals_for_in_not_in_single_value(self):
filtr = {'col': 'A', 'op': 'in', 'val': ['a']}
Expand All @@ -122,12 +122,12 @@ def test_get_filters_handles_arrays_for_string_types(self):

filtr = {'col': 'A', 'op': '==', 'val': []}
res = DruidDatasource.get_filters([filtr], [])
self.assertEqual(None, res.filter['filter']['value'])
self.assertIsNone(res.filter['filter']['value'])

def test_get_filters_handles_none_for_string_types(self):
filtr = {'col': 'A', 'op': '==', 'val': None}
res = DruidDatasource.get_filters([filtr], [])
self.assertEqual(None, res)
self.assertIsNone(res)

def test_get_filters_extracts_values_in_quotes(self):
filtr = {'col': 'A', 'op': 'in', 'val': [' "a" ']}
Expand Down

0 comments on commit 01aa3a2

Please sign in to comment.