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 min and max aggregators for long and double #84

Merged
merged 2 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 12 additions & 4 deletions pydruid/utils/aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,24 @@ 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):
Copy link
Member

Choose a reason for hiding this comment

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

Could you leave the old ones in for compatibility with older python clients? They should turn into doubleMin and doubleMax since the old min/max aggregators acted like the double versions.

Maybe also add a docstring to the old min/max versions saying they're deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'll do that

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