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

add support for nested filtered aggregators #45

Merged
merged 1 commit into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pydruid/utils/aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def build_aggregators(agg_input):

def _build_aggregator(name, kwargs):
if kwargs["type"] == "filtered":
kwargs["aggregator"]["name"] = name
kwargs["aggregator"] = _build_aggregator(name, kwargs["aggregator"])
else:
kwargs.update({"name": name})

Expand Down
17 changes: 17 additions & 0 deletions tests/utils/test_aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ def test_filtered_aggregator(self):
actual = aggregators.filtered(filter_, agg)
assert actual == expected

def test_nested_filtered_aggregator(self):
filter1 = filters.Filter(dimension='dim1', value='val')
filter2 = filters.Filter(dimension='dim2', value='val')
agg = aggregators.filtered(filter1,
aggregators.filtered(filter2, aggregators.count('metric1')))
actual = aggregators.build_aggregators({'agg_name': agg})
# the innermost aggregation must have 'agg_name'
expected = [{
'type': 'filtered',
'aggregator': {
'type': 'filtered',
'aggregator': {'fieldName': 'metric1', 'type': 'count', 'name': 'agg_name'},
'filter': {'dimension': 'dim2', 'value': 'val', 'type': 'selector'}},
'filter': {'dimension': 'dim1', 'value': 'val', 'type': 'selector'}
}]
assert expected == actual

def test_build_aggregators(self):
agg_input = {
'agg1': aggregators.count('metric1'),
Expand Down