]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: Add support for explicit discrete group-by function
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Wed, 4 Mar 2020 11:34:06 +0000 (06:34 -0500)
committerjeff.sipek <jeff.sipek@open-xchange.com>
Fri, 13 Mar 2020 08:25:17 +0000 (08:25 +0000)
One can specify the function as:

    <field>:discrete

This has the same exact behavior as the bare field name syntax before this
change.

For example, the following two lines have identical semantics:

    group_by = cmd_name:discrete
    group_by = cmd_name

src/stats/stats-settings.c
src/stats/test-stats-metrics.c

index f6b05887bf1345461f3be6e3e60246865f487a68..db2ad5df26a92c8335a89244002fe1d226f5e141 100644 (file)
@@ -301,7 +301,16 @@ static bool parse_metric_group_by(struct stats_metric_settings *set,
                params = t_strsplit(*tmp, ":");
 
                if (params[1] == NULL) {
+                       /* <field name> - alias for <field>:discrete */
                        group_by.func = STATS_METRIC_GROUPBY_DISCRETE;
+               } else if (strcmp(params[1], "discrete") == 0) {
+                       /* <field>:discrete */
+                       group_by.func = STATS_METRIC_GROUPBY_DISCRETE;
+                       if (params[2] != NULL) {
+                               *error_r = "group_by 'discrete' aggregate function "
+                                          "does not take any args";
+                               return FALSE;
+                       }
                } else {
                        *error_r = t_strdup_printf("unknown aggregation function "
                                                   "'%s' on field '%s'", params[1], params[0]);
index e80ef64ebedad347f7a284d987f62b1ce18cecbb..81b19a5eed48518ec2f288ed35e8de73e41cb504 100644 (file)
@@ -143,6 +143,18 @@ static const struct discrete_test discrete_tests[] = {
                { "eta", "kappa", "nu", },
                { "upsilon", "pi", "epsilon", },
        },
+       {
+               "test_name:discrete sub_name:discrete",
+               3,
+               { "apple", "bannana", "orange", },
+               { "pie", "yoghurt", "cobbler", },
+       },
+       {
+               "test_name sub_name:discrete",
+               3,
+               { "apollo", "gaia", "hermes", },
+               { "thor", "odin", "loki", },
+       },
 };
 
 static void test_stats_metrics_group_by_discrete_real(const struct discrete_test *test)