Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[explore] proper filtering of NULLs and '' #4651

Merged
merged 8 commits into from
Apr 18, 2018

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented Mar 20, 2018

screen shot 2018-03-19 at 11 21 00 pm

closes #4297

@codecov-io
Copy link

codecov-io commented Mar 20, 2018

Codecov Report

Merging #4651 into master will decrease coverage by 0.06%.
The diff coverage is 75.51%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4651      +/-   ##
==========================================
- Coverage   76.98%   76.91%   -0.07%     
==========================================
  Files          44       44              
  Lines        8498     8522      +24     
==========================================
+ Hits         6542     6555      +13     
- Misses       1956     1967      +11
Impacted Files Coverage Δ
superset/connectors/sqla/models.py 75.4% <50%> (-0.92%) ⬇️
superset/connectors/druid/models.py 81.16% <75%> (-0.45%) ⬇️
superset/connectors/base/models.py 90.5% <86.95%> (-0.61%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44c2d5b...741832e. Read the comment docs.

@hughhhh
Copy link
Member

hughhhh commented Mar 21, 2018

Definitely need this!!

@hughhhh
Copy link
Member

hughhhh commented Mar 21, 2018

Did some work on the druid side. I can pick up the rest but i wanted to get some insight before i go on.

https://github.com/hughhhh/incubator-superset/commit/3bc3bd46d05a96335f9663745f68429f10b5eff3

Copy link
Contributor

@jeffreythewang jeffreythewang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a [WIP] idea (tc-dc#8) for handling nulls that involves showing a tooltip next to the label, to distinguish between actual null values and "null" string values.

(I've only tested with druid, and so far only have it such that Enable Filter Select must be on.)

@@ -61,7 +61,7 @@ export default class AlteredSliceTag extends React.Component {
return '[]';
}
return value.map((v) => {
const filterVal = v.val.constructor === Array ? `[${v.val.join(', ')}]` : v.val;
const filterVal = v.val && v.val.constructor === Array ? `[${v.val.join(', ')}]` : v.val;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be my unfamiliarity, but why not use Array.isArray like in other parts of the code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't write that line but FWIW someone on StackOverflow says it's the best way
https://stackoverflow.com/questions/767486/how-do-you-check-if-a-variable-is-an-array-in-javascript

@mistercrunch mistercrunch changed the title [WiP] [explore] proper filtering of NULLs and '' [explore] proper filtering of NULLs and '' Apr 11, 2018
def handle_single_value(v):
# backward compatibility with previous <select> components
if isinstance(v, basestring):
v = v.strip().strip("'").strip('"')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do a single strip to remove whitespace and single/double quotes:

v = v.strip(' \'"')

Or, to also take care of tabs and line feeds:

v = v.strip('\t\n \'"')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh neat

return v
if isinstance(values, (list, tuple)):
values = [handle_single_value(v) for v in values]
values = handle_single_value(values)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing... I'd add the second call to an else block (unless I'm missing something):

if isinstance(values, (list, tuple)):
    values = [handle_single_value(v) for v in values]
else:
    values = handle_single_value(values)

values = [handle_single_value(v) for v in values]
values = handle_single_value(values)
if is_list_target and not isinstance(values, (tuple, list)):
values = [values]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if is_list_target is true but values is a tuple? In this case it would return a tuple, is that ok?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable should probably be called is_iterable_target, both tuple and list will work here.

eq = utils.string_to_num(eq)

eq = cls.filter_values_handler(
eq, is_list_target=op in ('in', 'not in'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit hard to read, can we define is_list_target outside the function call, like you did for is_numeric_col?

eq = self.filter_values_handler(
flt.get('val'),
target_column_is_numeric=col_obj.is_num,
is_list_target=op in ('in', 'not in'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above here.

superset/viz.py Outdated
@@ -1693,6 +1693,8 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d2d

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use assertIsNone instead.


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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@mistercrunch
Copy link
Member Author

@betodealmeida addressed your comments

TODO: handling of Druid equivalents
Error "unorderable types: str() < int()" occurs when grouping by a
numerical Druid colummn that contains null values.

* druid/pydruid returns strings in the datafram with NAs for nulls
* Superset has custom logic around get_fillna_for_col that fills in the
NULLs based on declared column type (FLOAT here), so now we have a mixed
bag of type in the series
* pandas chokes on pivot_table or groupby operations as it cannot sorts
mixed types

The approach here is to stringify and fillna('<NULL>') to get a
consistent series.
@mistercrunch mistercrunch merged commit eac97ce into apache:master Apr 18, 2018
@mistercrunch mistercrunch deleted the nulls branch April 18, 2018 05:26
michellethomas pushed a commit to michellethomas/panoramix that referenced this pull request May 24, 2018
* [WiP] [explore] proper filtering of NULLs and ''

TODO: handling of Druid equivalents

* Unit tests

* Some refactoring

* [druid] fix 'Unorderable types' when col has nuls

Error "unorderable types: str() < int()" occurs when grouping by a
numerical Druid colummn that contains null values.

* druid/pydruid returns strings in the datafram with NAs for nulls
* Superset has custom logic around get_fillna_for_col that fills in the
NULLs based on declared column type (FLOAT here), so now we have a mixed
bag of type in the series
* pandas chokes on pivot_table or groupby operations as it cannot sorts
mixed types

The approach here is to stringify and fillna('<NULL>') to get a
consistent series.

* typo

* Fix druid_func tests

* Addressing more comments

* last touches
timifasubaa pushed a commit to timifasubaa/incubator-superset that referenced this pull request May 31, 2018
* [WiP] [explore] proper filtering of NULLs and ''

TODO: handling of Druid equivalents

* Unit tests

* Some refactoring

* [druid] fix 'Unorderable types' when col has nuls

Error "unorderable types: str() < int()" occurs when grouping by a
numerical Druid colummn that contains null values.

* druid/pydruid returns strings in the datafram with NAs for nulls
* Superset has custom logic around get_fillna_for_col that fills in the
NULLs based on declared column type (FLOAT here), so now we have a mixed
bag of type in the series
* pandas chokes on pivot_table or groupby operations as it cannot sorts
mixed types

The approach here is to stringify and fillna('<NULL>') to get a
consistent series.

* typo

* Fix druid_func tests

* Addressing more comments

* last touches
wenchma pushed a commit to wenchma/incubator-superset that referenced this pull request Nov 16, 2018
* [WiP] [explore] proper filtering of NULLs and ''

TODO: handling of Druid equivalents

* Unit tests

* Some refactoring

* [druid] fix 'Unorderable types' when col has nuls

Error "unorderable types: str() < int()" occurs when grouping by a
numerical Druid colummn that contains null values.

* druid/pydruid returns strings in the datafram with NAs for nulls
* Superset has custom logic around get_fillna_for_col that fills in the
NULLs based on declared column type (FLOAT here), so now we have a mixed
bag of type in the series
* pandas chokes on pivot_table or groupby operations as it cannot sorts
mixed types

The approach here is to stringify and fillna('<NULL>') to get a
consistent series.

* typo

* Fix druid_func tests

* Addressing more comments

* last touches
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.25.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.25.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Filter Box] Boolean values show up blank in selector
5 participants