Code

store: Add the timeseries field to metrics.
[sysdb.git] / src / core / store_expr.c
index 8fc063d11e64ca621fd2206ad9a46b242d36cc48..80c1f4ac25c756383d579a1a92042045f5df6cec 100644 (file)
@@ -167,7 +167,7 @@ sdb_store_expr_fieldvalue(int field)
        sdb_data_t value = { SDB_TYPE_INTEGER, { .integer = field } };
        sdb_store_expr_t *e;
 
-       if ((field < SDB_FIELD_NAME) || (SDB_FIELD_BACKEND < field))
+       if ((field < SDB_FIELD_NAME) || (SDB_FIELD_TIMESERIES < field))
                return NULL;
        e = SDB_STORE_EXPR(sdb_object_create("store-fieldvalue", expr_type,
                                FIELD_VALUE, NULL, NULL, &value));
@@ -286,7 +286,12 @@ sdb_store_expr_iterable(sdb_store_expr_t *expr, int context)
                if ((context != SDB_HOST) && (context != SDB_SERVICE)
                                && (context != SDB_METRIC) && (context != SDB_ATTRIBUTE))
                        return 0;
-               return expr->data.data.integer == SDB_FIELD_BACKEND;
+               if (expr->data.data.integer == SDB_FIELD_BACKEND)
+                       return 1;
+               else if (expr->data.data.integer == SDB_FIELD_VALUE)
+                       /* we don't current support this just like when using
+                        * the attribute[<name>] syntax */
+                       return 0;
        }
        else if (! expr->type) {
                return !!(expr->data.type & SDB_TYPE_ARRAY);
@@ -302,10 +307,12 @@ sdb_store_expr_iter(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
        sdb_avltree_iter_t *tree = NULL;
        sdb_data_t array = SDB_DATA_INIT;
 
-       if ((! expr) || (! obj))
+       if (! expr)
                return NULL;
 
        if (expr->type == TYPED_EXPR) {
+               if (! obj)
+                       return NULL;
                if (obj->type == SDB_HOST) {
                        if (expr->data.data.integer == SDB_SERVICE)
                                tree = sdb_avltree_get_iter(HOST(obj)->services);
@@ -324,6 +331,8 @@ sdb_store_expr_iter(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
                }
        }
        else if (expr->type == FIELD_VALUE) {
+               if (! obj)
+                       return NULL;
                if (expr->data.data.integer == SDB_FIELD_BACKEND) {
                        /* while scanning the store, we hold a read lock, so it's safe to
                         * access the data without copying */