Skip to content

Commit

Permalink
Add min and max aggregators for long and double (#84)
Browse files Browse the repository at this point in the history
* Add min and max aggregators for long and double

* Add back min and max deprecated aggregators
  • Loading branch information
azymnis authored and gianm committed Apr 27, 2017
1 parent 8dd11ef commit 78bc5c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
30 changes: 26 additions & 4 deletions pydruid/utils/aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,42 @@
from .filters import Filter


def min(raw_metric):
"""
.. note:: Deprecated use `longMin`, `doubleMin' instead
"""
return {"type": "min", "fieldName": raw_metric}


def max(raw_metric):
"""
.. note:: Deprecated use `longMax`, `doubleMax' instead
"""
return {"type": "max", "fieldName": raw_metric}


def longsum(raw_metric):
return {"type": "longSum", "fieldName": raw_metric}


def longmin(raw_metric):
return {"type": "longMin", "fieldName": raw_metric}


def longmax(raw_metric):
return {"type": "longMax", "fieldName": raw_metric}


def doublesum(raw_metric):
return {"type": "doubleSum", "fieldName": raw_metric}


def min(raw_metric):
return {"type": "min", "fieldName": raw_metric}
def doublemin(raw_metric):
return {"type": "doubleMin", "fieldName": raw_metric}


def max(raw_metric):
return {"type": "max", "fieldName": raw_metric}
def doublemax(raw_metric):
return {"type": "doubleMax", "fieldName": raw_metric}


def count(raw_metric):
Expand Down
26 changes: 13 additions & 13 deletions tests/utils/test_aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class TestAggregators:

def test_aggregators(self):
aggs = [('longsum', 'longSum'), ('doublesum', 'doubleSum'),
('min', 'min'), ('max', 'max'), ('count', 'count'),
('hyperunique', 'hyperUnique')]
aggs = [('longsum', 'longSum'), ('longmin', 'longMin'), ('longmax', 'longMax'),
('doublesum', 'doubleSum'), ('doublemin', 'doubleMin'), ('doublemax', 'doubleMax'),
('count', 'count'), ('hyperunique', 'hyperUnique')]
aggs_funcs = [(getattr(aggregators, agg_name), agg_type)
for agg_name, agg_type in aggs]
for f, agg_type in aggs_funcs:
Expand All @@ -23,8 +23,8 @@ def test_filtered_aggregator(self):
aggs = [aggregators.count('metric1'),
aggregators.longsum('metric2'),
aggregators.doublesum('metric3'),
aggregators.min('metric4'),
aggregators.max('metric5'),
aggregators.doublemin('metric4'),
aggregators.doublemax('metric5'),
aggregators.hyperunique('metric6'),
aggregators.cardinality('dim1'),
aggregators.cardinality(['dim1', 'dim2'], by_row=True)]
Expand Down Expand Up @@ -63,8 +63,8 @@ def test_build_aggregators(self):
'agg1': aggregators.count('metric1'),
'agg2': aggregators.longsum('metric2'),
'agg3': aggregators.doublesum('metric3'),
'agg4': aggregators.min('metric4'),
'agg5': aggregators.max('metric5'),
'agg4': aggregators.doublemin('metric4'),
'agg5': aggregators.doublemax('metric5'),
'agg6': aggregators.hyperunique('metric6'),
'agg7': aggregators.cardinality('dim1'),
'agg8': aggregators.cardinality(['dim1', 'dim2'], by_row=True)
Expand All @@ -74,8 +74,8 @@ def test_build_aggregators(self):
{'name': 'agg1', 'type': 'count', 'fieldName': 'metric1'},
{'name': 'agg2', 'type': 'longSum', 'fieldName': 'metric2'},
{'name': 'agg3', 'type': 'doubleSum', 'fieldName': 'metric3'},
{'name': 'agg4', 'type': 'min', 'fieldName': 'metric4'},
{'name': 'agg5', 'type': 'max', 'fieldName': 'metric5'},
{'name': 'agg4', 'type': 'doubleMin', 'fieldName': 'metric4'},
{'name': 'agg5', 'type': 'doubleMax', 'fieldName': 'metric5'},
{'name': 'agg6', 'type': 'hyperUnique', 'fieldName': 'metric6'},
{'name': 'agg7', 'type': 'cardinality', 'fieldNames': ['dim1'], 'byRow': False},
{'name': 'agg8', 'type': 'cardinality', 'fieldNames': ['dim1', 'dim2'], 'byRow': True},
Expand All @@ -93,9 +93,9 @@ def test_build_filtered_aggregator(self):
'agg3': aggregators.filtered(filter_,
aggregators.doublesum('metric3')),
'agg4': aggregators.filtered(filter_,
aggregators.min('metric4')),
aggregators.doublemin('metric4')),
'agg5': aggregators.filtered(filter_,
aggregators.max('metric5')),
aggregators.doublemax('metric5')),
'agg6': aggregators.filtered(filter_,
aggregators.hyperunique('metric6')),
'agg7': aggregators.filtered(filter_,
Expand All @@ -116,8 +116,8 @@ def test_build_filtered_aggregator(self):
{'name': 'agg1', 'type': 'count', 'fieldName': 'metric1'},
{'name': 'agg2', 'type': 'longSum', 'fieldName': 'metric2'},
{'name': 'agg3', 'type': 'doubleSum', 'fieldName': 'metric3'},
{'name': 'agg4', 'type': 'min', 'fieldName': 'metric4'},
{'name': 'agg5', 'type': 'max', 'fieldName': 'metric5'},
{'name': 'agg4', 'type': 'doubleMin', 'fieldName': 'metric4'},
{'name': 'agg5', 'type': 'doubleMax', 'fieldName': 'metric5'},
{'name': 'agg6', 'type': 'hyperUnique', 'fieldName': 'metric6'},
{'name': 'agg7', 'type': 'cardinality', 'fieldNames': ['dim1'], 'byRow': False},
{'name': 'agg8', 'type': 'cardinality', 'fieldNames': ['dim1', 'dim2'], 'byRow': True},
Expand Down

0 comments on commit 78bc5c2

Please sign in to comment.