From 2667241cb886d03b10230ff360867ef4ddd5be3c Mon Sep 17 00:00:00 2001 From: Alex Pilon Date: Fri, 9 Jul 2021 14:52:02 -0400 Subject: [PATCH] Add doublemean aggregator, update aggregator tests --- pydruid/utils/aggregators.py | 4 ++ tests/utils/test_aggregators.py | 66 ++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/pydruid/utils/aggregators.py b/pydruid/utils/aggregators.py index 23caa826..87abeef0 100644 --- a/pydruid/utils/aggregators.py +++ b/pydruid/utils/aggregators.py @@ -63,6 +63,10 @@ def doublemax(raw_metric): return {"type": "doubleMax", "fieldName": raw_metric} +def doublemean(raw_metric): + return {"type": "doubleMean", "fieldName": raw_metric} + + def count(raw_metric): return {"type": "count", "fieldName": raw_metric} diff --git a/tests/utils/test_aggregators.py b/tests/utils/test_aggregators.py index aa5e7125..a0943dca 100644 --- a/tests/utils/test_aggregators.py +++ b/tests/utils/test_aggregators.py @@ -15,6 +15,7 @@ def test_aggregators(self): ("doublesum", "doubleSum"), ("doublemin", "doubleMin"), ("doublemax", "doubleMax"), + ("doublemean", "doubleMean"), ("count", "count"), ("hyperunique", "hyperUnique"), ("stringfirst", "stringFirst"), @@ -34,12 +35,13 @@ def test_filtered_aggregator(self): aggregators.doublesum("metric3"), aggregators.doublemin("metric4"), aggregators.doublemax("metric5"), - aggregators.hyperunique("metric6"), + aggregators.doublemean("metric6"), + aggregators.hyperunique("metric7"), aggregators.cardinality("dim1"), aggregators.cardinality(["dim1", "dim2"], by_row=True), aggregators.thetasketch("dim1"), - aggregators.thetasketch("metric7"), - aggregators.thetasketch("metric8", isinputthetasketch=True, size=8192), + aggregators.thetasketch("metric8"), + aggregators.thetasketch("metric9", isinputthetasketch=True, size=8192), ] for agg in aggs: expected = { @@ -82,13 +84,14 @@ def test_build_aggregators(self): "agg3": aggregators.doublesum("metric3"), "agg4": aggregators.doublemin("metric4"), "agg5": aggregators.doublemax("metric5"), - "agg6": aggregators.hyperunique("metric6"), - "agg7": aggregators.cardinality("dim1"), - "agg8": aggregators.cardinality(["dim1", "dim2"], by_row=True), - "agg9": aggregators.thetasketch("dim1"), - "agg10": aggregators.thetasketch("metric7"), - "agg11": aggregators.thetasketch( - "metric8", isinputthetasketch=True, size=8192 + "agg6": aggregators.doublemean("metric6"), + "agg7": aggregators.hyperunique("metric7"), + "agg8": aggregators.cardinality("dim1"), + "agg9": aggregators.cardinality(["dim1", "dim2"], by_row=True), + "agg10": aggregators.thetasketch("dim1"), + "agg11": aggregators.thetasketch("metric8"), + "agg12": aggregators.thetasketch( + "metric9", isinputthetasketch=True, size=8192 ), } built_agg = aggregators.build_aggregators(agg_input) @@ -98,37 +101,38 @@ def test_build_aggregators(self): {"name": "agg3", "type": "doubleSum", "fieldName": "metric3"}, {"name": "agg4", "type": "doubleMin", "fieldName": "metric4"}, {"name": "agg5", "type": "doubleMax", "fieldName": "metric5"}, - {"name": "agg6", "type": "hyperUnique", "fieldName": "metric6"}, + {"name": "agg6", "type": "doubleMean", "fieldName": "metric6"}, + {"name": "agg7", "type": "hyperUnique", "fieldName": "metric7"}, { - "name": "agg7", + "name": "agg8", "type": "cardinality", "fieldNames": ["dim1"], "byRow": False, }, { - "name": "agg8", + "name": "agg9", "type": "cardinality", "fieldNames": ["dim1", "dim2"], "byRow": True, }, { - "name": "agg9", + "name": "agg10", "type": "thetaSketch", "fieldName": "dim1", "isInputThetaSketch": False, "size": 16384, }, { - "name": "agg10", + "name": "agg11", "type": "thetaSketch", - "fieldName": "metric7", + "fieldName": "metric8", "isInputThetaSketch": False, "size": 16384, }, { - "name": "agg11", + "name": "agg12", "type": "thetaSketch", - "fieldName": "metric8", + "fieldName": "metric9", "isInputThetaSketch": True, "size": 8192, }, @@ -145,14 +149,15 @@ def test_build_filtered_aggregator(self): "agg3": aggregators.filtered(filter_, aggregators.doublesum("metric3")), "agg4": aggregators.filtered(filter_, aggregators.doublemin("metric4")), "agg5": aggregators.filtered(filter_, aggregators.doublemax("metric5")), - "agg6": aggregators.filtered(filter_, aggregators.hyperunique("metric6")), - "agg7": aggregators.filtered(filter_, aggregators.cardinality("dim1")), - "agg8": aggregators.filtered( + "agg5": aggregators.filtered(filter_, aggregators.doublemean("metric6")), + "agg7": aggregators.filtered(filter_, aggregators.hyperunique("metric7")), + "agg8": aggregators.filtered(filter_, aggregators.cardinality("dim1")), + "agg9": aggregators.filtered( filter_, aggregators.cardinality(["dim1", "dim2"], by_row=True) ), - "agg9": aggregators.filtered(filter_, aggregators.thetasketch("dim1")), - "agg10": aggregators.filtered(filter_, aggregators.thetasketch("metric7")), - "agg11": aggregators.filtered( + "agg10": aggregators.filtered(filter_, aggregators.thetasketch("dim1")), + "agg11": aggregators.filtered(filter_, aggregators.thetasketch("metric7")), + "agg12": aggregators.filtered( filter_, aggregators.thetasketch("metric8", isinputthetasketch=True, size=8192), ), @@ -168,35 +173,36 @@ def test_build_filtered_aggregator(self): {"name": "agg3", "type": "doubleSum", "fieldName": "metric3"}, {"name": "agg4", "type": "doubleMin", "fieldName": "metric4"}, {"name": "agg5", "type": "doubleMax", "fieldName": "metric5"}, - {"name": "agg6", "type": "hyperUnique", "fieldName": "metric6"}, + {"name": "agg6", "type": "doubleMean", "fieldName": "metric6"}, + {"name": "agg7", "type": "hyperUnique", "fieldName": "metric7"}, { - "name": "agg7", + "name": "agg8", "type": "cardinality", "fieldNames": ["dim1"], "byRow": False, }, { - "name": "agg8", + "name": "agg9", "type": "cardinality", "fieldNames": ["dim1", "dim2"], "byRow": True, }, { - "name": "agg9", + "name": "agg10", "type": "thetaSketch", "fieldName": "dim1", "isInputThetaSketch": False, "size": 16384, }, { - "name": "agg10", + "name": "agg11", "type": "thetaSketch", "fieldName": "metric7", "isInputThetaSketch": False, "size": 16384, }, { - "name": "agg11", + "name": "agg12", "type": "thetaSketch", "fieldName": "metric8", "isInputThetaSketch": True,