Skip to content

Commit

Permalink
Fix druid_func tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 18, 2018
1 parent 289b5aa commit ffe30a1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
25 changes: 25 additions & 0 deletions superset/assets/src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,28 @@ export function isTruthy(obj) {
}
return !!obj;
}

export function optionLabel(opt) {
if (opt === null) {
return '<NULL>';
} else if (opt === '') {
return '<empty string>';
} else if (opt === true) {
return '<true>';
} else if (opt === false) {
return '<false>';
}
return opt;
}

export function optionValue(opt) {
if (opt === null) {
return '<NULL>';
}
return opt;
}

export function optionFromValue(opt) {
// From a list of options, handles special values & labels
return { value: optionValue(opt), label: optionLabel(opt) };
}
2 changes: 1 addition & 1 deletion superset/connectors/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def filter_values_handler(
def handle_single_value(v):
# backward compatibility with previous <select> components
if isinstance(v, basestring):
v = v.strip("'").strip('"')
v = v.strip().strip("'").strip('"')
if target_column_is_numeric:
# For backwards compatibility and edge cases
# where a column data type might have changed
Expand Down
12 changes: 8 additions & 4 deletions superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,18 +1341,22 @@ def increment_timestamp(ts):

@classmethod
def get_filters(cls, raw_filters, num_cols): # noqa
"""Given Superset filter data structure, returns pydruid Filter(s)"""
filters = None
for flt in raw_filters:
col = flt.get('col')
op = flt.get('op')
eq = flt.get('val')
if not col or not op:
if (
not col or
not op or
(eq is None and op not in ('IS NULL', 'IS NOT NULL'))):
continue
cond = None
eq = cls.filter_values_handler(
eq, is_list_target=op in ('in', 'not in'))

is_numeric_col = col in num_cols
eq = cls.filter_values_handler(
eq, is_list_target=op in ('in', 'not in'),
target_column_is_numeric=is_numeric_col)
if op == '==':
cond = Dimension(col) == eq
elif op == '!=':
Expand Down
4 changes: 2 additions & 2 deletions tests/druid_func_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('', res.filter['filter']['value'])
self.assertEqual(None, 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('', res.filter['filter']['value'])
self.assertEqual(None, res)

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

0 comments on commit ffe30a1

Please sign in to comment.