Code

store: Fix execution of more complex iterators.
authorSebastian Harl <sh@tokkee.org>
Wed, 2 Sep 2015 22:40:39 +0000 (00:40 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 2 Sep 2015 22:40:39 +0000 (00:40 +0200)
That is, follow "indirections" of typed expressions if the iterator is not on
the top-most level.

src/core/store_expr.c
t/unit/frontend/query_test.c

index 642255e4ab94c77028e1f1779d77fd56bfe3584a..6405002cfda3187177dc9b49dae9ce2bc8e82322 100644 (file)
@@ -275,6 +275,23 @@ sdb_store_expr_iter(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
        if (! expr)
                return NULL;
 
+       while (expr->type == TYPED_EXPR) {
+               int type = (int)expr->data.data.integer;
+
+               if (obj->type == type) {
+                       /* self reference */
+               }
+               else if ((type == SDB_HOST)
+                               && ((obj->type == SDB_SERVICE)
+                                       || (obj->type == SDB_METRIC))) {
+                       /* reference to parent host */
+                       obj = obj->parent;
+               }
+               else
+                       break;
+               expr = expr->left;
+       }
+
        if (expr->type == TYPED_EXPR) {
                if (! obj)
                        return NULL;
index 7640511b692f7bfaa68f5a627066d7b5afa0bf90..8ac497c3ecc0a4901b4bd23834625d89221d3418 100644 (file)
@@ -173,6 +173,28 @@ turndown(void)
                                        "{\"name\": \"hostname\", \"value\": \"h2\", " \
                                                "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}"
+#define SERVICE_H2_S12 \
+       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
+                       "\"update_interval\": \"0s\", \"backends\": [], " \
+               "\"services\": [" \
+                       "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
+                               "\"update_interval\": \"0s\", \"backends\": [], " \
+                               "\"attributes\": [" \
+                                       "{\"name\": \"hostname\", \"value\": \"h2\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
+                                               "\"update_interval\": \"0s\", \"backends\": []}]}," \
+                       "{\"name\": \"s2\", \"last_update\": \"1970-01-01 00:00:02 +0000\", " \
+                               "\"update_interval\": \"0s\", \"backends\": [], " \
+                               "\"attributes\": [" \
+                                       "{\"name\": \"hostname\", \"value\": \"h2\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
+                                               "\"update_interval\": \"0s\", \"backends\": []}," \
+                                       "{\"name\": \"k1\", \"value\": 123, " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
+                                               "\"update_interval\": \"0s\", \"backends\": []}," \
+                                       "{\"name\": \"k2\", \"value\": 4711, " \
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
+                                               "\"update_interval\": \"0s\", \"backends\": []}]}]}"
 #define SERVICE_H2_S1_ARRAY "["SERVICE_H2_S1"]"
 #define SERVICE_H2_S12_LISTING \
        "[{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
@@ -471,6 +493,22 @@ static struct {
                SDB_CONNECTION_QUERY, "LOOKUP services MATCHING name = 's1'", -1,
                0, SDB_CONNECTION_DATA, 358, SDB_CONNECTION_LOOKUP, SERVICE_H2_S1_ARRAY,
        },
+       {
+               SDB_CONNECTION_QUERY, "LOOKUP services MATCHING host.name = 'h2'", -1,
+               0, SDB_CONNECTION_DATA, 825, SDB_CONNECTION_LOOKUP, "["SERVICE_H2_S12"]",
+       },
+       {
+               SDB_CONNECTION_QUERY, "LOOKUP services MATCHING ANY host.metric.name = 'm1'", -1,
+               0, SDB_CONNECTION_DATA, 825, SDB_CONNECTION_LOOKUP, "["SERVICE_H2_S12"]",
+       },
+       {
+               SDB_CONNECTION_QUERY, "LOOKUP services MATCHING ANY host.metric.last_update = 1s", -1,
+               0, SDB_CONNECTION_DATA, 825, SDB_CONNECTION_LOOKUP, "["SERVICE_H2_S12"]",
+       },
+       {
+               SDB_CONNECTION_QUERY, "LOOKUP services MATCHING ANY host.metric.name = 'mX'", -1,
+               0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LOOKUP, "[]",
+       },
        {
                SDB_CONNECTION_LOOKUP, "\0\0\0\2""name = 's1'", 16,
                0, SDB_CONNECTION_DATA, 358, SDB_CONNECTION_LOOKUP, SERVICE_H2_S1_ARRAY,