Skip to content

Commit

Permalink
All tests are passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Mast committed Feb 15, 2015
1 parent f4a17f9 commit 42d7ee2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 60 deletions.
13 changes: 10 additions & 3 deletions client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,21 @@ client :: prepare_checks(const char* space, const schema& sc,
return i;
}

if (!path && datatype == HYPERDATATYPE_DOCUMENT)
{
// Document datatype always requires a path. Empty means root.
path = "";
}

if (path)
{
size_t path_sz = strlen(path) + 1;
size_t sz = path_sz + chks[i].value_sz;
size_t sz = path_sz + c.value.size();
unsigned char* tmp = NULL;
memory->allocate(path_sz + chks[i].value_sz, &tmp);
memory->allocate(path_sz + c.value.size(), &tmp);
memmove(tmp, path, path_sz);
memmove(tmp + path_sz, chks[i].value, chks[i].value_sz);
memmove(tmp + path_sz, c.value.data(), c.value.size());

c.value = e::slice(tmp, sz);
}

Expand Down
74 changes: 24 additions & 50 deletions common/datatype_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ datatype_document :: apply(const e::slice& old_value,
return false;
}

// Pass funcall down to underlying datatype (string, integer etc...)
if (!di->apply(v, &func, 1, new_memory, &tmp_value))
{
return false;
Expand Down Expand Up @@ -360,11 +361,8 @@ bool
datatype_document :: document_check(const attribute_check& check,
const e::slice& doc) const
{
if (check.datatype == HYPERDATATYPE_DOCUMENT)
{
return check.predicate == HYPERPREDICATE_EQUALS &&
check.value == doc;
}
// We expected the follwing format:
// <path>\0\n<value>

const char* path = reinterpret_cast<const char*>(check.value.data());
size_t path_sz = strnlen(path, check.value.size());
Expand All @@ -383,13 +381,24 @@ datatype_document :: document_check(const attribute_check& check,
return false;
}

attribute_check new_check;
new_check.attr = check.attr;
new_check.value = check.value;
new_check.datatype = check.datatype;
new_check.predicate = check.predicate;
new_check.value.advance(path_sz + 1);
return passes_attribute_check(type, new_check, value);
if(type == HYPERDATATYPE_DOCUMENT)
{
// Compare two subdocuments
e::slice chk_value = check.value;
chk_value.advance(path_sz + 1);
return (value == chk_value);
}
else
{
// Pass down to underlying datatype
attribute_check new_check;
new_check.attr = check.attr;
new_check.value = check.value;
new_check.datatype = check.datatype;
new_check.predicate = check.predicate;
new_check.value.advance(path_sz + 1);
return passes_attribute_check(type, new_check, value);
}
}

bool
Expand Down Expand Up @@ -461,43 +470,6 @@ datatype_document :: coerce_primitive_to_binary(hyperdatatype type,
*value = e::slice(&(*scratch)[0], v_sz);
}

bool
datatype_document :: comparable() const
{
return true;
}

// Same as string compare
static int
compare(const e::slice& lhs,
const e::slice& rhs)
{
int cmp = memcmp(lhs.data(), rhs.data(), std::min(lhs.size(), rhs.size()));

if (cmp == 0)
{
if (lhs.size() < rhs.size())
{
return -1;
}

if (lhs.size() > rhs.size())
{
return 1;
}

return 0;
}

return cmp;
}

int
datatype_document :: compare(const e::slice& lhs, const e::slice& rhs) const
{
return ::compare(lhs, rhs);
}

bool
datatype_document :: coerce_binary_to_primitive(const e::slice& in,
hyperdatatype* type,
Expand Down Expand Up @@ -532,7 +504,9 @@ datatype_document :: coerce_binary_to_primitive(const e::slice& in,
else
{
*type = HYPERDATATYPE_DOCUMENT;
*value = in;
scratch->resize(in.size());
memmove(scratch->data(), in.data(), in.size());
*value = e::slice(&(*scratch)[0], in.size());
}

return true;
Expand Down
4 changes: 0 additions & 4 deletions common/datatype_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class datatype_document : public datatype_info
virtual bool document_check(const attribute_check& check,
const e::slice& value) const;

public:
bool comparable() const;
int compare(const e::slice& lhs, const e::slice& rhs) const;

public:
bool extract_value(const char* path,
const e::slice& data,
Expand Down
10 changes: 7 additions & 3 deletions test/python/DataTypeDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,14 @@ def to_objectset(xs):

# Search on Documents
assertTrue(c.put('kv', 'k9', {'v' : Document({'x' : {'b' : 'c'}})}))
#res1 = c.search('kv', {'v.x.b' : 'c'})
res1 = c.search('kv', {'v.x.b' : 'c'})
res2 = c.search('kv', {'v.x' : Document({'b' : 'c'})})
#assertEquals(res1.next(), {'k' : 'k9', 'v' : Document({'x' : {'b' : 'c'}})})
#assertFalse(res1.hasNext())
res3 = c.search('kv', {'v' : Document({'x' : {'b' : 'c'}})})
assertEquals(res1.next(), {'k' : 'k9', 'v' : Document({'x' : {'b' : 'c'}})})
assertFalse(res1.hasNext())
assertEquals(res2.next(), {'k' : 'k9', 'v' : Document({'x' : {'b' : 'c'}})})
assertFalse(res2.hasNext())
assertEquals(res3.next(), {'k' : 'k9', 'v' : Document({'x' : {'b' : 'c'}})})
assertFalse(res3.hasNext())


0 comments on commit 42d7ee2

Please sign in to comment.