Skip to content

Commit

Permalink
Merge cded9ae into 41bc761
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinPapke committed Jan 16, 2020
2 parents 41bc761 + cded9ae commit ca18b5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fireant/queries/builder/dimension_choices_query_builder.py
Expand Up @@ -157,6 +157,9 @@ def fetch(self, hint=None, force_include=()) -> pd.Series:
# Ensure that these values are included
query = query.orderby(include, order=Order.desc)

# Filter out NULL values from choices
query = query.where(dimension_definition.notnull())

# Order by the dimension definition that the choices are for
query = query.orderby(alias_definition)

Expand Down
9 changes: 9 additions & 0 deletions fireant/tests/queries/test_dimension_choices.py
Expand Up @@ -66,6 +66,7 @@ def test_query_choices_for_dataset_with_hint_table(self, mock_fetch_data: Mock):
[PypikaQueryMatcher('SELECT '
'"political_party" "$political_party" '
'FROM "politics"."hints" '
'WHERE NOT "political_party" IS NULL '
'GROUP BY "$political_party" '
'ORDER BY "$political_party"')],
FieldMatcher(mock_hint_dataset.fields.political_party))
Expand All @@ -86,6 +87,7 @@ def test_query_choices_for_field_with_display_hint_table(self,
'"candidate_name_display" '
'"$candidate_name_display" '
'FROM "politics"."hints" '
'WHERE NOT "candidate_name" IS NULL '
'GROUP BY "$candidate_name",'
'"$candidate_name_display" '
'ORDER BY "$candidate_name"')],
Expand All @@ -110,6 +112,7 @@ def test_query_choices_for_filters_from_joins(self,
'JOIN "locations"."state" ON '
'"hints"."state_id"="state"."id" '
'WHERE "state"."state_name" IN (\'Texas\') '
'AND NOT "hints"."political_party" IS NULL '
'GROUP BY "$political_party" '
'ORDER BY "$political_party"')],
FieldMatcher(mock_hint_dataset.fields.political_party))
Expand All @@ -131,6 +134,7 @@ def test_query_choices_for_filters_from_base(self,
'"political_party" "$political_party" '
'FROM "politics"."hints" '
'WHERE "candidate_name" IN (\'Bill Clinton\') '
'AND NOT "political_party" IS NULL '
'GROUP BY "$political_party" '
'ORDER BY "$political_party"')],
FieldMatcher(mock_hint_dataset.fields.political_party))
Expand All @@ -150,6 +154,7 @@ def test_query_choices_for_case_filter(self,
[PypikaQueryMatcher('SELECT '
'"political_party" "$political_party" '
'FROM "politics"."hints" '
'WHERE NOT "political_party" IS NULL '
'GROUP BY "$political_party" '
'ORDER BY "$political_party"')],
FieldMatcher(mock_hint_dataset.fields.political_party))
Expand All @@ -168,6 +173,7 @@ def test_query_choices_for_join_dimension(self,
[PypikaQueryMatcher('SELECT '
'"district_name" "$district-name" '
'FROM "politics"."hints" '
'WHERE NOT "district_name" IS NULL '
'GROUP BY "$district-name" '
'ORDER BY "$district-name"')],
FieldMatcher(mock_hint_dataset.fields['district-name']))
Expand All @@ -188,6 +194,7 @@ def test_query_choices_for_join_dimension_with_filter_from_base(self,
'"district_name" "$district-name" '
'FROM "politics"."hints" '
'WHERE "candidate_name" IN (\'Bill Clinton\') '
'AND NOT "district_name" IS NULL '
'GROUP BY "$district-name" '
'ORDER BY "$district-name"')],
FieldMatcher(mock_hint_dataset.fields['district-name']))
Expand All @@ -211,6 +218,7 @@ def test_query_choices_for_join_dimension_with_filter_from_join(self,
'"hints"."district_id"="district"."id" '
'WHERE "district"."district_name" IN ('
'\'Manhattan\') '
'AND NOT "hints"."district_name" IS NULL '
'GROUP BY "$district-name" '
'ORDER BY "$district-name"')],
FieldMatcher(mock_hint_dataset.fields['district-name']))
Expand All @@ -228,6 +236,7 @@ def test_query_choices_for_field(self, mock_fetch_data: Mock):
[PypikaQueryMatcher('SELECT '
'"political_party" "$political_party" '
'FROM "politics"."politician" '
'WHERE NOT "political_party" IS NULL '
'GROUP BY "$political_party" '
'ORDER BY "$political_party"')],
FieldMatcher(mock_dataset.fields.political_party))

0 comments on commit ca18b5d

Please sign in to comment.