Skip to content

Commit

Permalink
Filter and Postaggregator builder methods are static members of their…
Browse files Browse the repository at this point in the history
… respective classes
  • Loading branch information
Deep Ganguli committed Mar 5, 2014
1 parent 2f92ec7 commit 1b1f00b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pydruid/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ def build_query(self, args):
if key == 'aggregations':
query_dict[key] = build_aggregators(val)
elif key == 'post_aggregations':
query_dict['postAggregations'] = build_post_aggregators(val)
query_dict['postAggregations'] = Postaggregator.build_post_aggregators(val)
elif key == 'datasource':
query_dict['dataSource'] = val
elif key == "filter":
query_dict[key] = build_filter(val)
query_dict[key] = Filter.build_filter(val)
else:
query_dict[key] = val

Expand Down
7 changes: 4 additions & 3 deletions pydruid/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def __or__(self, x):
def __invert__(self):
return Filter(type="not", field=self.filter['filter'])

@staticmethod
def build_filter(filter_obj):
return filter_obj.filter['filter']


class Dimension:
def __init__(self, dim):
Expand All @@ -61,6 +65,3 @@ def __init__(self, dim):
def __eq__(self, other):
return Filter(dimension=self.dimension, value=other)


def build_filter(filter_obj):
return filter_obj.filter['filter']
19 changes: 9 additions & 10 deletions pydruid/utils/postaggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ def __div__(self, other):
def fields(self, other):
return [self.post_aggregator, other.post_aggregator]

@staticmethod
def build_post_aggregators(postaggs):
def rename_postagg(new_name, post_aggregator):
post_aggregator['name'] = new_name
return post_aggregator

return [rename_postagg(new_name, postagg.post_aggregator)
for (new_name, postagg) in postaggs.iteritems()]


class Field(Postaggregator):
def __init__(self, name):
Expand All @@ -62,13 +71,3 @@ def __init__(self, value, output_name=None):
Postaggregator.__init__(self, None, None, name)
self.post_aggregator = {
'type': 'constant', 'name': name, 'value': value}


def build_post_aggregators(postaggs):
return [rename_postagg(new_name, postagg.post_aggregator)
for (new_name, postagg) in postaggs.iteritems()]


def rename_postagg(new_name, post_aggregator):
post_aggregator['name'] = new_name
return post_aggregator

0 comments on commit 1b1f00b

Please sign in to comment.