Skip to content

Commit 2667241

Browse files
committed
Add doublemean aggregator, update aggregator tests
1 parent 98cab4d commit 2667241

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

pydruid/utils/aggregators.py

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def doublemax(raw_metric):
6363
return {"type": "doubleMax", "fieldName": raw_metric}
6464

6565

66+
def doublemean(raw_metric):
67+
return {"type": "doubleMean", "fieldName": raw_metric}
68+
69+
6670
def count(raw_metric):
6771
return {"type": "count", "fieldName": raw_metric}
6872

tests/utils/test_aggregators.py

+36-30
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def test_aggregators(self):
1515
("doublesum", "doubleSum"),
1616
("doublemin", "doubleMin"),
1717
("doublemax", "doubleMax"),
18+
("doublemean", "doubleMean"),
1819
("count", "count"),
1920
("hyperunique", "hyperUnique"),
2021
("stringfirst", "stringFirst"),
@@ -34,12 +35,13 @@ def test_filtered_aggregator(self):
3435
aggregators.doublesum("metric3"),
3536
aggregators.doublemin("metric4"),
3637
aggregators.doublemax("metric5"),
37-
aggregators.hyperunique("metric6"),
38+
aggregators.doublemean("metric6"),
39+
aggregators.hyperunique("metric7"),
3840
aggregators.cardinality("dim1"),
3941
aggregators.cardinality(["dim1", "dim2"], by_row=True),
4042
aggregators.thetasketch("dim1"),
41-
aggregators.thetasketch("metric7"),
42-
aggregators.thetasketch("metric8", isinputthetasketch=True, size=8192),
43+
aggregators.thetasketch("metric8"),
44+
aggregators.thetasketch("metric9", isinputthetasketch=True, size=8192),
4345
]
4446
for agg in aggs:
4547
expected = {
@@ -82,13 +84,14 @@ def test_build_aggregators(self):
8284
"agg3": aggregators.doublesum("metric3"),
8385
"agg4": aggregators.doublemin("metric4"),
8486
"agg5": aggregators.doublemax("metric5"),
85-
"agg6": aggregators.hyperunique("metric6"),
86-
"agg7": aggregators.cardinality("dim1"),
87-
"agg8": aggregators.cardinality(["dim1", "dim2"], by_row=True),
88-
"agg9": aggregators.thetasketch("dim1"),
89-
"agg10": aggregators.thetasketch("metric7"),
90-
"agg11": aggregators.thetasketch(
91-
"metric8", isinputthetasketch=True, size=8192
87+
"agg6": aggregators.doublemean("metric6"),
88+
"agg7": aggregators.hyperunique("metric7"),
89+
"agg8": aggregators.cardinality("dim1"),
90+
"agg9": aggregators.cardinality(["dim1", "dim2"], by_row=True),
91+
"agg10": aggregators.thetasketch("dim1"),
92+
"agg11": aggregators.thetasketch("metric8"),
93+
"agg12": aggregators.thetasketch(
94+
"metric9", isinputthetasketch=True, size=8192
9295
),
9396
}
9497
built_agg = aggregators.build_aggregators(agg_input)
@@ -98,37 +101,38 @@ def test_build_aggregators(self):
98101
{"name": "agg3", "type": "doubleSum", "fieldName": "metric3"},
99102
{"name": "agg4", "type": "doubleMin", "fieldName": "metric4"},
100103
{"name": "agg5", "type": "doubleMax", "fieldName": "metric5"},
101-
{"name": "agg6", "type": "hyperUnique", "fieldName": "metric6"},
104+
{"name": "agg6", "type": "doubleMean", "fieldName": "metric6"},
105+
{"name": "agg7", "type": "hyperUnique", "fieldName": "metric7"},
102106
{
103-
"name": "agg7",
107+
"name": "agg8",
104108
"type": "cardinality",
105109
"fieldNames": ["dim1"],
106110
"byRow": False,
107111
},
108112
{
109-
"name": "agg8",
113+
"name": "agg9",
110114
"type": "cardinality",
111115
"fieldNames": ["dim1", "dim2"],
112116
"byRow": True,
113117
},
114118
{
115-
"name": "agg9",
119+
"name": "agg10",
116120
"type": "thetaSketch",
117121
"fieldName": "dim1",
118122
"isInputThetaSketch": False,
119123
"size": 16384,
120124
},
121125
{
122-
"name": "agg10",
126+
"name": "agg11",
123127
"type": "thetaSketch",
124-
"fieldName": "metric7",
128+
"fieldName": "metric8",
125129
"isInputThetaSketch": False,
126130
"size": 16384,
127131
},
128132
{
129-
"name": "agg11",
133+
"name": "agg12",
130134
"type": "thetaSketch",
131-
"fieldName": "metric8",
135+
"fieldName": "metric9",
132136
"isInputThetaSketch": True,
133137
"size": 8192,
134138
},
@@ -145,14 +149,15 @@ def test_build_filtered_aggregator(self):
145149
"agg3": aggregators.filtered(filter_, aggregators.doublesum("metric3")),
146150
"agg4": aggregators.filtered(filter_, aggregators.doublemin("metric4")),
147151
"agg5": aggregators.filtered(filter_, aggregators.doublemax("metric5")),
148-
"agg6": aggregators.filtered(filter_, aggregators.hyperunique("metric6")),
149-
"agg7": aggregators.filtered(filter_, aggregators.cardinality("dim1")),
150-
"agg8": aggregators.filtered(
152+
"agg5": aggregators.filtered(filter_, aggregators.doublemean("metric6")),
153+
"agg7": aggregators.filtered(filter_, aggregators.hyperunique("metric7")),
154+
"agg8": aggregators.filtered(filter_, aggregators.cardinality("dim1")),
155+
"agg9": aggregators.filtered(
151156
filter_, aggregators.cardinality(["dim1", "dim2"], by_row=True)
152157
),
153-
"agg9": aggregators.filtered(filter_, aggregators.thetasketch("dim1")),
154-
"agg10": aggregators.filtered(filter_, aggregators.thetasketch("metric7")),
155-
"agg11": aggregators.filtered(
158+
"agg10": aggregators.filtered(filter_, aggregators.thetasketch("dim1")),
159+
"agg11": aggregators.filtered(filter_, aggregators.thetasketch("metric7")),
160+
"agg12": aggregators.filtered(
156161
filter_,
157162
aggregators.thetasketch("metric8", isinputthetasketch=True, size=8192),
158163
),
@@ -168,35 +173,36 @@ def test_build_filtered_aggregator(self):
168173
{"name": "agg3", "type": "doubleSum", "fieldName": "metric3"},
169174
{"name": "agg4", "type": "doubleMin", "fieldName": "metric4"},
170175
{"name": "agg5", "type": "doubleMax", "fieldName": "metric5"},
171-
{"name": "agg6", "type": "hyperUnique", "fieldName": "metric6"},
176+
{"name": "agg6", "type": "doubleMean", "fieldName": "metric6"},
177+
{"name": "agg7", "type": "hyperUnique", "fieldName": "metric7"},
172178
{
173-
"name": "agg7",
179+
"name": "agg8",
174180
"type": "cardinality",
175181
"fieldNames": ["dim1"],
176182
"byRow": False,
177183
},
178184
{
179-
"name": "agg8",
185+
"name": "agg9",
180186
"type": "cardinality",
181187
"fieldNames": ["dim1", "dim2"],
182188
"byRow": True,
183189
},
184190
{
185-
"name": "agg9",
191+
"name": "agg10",
186192
"type": "thetaSketch",
187193
"fieldName": "dim1",
188194
"isInputThetaSketch": False,
189195
"size": 16384,
190196
},
191197
{
192-
"name": "agg10",
198+
"name": "agg11",
193199
"type": "thetaSketch",
194200
"fieldName": "metric7",
195201
"isInputThetaSketch": False,
196202
"size": 16384,
197203
},
198204
{
199-
"name": "agg11",
205+
"name": "agg12",
200206
"type": "thetaSketch",
201207
"fieldName": "metric8",
202208
"isInputThetaSketch": True,

0 commit comments

Comments
 (0)