summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 132f7e1)
raw | patch | inline | side by side (parent: 132f7e1)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 22 Oct 2014 08:48:13 +0000 (10:48 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 22 Oct 2014 08:48:13 +0000 (10:48 +0200) |
Those functions have been superseded by the new expression-based matchers.
index c6350b3530c4a2518ce0a515da601c1256768700..be262ec61ecfb901a2fb12ff96667d8083f5786c 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
} attr_cond_t;
#define ATTR_C(obj) ((attr_cond_t *)(obj))
-typedef struct {
- sdb_store_cond_t super;
- int field;
- sdb_store_expr_t *expr;
-} obj_cond_t;
-#define OBJ_C(obj) ((obj_cond_t *)(obj))
-
/*
* matchers
*/
index 5187a3785b3b737be5964906c11c32e0d60c384d..5f23cd753d9b4cda959c7111aae2d76fd8c1a34f 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
return status;
} /* attr_cmp */
-static int
-obj_cmp(sdb_store_obj_t *obj, sdb_store_cond_t *cond,
- sdb_store_matcher_t *filter)
-{
- sdb_data_t obj_value = SDB_DATA_INIT;
- sdb_data_t value = SDB_DATA_INIT;
- int status;
-
- if (sdb_store_expr_eval(OBJ_C(cond)->expr, obj, &value, filter))
- return INT_MAX;
-
- if (OBJ_C(cond)->field == SDB_FIELD_BACKEND) {
- /* this implementation is not actually a conditional but rather checks
- * for equality (or rather, existence) only */
- size_t i;
-
- if (value.type != SDB_TYPE_STRING)
- return INT_MAX;
-
- status = INT_MAX;
- for (i = 0; i < obj->backends_num; ++i) {
- if (! strcasecmp(obj->backends[i], value.data.string)) {
- status = 0;
- break;
- }
- }
- sdb_data_free_datum(&value);
- return status;
- }
-
- if (sdb_store_get_field(obj, OBJ_C(cond)->field, &obj_value))
- return INT_MAX;
- if (obj_value.type != value.type) {
- sdb_data_free_datum(&obj_value);
- sdb_data_free_datum(&value);
- return INT_MAX;
- }
-
- status = sdb_data_cmp(&obj_value, &value);
- sdb_data_free_datum(&obj_value);
- sdb_data_free_datum(&value);
- return status;
-} /* obj_cmp */
-
/*
* matcher implementations
*/
/* destroy = */ attr_cond_destroy,
};
-static int
-obj_cond_init(sdb_object_t *obj, va_list ap)
-{
- int field = va_arg(ap, int);
- sdb_store_expr_t *expr = va_arg(ap, sdb_store_expr_t *);
-
- SDB_STORE_COND(obj)->cmp = obj_cmp;
-
- OBJ_C(obj)->field = field;
- OBJ_C(obj)->expr = expr;
- sdb_object_ref(SDB_OBJ(expr));
- return 0;
-} /* obj_cond_init */
-
-static void
-obj_cond_destroy(sdb_object_t *obj)
-{
- sdb_object_deref(SDB_OBJ(OBJ_C(obj)->expr));
-} /* obj_cond_destroy */
-
-static sdb_type_t obj_cond_type = {
- /* size = */ sizeof(obj_cond_t),
- /* init = */ obj_cond_init,
- /* destroy = */ obj_cond_destroy,
-};
-
/*
* private matcher types
*/
name, expr));
} /* sdb_store_attr_cond */
-sdb_store_cond_t *
-sdb_store_obj_cond(int field, sdb_store_expr_t *expr)
-{
- return SDB_STORE_COND(sdb_object_create("obj-cond", obj_cond_type,
- field, expr));
-} /* sdb_store_obj_cond */
-
sdb_store_matcher_t *
sdb_store_name_matcher(int type, const char *name, _Bool re)
{
return maybe_inv_matcher(m, inv);
} /* sdb_store_matcher_parse_cmp */
-sdb_store_matcher_t *
-sdb_store_matcher_parse_field_cmp(const char *name, const char *op,
- sdb_store_expr_t *expr)
-{
- sdb_store_matcher_t *(*matcher)(sdb_store_cond_t *) = NULL;
- sdb_store_matcher_t *m;
- sdb_store_cond_t *cond;
- _Bool inv = 0;
-
- int field;
-
- if (! expr)
- return NULL;
-
- field = sdb_store_parse_field_name(name);
- if (field < 0)
- return NULL;
-
- if (parse_cond_op(op, &matcher, &inv))
- return NULL;
- cond = sdb_store_obj_cond(field, expr);
- if (! cond)
- return NULL;
-
- assert(matcher);
- m = matcher(cond);
- /* pass ownership to 'm' or destroy in case of an error */
- sdb_object_deref(SDB_OBJ(cond));
- return maybe_inv_matcher(m, inv);
-} /* sdb_store_matcher_parse_field_cmp */
-
sdb_store_matcher_t *
sdb_store_dis_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right)
{
index 2624194955c3ed9ebee454fec4e83dc017e0c8ec..4e9e32ce1d25ec980a15eb16773f6c52f1773daa 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
sdb_store_cond_t *
sdb_store_attr_cond(const char *name, sdb_store_expr_t *expr);
-/*
- * sdb_store_obj_cond:
- * Creates a conditional based on queryable object fields. The respective
- * field of *any* object type is compared against the value the expression
- * evaluates to.
- */
-sdb_store_cond_t *
-sdb_store_obj_cond(int field, sdb_store_expr_t *expr);
-
/*
* sdb_store_name_matcher:
* Creates a matcher matching by the specified object type's name. If 're' is
sdb_store_matcher_parse_cmp(const char *obj_type, const char *attr,
const char *op, sdb_store_expr_t *expr);
-/*
- * sdb_store_matcher_parse_field_cmp:
- * Parse a simple compare expression for queryable object fields (<field> <op>
- * <expression>).
- *
- * Returns:
- * - a matcher object on success
- * - NULL else
- */
-sdb_store_matcher_t *
-sdb_store_matcher_parse_field_cmp(const char *name, const char *op,
- sdb_store_expr_t *expr);
-
/*
* sdb_store_dis_matcher:
* Creates a matcher matching the disjunction (logical OR) of two matchers.
index ed2731292fa4f55b8cd5d49ec88ce55b68d0854a..805de03e7deb6f6645aaa37be3d85c4344680cc3 100644 (file)
}
END_TEST
-START_TEST(test_parse_field_cmp)
-{
- sdb_data_t datetime = { SDB_TYPE_DATETIME, { .datetime = 1 } };
- sdb_data_t string = { SDB_TYPE_STRING, { .string = "s" } };
-
- struct {
- const char *field;
- const char *op;
- const sdb_data_t *value;
- int expected;
- } golden_data[] = {
- { "name", "<", &string, MATCHER_LT },
- { "name", "<=", &string, MATCHER_LE },
- { "name", "=", &string, MATCHER_EQ },
- { "name", ">=", &string, MATCHER_GE },
- { "name", ">", &string, MATCHER_GT },
- { "name", "!=", &string, MATCHER_NOT },
- { "last_update", "<", &datetime, MATCHER_LT },
- { "last_update", "<=", &datetime, MATCHER_LE },
- { "last_update", "=", &datetime, MATCHER_EQ },
- { "last_update", ">=", &datetime, MATCHER_GE },
- { "last_update", ">", &datetime, MATCHER_GT },
- { "last_update", "!=", &datetime, MATCHER_NOT },
- { "age", "<", &datetime, MATCHER_LT },
- { "age", "<=", &datetime, MATCHER_LE },
- { "age", "=", &datetime, MATCHER_EQ },
- { "age", ">=", &datetime, MATCHER_GE },
- { "age", ">", &datetime, MATCHER_GT },
- { "age", "!=", &datetime, MATCHER_NOT },
- { "interval", "<", &datetime, MATCHER_LT },
- { "interval", "<=", &datetime, MATCHER_LE },
- { "interval", "=", &datetime, MATCHER_EQ },
- { "interval", ">=", &datetime, MATCHER_GE },
- { "interval", ">", &datetime, MATCHER_GT },
- { "interval", "!=", &datetime, MATCHER_NOT },
- { "backend", "=", &string, MATCHER_EQ },
- { "backend", "!=", &string, MATCHER_NOT },
- /* the behavior for other operators on .backend
- * is currently unspecified */
- { "last_update", "=", NULL, -1 },
- { "last_update", "IS", NULL, -1 },
- { "age", "=", NULL, -1 },
- { "interval", "=", NULL, -1 },
- { "backend", "=", NULL, -1 },
- { "backend", "=~", &string, -1 },
- };
-
- size_t i;
-
- for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
- sdb_store_matcher_t *check;
- sdb_store_expr_t *expr;
- char buf[1024];
-
- if (sdb_data_format(golden_data[i].value,
- buf, sizeof(buf), SDB_UNQUOTED) < 0)
- snprintf(buf, sizeof(buf), "ERR");
-
- expr = sdb_store_expr_constvalue(golden_data[i].value);
- fail_unless(expr != NULL || golden_data[i].value == NULL,
- "sdb_store_expr_constvalue(%s) = NULL; expected: <expr>",
- buf);
-
- check = sdb_store_matcher_parse_field_cmp(golden_data[i].field,
- golden_data[i].op, expr);
- sdb_object_deref(SDB_OBJ(expr));
-
- if (golden_data[i].expected == -1) {
- fail_unless(check == NULL,
- "sdb_store_matcher_parse_field_cmp(%s, %s, expr{%s}) = %p; "
- "expected: NULL", golden_data[i].field,
- golden_data[i].op, buf, check);
- continue;
- }
-
- fail_unless(check != NULL,
- "sdb_store_matcher_parse_field_cmp(%s, %s, %s) = %p; "
- "expected: NULL", golden_data[i].field,
- golden_data[i].op, buf, check);
- fail_unless(M(check)->type == golden_data[i].expected,
- "sdb_store_matcher_parse_field_cmp(%s, %s, %s) returned "
- "matcher of type %d; expected: %d", golden_data[i].field,
- golden_data[i].op, buf, M(check)->type,
- golden_data[i].expected);
-
- sdb_object_deref(SDB_OBJ(check));
- }
-}
-END_TEST
-
static int
scan_cb(sdb_store_obj_t *obj, void *user_data)
{
tcase_add_test(tc, test_cmp_obj);
tcase_add_test(tc, test_store_match_op);
tcase_add_test(tc, test_parse_cmp);
- tcase_add_test(tc, test_parse_field_cmp);
tcase_add_test(tc, test_scan);
suite_add_tcase(s, tc);
index bcf00b22088ca27e3a3c3f1906cd660b665a91f5..0112da69d28c37f381d911c719fb05c360a8272c 100644 (file)
{ "attribute['foo'] IS NOT NULL", -1, MATCHER_ISNNULL },
/* object field matchers */
- { ".last_update < 10s", -1, MATCHER_CMP_LT },
- { ".AGE <= 1m", -1, MATCHER_CMP_LE },
- { ".interval = 10h", -1, MATCHER_CMP_EQ },
+ { ".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 },
{ "'be' IN .backend", -1, MATCHER_IN },
/* check operator precedence */