From: Sebastian Harl Date: Wed, 2 Sep 2015 22:40:39 +0000 (+0200) Subject: store: Fix execution of more complex iterators. X-Git-Tag: sysdb-0.8.0~33 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=060c0cebbae60bd3d90691858465d462fba0d952 store: Fix execution of more complex iterators. That is, follow "indirections" of typed expressions if the iterator is not on the top-most level. --- diff --git a/src/core/store_expr.c b/src/core/store_expr.c index 642255e..6405002 100644 --- a/src/core/store_expr.c +++ b/src/core/store_expr.c @@ -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; diff --git a/t/unit/frontend/query_test.c b/t/unit/frontend/query_test.c index 7640511..8ac497c 100644 --- a/t/unit/frontend/query_test.c +++ b/t/unit/frontend/query_test.c @@ -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,