From 73b11c814814e5343ccb66c9a7b45f634b02b07f Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Wed, 22 Oct 2014 11:26:45 +0200 Subject: [PATCH] store: Renamed sdb_store_cmp_XX to sdb_store_XX_matcher. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … now that these names have become available again. --- src/core/store-private.h | 19 +++--- src/core/store_lookup.c | 101 +++++++++++++++----------------- src/include/core/store.h | 20 +++---- t/unit/core/store_lookup_test.c | 20 +++---- t/unit/core/store_test.c | 8 +-- t/unit/frontend/parser_test.c | 82 +++++++++++++------------- 6 files changed, 125 insertions(+), 125 deletions(-) diff --git a/src/core/store-private.h b/src/core/store-private.h index 6e232dd..717f893 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -139,12 +139,12 @@ enum { MATCHER_SERVICE, MATCHER_METRIC, MATCHER_ATTRIBUTE, - MATCHER_CMP_LT, - MATCHER_CMP_LE, - MATCHER_CMP_EQ, - MATCHER_CMP_NE, - MATCHER_CMP_GE, - MATCHER_CMP_GT, + MATCHER_LT, + MATCHER_LE, + MATCHER_EQ, + MATCHER_NE, + MATCHER_GE, + MATCHER_GT, MATCHER_IN, MATCHER_REGEX, MATCHER_NREGEX, @@ -161,7 +161,12 @@ enum { : ((t) == MATCHER_SERVICE) ? "SERVICE" \ : ((t) == MATCHER_METRIC) ? "METRIC" \ : ((t) == MATCHER_ATTRIBUTE) ? "ATTRIBUTE" \ - : ((t) == MATCHER_CMP_NE) ? "!=" \ + : ((t) == MATCHER_LT) ? "<" \ + : ((t) == MATCHER_LE) ? "<=" \ + : ((t) == MATCHER_EQ) ? "=" \ + : ((t) == MATCHER_NE) ? "!=" \ + : ((t) == MATCHER_GE) ? ">=" \ + : ((t) == MATCHER_GT) ? ">" \ : ((t) == MATCHER_IN) ? "IN" \ : ((t) == MATCHER_REGEX) ? "=~" \ : ((t) == MATCHER_NREGEX) ? "!~" \ diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 05e6b74..7f96057 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -286,64 +286,64 @@ cmp_expr(sdb_store_expr_t *e1, sdb_store_expr_t *e2, } /* cmp_expr */ static int -match_cmp_lt(sdb_store_matcher_t *m, sdb_store_obj_t *obj, +match_lt(sdb_store_matcher_t *m, sdb_store_obj_t *obj, sdb_store_matcher_t *filter) { int status; - assert(m->type == MATCHER_CMP_LT); + assert(m->type == MATCHER_LT); status = cmp_expr(CMP_M(m)->left, CMP_M(m)->right, obj, filter); return (status != INT_MAX) && (status < 0); -} /* match_cmp_lt */ +} /* match_lt */ static int -match_cmp_le(sdb_store_matcher_t *m, sdb_store_obj_t *obj, +match_le(sdb_store_matcher_t *m, sdb_store_obj_t *obj, sdb_store_matcher_t *filter) { int status; - assert(m->type == MATCHER_CMP_LE); + assert(m->type == MATCHER_LE); status = cmp_expr(CMP_M(m)->left, CMP_M(m)->right, obj, filter); return (status != INT_MAX) && (status <= 0); -} /* match_cmp_le */ +} /* match_le */ static int -match_cmp_eq(sdb_store_matcher_t *m, sdb_store_obj_t *obj, +match_eq(sdb_store_matcher_t *m, sdb_store_obj_t *obj, sdb_store_matcher_t *filter) { int status; - assert(m->type == MATCHER_CMP_EQ); + assert(m->type == MATCHER_EQ); status = cmp_expr(CMP_M(m)->left, CMP_M(m)->right, obj, filter); return (status != INT_MAX) && (! status); -} /* match_cmp_eq */ +} /* match_eq */ static int -match_cmp_ne(sdb_store_matcher_t *m, sdb_store_obj_t *obj, +match_ne(sdb_store_matcher_t *m, sdb_store_obj_t *obj, sdb_store_matcher_t *filter) { int status; - assert(m->type == MATCHER_CMP_NE); + assert(m->type == MATCHER_NE); status = cmp_expr(CMP_M(m)->left, CMP_M(m)->right, obj, filter); return (status != INT_MAX) && status; -} /* match_cmp_ne */ +} /* match_ne */ static int -match_cmp_ge(sdb_store_matcher_t *m, sdb_store_obj_t *obj, +match_ge(sdb_store_matcher_t *m, sdb_store_obj_t *obj, sdb_store_matcher_t *filter) { int status; - assert(m->type == MATCHER_CMP_GE); + assert(m->type == MATCHER_GE); status = cmp_expr(CMP_M(m)->left, CMP_M(m)->right, obj, filter); return (status != INT_MAX) && (status >= 0); -} /* match_cmp_ge */ +} /* match_ge */ static int -match_cmp_gt(sdb_store_matcher_t *m, sdb_store_obj_t *obj, +match_gt(sdb_store_matcher_t *m, sdb_store_obj_t *obj, sdb_store_matcher_t *filter) { int status; - assert(m->type == MATCHER_CMP_GT); + assert(m->type == MATCHER_GT); status = cmp_expr(CMP_M(m)->left, CMP_M(m)->right, obj, filter); return (status != INT_MAX) && (status > 0); -} /* match_cmp_gt */ +} /* match_gt */ static int match_in(sdb_store_matcher_t *m, sdb_store_obj_t *obj, @@ -464,12 +464,12 @@ matchers[] = { match_child, match_child, match_child, - match_cmp_lt, - match_cmp_le, - match_cmp_eq, - match_cmp_ne, - match_cmp_ge, - match_cmp_gt, + match_lt, + match_le, + match_eq, + match_ne, + match_ge, + match_gt, match_in, match_regex, match_regex, @@ -757,52 +757,47 @@ sdb_store_child_matcher(int type, sdb_store_matcher_t *m) return M(sdb_object_create("any-matcher", child_type, type, m)); } /* sdb_store_child_matcher */ -/* - * TODO: Rename sdb_store_cmp_* to sdb_store_* once the old code is unused and - * has been removed. - */ - sdb_store_matcher_t * -sdb_store_cmp_lt(sdb_store_expr_t *left, sdb_store_expr_t *right) +sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) { return M(sdb_object_create("lt-matcher", cmp_type, - MATCHER_CMP_LT, left, right)); -} /* sdb_store_cmp_lt */ + MATCHER_LT, left, right)); +} /* sdb_store_lt_matcher */ sdb_store_matcher_t * -sdb_store_cmp_le(sdb_store_expr_t *left, sdb_store_expr_t *right) +sdb_store_le_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) { return M(sdb_object_create("le-matcher", cmp_type, - MATCHER_CMP_LE, left, right)); -} /* sdb_store_cmp_le */ + MATCHER_LE, left, right)); +} /* sdb_store_le_matcher */ sdb_store_matcher_t * -sdb_store_cmp_eq(sdb_store_expr_t *left, sdb_store_expr_t *right) +sdb_store_eq_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) { return M(sdb_object_create("eq-matcher", cmp_type, - MATCHER_CMP_EQ, left, right)); -} /* sdb_store_cmp_eq */ + MATCHER_EQ, left, right)); +} /* sdb_store_eq_matcher */ sdb_store_matcher_t * -sdb_store_cmp_ne(sdb_store_expr_t *left, sdb_store_expr_t *right) +sdb_store_ne_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) { return M(sdb_object_create("ne-matcher", cmp_type, - MATCHER_CMP_NE, left, right)); -} /* sdb_store_cmp_ne */ + MATCHER_NE, left, right)); +} /* sdb_store_ne_matcher */ sdb_store_matcher_t * -sdb_store_cmp_ge(sdb_store_expr_t *left, sdb_store_expr_t *right) +sdb_store_ge_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) { return M(sdb_object_create("ge-matcher", cmp_type, - MATCHER_CMP_GE, left, right)); -} /* sdb_store_cmp_ge */ + MATCHER_GE, left, right)); +} /* sdb_store_ge_matcher */ sdb_store_matcher_t * -sdb_store_cmp_gt(sdb_store_expr_t *left, sdb_store_expr_t *right) +sdb_store_gt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) { return M(sdb_object_create("gt-matcher", cmp_type, - MATCHER_CMP_GT, left, right)); -} /* sdb_store_cmp_gt */ + MATCHER_GT, left, right)); +} /* sdb_store_gt_matcher */ sdb_store_matcher_t * sdb_store_in_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) @@ -858,17 +853,17 @@ sdb_store_matcher_op_cb sdb_store_parse_matcher_op(const char *op) { if (! strcasecmp(op, "<")) - return sdb_store_cmp_lt; + return sdb_store_lt_matcher; else if (! strcasecmp(op, "<=")) - return sdb_store_cmp_le; + return sdb_store_le_matcher; else if (! strcasecmp(op, "=")) - return sdb_store_cmp_eq; + return sdb_store_eq_matcher; else if (! strcasecmp(op, "!=")) - return sdb_store_cmp_ne; + return sdb_store_ne_matcher; else if (! strcasecmp(op, ">=")) - return sdb_store_cmp_ge; + return sdb_store_ge_matcher; else if (! strcasecmp(op, ">")) - return sdb_store_cmp_gt; + return sdb_store_gt_matcher; else if (! strcasecmp(op, "=~")) return sdb_store_regex_matcher; else if (! strcasecmp(op, "!~")) diff --git a/src/include/core/store.h b/src/include/core/store.h index cef3d06..a3bb2b7 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -401,23 +401,23 @@ sdb_store_child_matcher(int type, sdb_store_matcher_t *m); /* * sdb_store_lt_matcher, sdb_store_le_matcher, sdb_store_eq_matcher, * sdb_store_ge_matcher, sdb_store_gt_matcher: - * Creates a matcher based on a conditional. The matcher matches objects for - * which the conditional evaluates the object to compare less than, less or - * equal, equal, greater or equal, or greater than the conditional's value - * repsectively. + * Create conditional matchers comparing the values of two expressions. The + * matcher matches if the left expression compres less than, less or equal + * than, equal to, not equal to, greater or equal than, or greater than the + * right expression. */ sdb_store_matcher_t * -sdb_store_cmp_lt(sdb_store_expr_t *left, sdb_store_expr_t *right); +sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * -sdb_store_cmp_le(sdb_store_expr_t *left, sdb_store_expr_t *right); +sdb_store_le_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * -sdb_store_cmp_eq(sdb_store_expr_t *left, sdb_store_expr_t *right); +sdb_store_eq_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * -sdb_store_cmp_ne(sdb_store_expr_t *left, sdb_store_expr_t *right); +sdb_store_ne_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * -sdb_store_cmp_ge(sdb_store_expr_t *left, sdb_store_expr_t *right); +sdb_store_ge_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); sdb_store_matcher_t * -sdb_store_cmp_gt(sdb_store_expr_t *left, sdb_store_expr_t *right); +sdb_store_gt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right); /* * sdb_store_in_matcher: diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 38162d2..d80a599 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -316,11 +316,11 @@ START_TEST(test_cmp_attr) sdb_store_expr_t *); int expected; } tests[] = { - { sdb_store_cmp_lt, golden_data[i].expected_lt }, - { sdb_store_cmp_le, golden_data[i].expected_le }, - { sdb_store_cmp_eq, golden_data[i].expected_eq }, - { sdb_store_cmp_ge, golden_data[i].expected_ge }, - { sdb_store_cmp_gt, golden_data[i].expected_gt }, + { sdb_store_lt_matcher, golden_data[i].expected_lt }, + { sdb_store_le_matcher, golden_data[i].expected_le }, + { sdb_store_eq_matcher, golden_data[i].expected_eq }, + { sdb_store_ge_matcher, golden_data[i].expected_ge }, + { sdb_store_gt_matcher, golden_data[i].expected_gt }, }; sdb_data_format(&golden_data[i].value, @@ -425,11 +425,11 @@ START_TEST(test_cmp_obj) sdb_store_expr_t *); int expected; } tests[] = { - { sdb_store_cmp_lt, golden_data[i].expected_lt }, - { sdb_store_cmp_le, golden_data[i].expected_le }, - { sdb_store_cmp_eq, golden_data[i].expected_eq }, - { sdb_store_cmp_ge, golden_data[i].expected_ge }, - { sdb_store_cmp_gt, golden_data[i].expected_gt }, + { sdb_store_lt_matcher, golden_data[i].expected_lt }, + { sdb_store_le_matcher, golden_data[i].expected_le }, + { sdb_store_eq_matcher, golden_data[i].expected_eq }, + { sdb_store_ge_matcher, golden_data[i].expected_ge }, + { sdb_store_gt_matcher, golden_data[i].expected_gt }, }; char *op_str[] = { "<", "<=", "=", ">=", ">" }; diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index df07fff..f459b6e 100644 --- a/t/unit/core/store_test.c +++ b/t/unit/core/store_test.c @@ -605,14 +605,14 @@ START_TEST(test_store_tojson) "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": []}" "]" }, - { { sdb_store_cmp_eq, SDB_FIELD_NAME, + { { sdb_store_eq_matcher, SDB_FIELD_NAME, { SDB_TYPE_STRING, { .string = "h1" } } }, 0, "[" "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [], \"metrics\": [], \"services\": []}" "]" }, - { { sdb_store_cmp_gt, SDB_FIELD_LAST_UPDATE, + { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE, { SDB_TYPE_DATETIME, { .datetime = 1 } } }, 0, "[" "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " @@ -630,7 +630,7 @@ START_TEST(test_store_tojson) "]}" "]}" "]" }, - { { sdb_store_cmp_le, SDB_FIELD_LAST_UPDATE, + { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE, { SDB_TYPE_DATETIME, { .datetime = 1 } } }, 0, "[" "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " @@ -648,7 +648,7 @@ START_TEST(test_store_tojson) "], " "\"services\": []}" "]" }, - { { sdb_store_cmp_ge, SDB_FIELD_LAST_UPDATE, + { { sdb_store_ge_matcher, SDB_FIELD_LAST_UPDATE, { SDB_TYPE_DATETIME, { .datetime = 3 } } }, 0, "[" "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " diff --git a/t/unit/frontend/parser_test.c b/t/unit/frontend/parser_test.c index 0112da6..e251d71 100644 --- a/t/unit/frontend/parser_test.c +++ b/t/unit/frontend/parser_test.c @@ -329,61 +329,61 @@ START_TEST(test_parse_matcher) "service =~ 'pattern'", -1, MATCHER_OR }, { "NOT host = 'host'", -1, MATCHER_NOT }, /* numeric expressions */ - { "attribute['foo'] < 123", -1, MATCHER_CMP_LT }, - { "attribute['foo'] <= 123", -1, MATCHER_CMP_LE }, - { "attribute['foo'] = 123", -1, MATCHER_CMP_EQ }, - { "attribute['foo'] >= 123", -1, MATCHER_CMP_GE }, - { "attribute['foo'] > 123", -1, MATCHER_CMP_GT }, + { "attribute['foo'] < 123", -1, MATCHER_LT }, + { "attribute['foo'] <= 123", -1, MATCHER_LE }, + { "attribute['foo'] = 123", -1, MATCHER_EQ }, + { "attribute['foo'] >= 123", -1, MATCHER_GE }, + { "attribute['foo'] > 123", -1, MATCHER_GT }, /* datetime expressions */ { "attribute['foo'] = " - "2014-08-16", -1, MATCHER_CMP_EQ }, + "2014-08-16", -1, MATCHER_EQ }, { "attribute['foo'] = " - "17:23", -1, MATCHER_CMP_EQ }, + "17:23", -1, MATCHER_EQ }, { "attribute['foo'] = " - "17:23:53", -1, MATCHER_CMP_EQ }, + "17:23:53", -1, MATCHER_EQ }, { "attribute['foo'] = " - "17:23:53.123", -1, MATCHER_CMP_EQ }, + "17:23:53.123", -1, MATCHER_EQ }, { "attribute['foo'] = " - "17:23:53.123456789", -1, MATCHER_CMP_EQ }, + "17:23:53.123456789", -1, MATCHER_EQ }, { "attribute['foo'] = " - "2014-08-16 17:23", -1, MATCHER_CMP_EQ }, + "2014-08-16 17:23", -1, MATCHER_EQ }, { "attribute['foo'] = " - "2014-08-16 17:23:53", -1, MATCHER_CMP_EQ }, + "2014-08-16 17:23:53", -1, MATCHER_EQ }, /* NULL; while this is an implementation detail, * IS NULL currently maps to an equality matcher */ { "attribute['foo'] IS NULL", -1, MATCHER_ISNULL }, { "attribute['foo'] IS NOT NULL", -1, MATCHER_ISNNULL }, /* object field matchers */ - { ".name < 'a'", -1, MATCHER_CMP_LT }, - { ".name <= 'a'", -1, MATCHER_CMP_LE }, - { ".name = 'a'", -1, MATCHER_CMP_EQ }, - { ".name != 'a'", -1, MATCHER_CMP_NE }, - { ".name >= 'a'", -1, MATCHER_CMP_GE }, - { ".name > 'a'", -1, MATCHER_CMP_GT }, - { ".last_update < 2014-10-01", -1, MATCHER_CMP_LT }, - { ".last_update <= 2014-10-01", -1, MATCHER_CMP_LE }, - { ".last_update = 2014-10-01", -1, MATCHER_CMP_EQ }, - { ".last_update != 2014-10-01", -1, MATCHER_CMP_NE }, - { ".last_update >= 2014-10-01", -1, MATCHER_CMP_GE }, - { ".last_update > 2014-10-01", -1, MATCHER_CMP_GT }, - { ".Last_Update >= 24D", -1, MATCHER_CMP_GE }, - { ".age < 20s", -1, MATCHER_CMP_LT }, - { ".age <= 20s", -1, MATCHER_CMP_LE }, - { ".age = 20s", -1, MATCHER_CMP_EQ }, - { ".age != 20s", -1, MATCHER_CMP_NE }, - { ".age >= 20s", -1, MATCHER_CMP_GE }, - { ".age > 20s", -1, MATCHER_CMP_GT }, - { ".AGE <= 1m", -1, MATCHER_CMP_LE }, - { ".age > 1M", -1, MATCHER_CMP_GT }, - { ".age != 20Y", -1, MATCHER_CMP_NE }, - { ".age <= 2 * .interval", -1, MATCHER_CMP_LE }, - { ".interval < 20s", -1, MATCHER_CMP_LT }, - { ".interval <= 20s", -1, MATCHER_CMP_LE }, - { ".interval = 20s", -1, MATCHER_CMP_EQ }, - { ".interval != 20s", -1, MATCHER_CMP_NE }, - { ".interval >= 20s", -1, MATCHER_CMP_GE }, - { ".interval > 20s", -1, MATCHER_CMP_GT }, + { ".name < 'a'", -1, MATCHER_LT }, + { ".name <= 'a'", -1, MATCHER_LE }, + { ".name = 'a'", -1, MATCHER_EQ }, + { ".name != 'a'", -1, MATCHER_NE }, + { ".name >= 'a'", -1, MATCHER_GE }, + { ".name > 'a'", -1, MATCHER_GT }, + { ".last_update < 2014-10-01", -1, MATCHER_LT }, + { ".last_update <= 2014-10-01", -1, MATCHER_LE }, + { ".last_update = 2014-10-01", -1, MATCHER_EQ }, + { ".last_update != 2014-10-01", -1, MATCHER_NE }, + { ".last_update >= 2014-10-01", -1, MATCHER_GE }, + { ".last_update > 2014-10-01", -1, MATCHER_GT }, + { ".Last_Update >= 24D", -1, MATCHER_GE }, + { ".age < 20s", -1, MATCHER_LT }, + { ".age <= 20s", -1, MATCHER_LE }, + { ".age = 20s", -1, MATCHER_EQ }, + { ".age != 20s", -1, MATCHER_NE }, + { ".age >= 20s", -1, MATCHER_GE }, + { ".age > 20s", -1, MATCHER_GT }, + { ".AGE <= 1m", -1, MATCHER_LE }, + { ".age > 1M", -1, MATCHER_GT }, + { ".age != 20Y", -1, MATCHER_NE }, + { ".age <= 2 * .interval", -1, MATCHER_LE }, + { ".interval < 20s", -1, MATCHER_LT }, + { ".interval <= 20s", -1, MATCHER_LE }, + { ".interval = 20s", -1, MATCHER_EQ }, + { ".interval != 20s", -1, MATCHER_NE }, + { ".interval >= 20s", -1, MATCHER_GE }, + { ".interval > 20s", -1, MATCHER_GT }, { "'be' IN .backend", -1, MATCHER_IN }, /* check operator precedence */ -- 2.30.2