diff --git a/pydruid/client.py b/pydruid/client.py index 2a245bc1..cd5f5f5e 100755 --- a/pydruid/client.py +++ b/pydruid/client.py @@ -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 diff --git a/pydruid/utils/filters.py b/pydruid/utils/filters.py index ecfde90c..053bb4b1 100644 --- a/pydruid/utils/filters.py +++ b/pydruid/utils/filters.py @@ -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): @@ -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'] diff --git a/pydruid/utils/postaggregator.py b/pydruid/utils/postaggregator.py index c1837bc4..c6dd5e3a 100644 --- a/pydruid/utils/postaggregator.py +++ b/pydruid/utils/postaggregator.py @@ -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): @@ -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