Skip to content

Commit

Permalink
store: During lookup use strcmp() only for unknown data-types.
Browse files Browse the repository at this point in the history
Unknown data-types means that we don't know the type of either one expression
before hand. For example, this is true for attributes given that there is no
schema.
  • Loading branch information
tokkee committed Oct 24, 2014
1 parent 9d15e8a commit b413c7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/core/store_lookup.c
Expand Up @@ -184,6 +184,8 @@ cmp_expr(sdb_store_expr_t *e1, sdb_store_expr_t *e2,
status = INT_MAX;
else if (v1.type == v2.type)
status = sdb_data_cmp(&v1, &v2);
else if ((e1->data_type >= 0) && (e2->data_type >= 0))
status = INT_MAX;
else
status = sdb_data_strcmp(&v1, &v2);

Expand Down
14 changes: 7 additions & 7 deletions t/unit/core/store_lookup_test.c
Expand Up @@ -266,6 +266,9 @@ START_TEST(test_cmp_attr)
{ sdb_store_gt_matcher, golden_data[i].expected_gt },
};

const char *op_str[] = { "<", "<=", "=", ">=", ">" };
assert(SDB_STATIC_ARRAY_LEN(tests) == SDB_STATIC_ARRAY_LEN(op_str));

sdb_data_format(&golden_data[i].value,
value_str, sizeof(value_str), SDB_UNQUOTED);

Expand All @@ -288,8 +291,10 @@ START_TEST(test_cmp_attr)

status = sdb_store_matcher_matches(m, host, /* filter */ NULL);
fail_unless(status == tests[j].expected,
"sdb_store_matcher_matches(<m>, <host>, NULL) = %d; "
"expected: %d", status, tests[j].expected);
"sdb_store_matcher_matches(<attr[%s] %s %s>, "
"<host>, NULL) = %d; expected: %d",
golden_data[i].attr, op_str[j], value_str,
status, tests[j].expected);

sdb_object_deref(SDB_OBJ(m));
}
Expand Down Expand Up @@ -332,8 +337,6 @@ START_TEST(test_cmp_obj)
{ "a", SDB_FIELD_INTERVAL,
{ SDB_TYPE_DATETIME, { .datetime = 1 } }, 1, 1, 0, 0, 0 },
/* type mismatch */
/* TODO: let matchers only use data_strcmp for attributes
* everything else has a well-known type
{ "a", SDB_FIELD_LAST_UPDATE,
{ SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
{ "a", SDB_FIELD_AGE,
Expand All @@ -344,13 +347,10 @@ START_TEST(test_cmp_obj)
{ SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
{ "a", SDB_FIELD_BACKEND,
{ SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 },
*/
/* (64bit) integer value without zero-bytes */
/*
{ "a", SDB_FIELD_BACKEND,
{ SDB_TYPE_INTEGER, { .integer = 0xffffffffffffffffL } },
0, 0, 0, 0, 0 },
*/
};

int status;
Expand Down

0 comments on commit b413c7f

Please sign in to comment.