Skip to content

Commit

Permalink
add support for nested filtered aggregators
Browse files Browse the repository at this point in the history
  • Loading branch information
dakra committed Mar 3, 2016
1 parent 56efc78 commit 8b08a91
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 8b08a91

Please sign in to comment.