Merge lp:~thisfred/u1db/c-nested_index into lp:u1db
| Status: | Merged |
|---|---|
| Approved by: | John A Meinel on 2012-03-07 |
| Approved revision: | 224 |
| Merged at revision: | 226 |
| Proposed branch: | lp:~thisfred/u1db/c-nested_index |
| Merge into: | lp:u1db |
| Diff against target: |
189 lines (+48/-21) 4 files modified
src/u1db.c (+12/-12) src/u1db_query.c (+17/-1) u1db/tests/test_backends.py (+18/-3) u1db/tests/test_c_backend.py (+1/-5) |
| To merge this branch: | bzr merge lp:~thisfred/u1db/c-nested_index |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| John A Meinel (community) | 2012-03-06 | Needs Fixing on 2012-03-07 | |
|
Review via email:
|
|||
Commit Message
Added support for nested indexes.
Description of the Change
Added support for nested indexes.
| Eric Casteleijn (thisfred) wrote : | # |
- 222. By Eric Casteleijn on 2012-03-06
-
initialize
- 223. By Eric Casteleijn on 2012-03-06
-
strtok_r is threadsafe
| John A Meinel (jameinel) wrote : | # |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 3/6/2012 7:45 PM, Eric Casteleijn wrote:
> Eric Casteleijn has proposed merging
> lp:~thisfred/u1db/c-nested_index into lp:u1db.
>
> Requested reviews: John A Meinel (jameinel)
>
> For more details, see:
> https:/
>
> Added support for nested indexes.
+ val = int(self.
The assert is effectively that a ValueError is not raised because uid
is a valid hex string.
You can put a comment to that fact if you prefer. The uid is going to
be random, so we can't assert what value it has, but we are asserting
that it is a hex string.
- - val = json_object_
+ tmp_expression = strdup(expression); // XXX: need to test for out
of mem?
+ result = strtok(
+ val = ctx->obj;
+ while (result != NULL) {
+ val = json_object_
+ result = strtok(NULL, DOT);
+ }
+ free(tmp_
I'm not a big fan of strtok, because the state is kept within the
function, rather than being exposed and passed back.
Plus it mutates the buffer you're working with, etc. Though we
probably don't have much choice on the latter, because libjson doesn't
have a get that you can pass the length of the string (it has to be
null-terminated).
I see that you switched to strtok_r in a follow up patch that doesn't
show up in the email diff. Which I thought was a good idea from "man
strtok", except strtok_r doesn't exist for MSVC.. :(
It isn't particularly hard to write our own strtok_r, or even do the
parsing manually, since we don't need to support a set of characters,
just one. So strchr is a pretty easy substitute.
// Not actually tested:
tmp_expression = strdup(expression);
result = tmp_expression;
while (result != NULL) {
dot_chr = strchr(result, '.');
if (dot_chr != NULL) {
*dot_chr = '\0';
dot_chr ++;
}
val = json_object_
result = dot_chr;
}
free(tmp_
Oh, we'll also want to trap for 'val' become non-existent, I believe
[while (result != NULL && val != NULL)]. I think we need another test
case for:
def tested_
doc = self.db.
# sub exists, but sub.foo does not:
self.
self.
I'm not 100% sure how json_object_
exist, but that's why we test it :).
This is the sort of test that *could* be a specific implementation
test, but it works well enough to be tested at the API level, and all
implementations shouldn't crash if an index requests an attribute that
doesn't exist.
Otherwise, I think this idea is pretty good.
review: needsfixing
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAk9
pdMAoKsheZPbqs+
=oLyS
-----END PGP SIGNATURE-----
| Eric Casteleijn (thisfred) wrote : | # |
Thanks, will fix, when mulling this over last night I realized we only tested for the happy path, and it probably breaks horribly when the subfield does not exist.
| Eric Casteleijn (thisfred) wrote : | # |
The above test passes with the current code, because the final val being NULL was already caught by the
if (val != NULL)
below, so I added another test which looks for a value that is nested deeper, and that indeed blew up the code, which your proposed extra check fixed.
- 224. By Eric Casteleijn on 2012-03-07
-
removed use of strtok, added a test for nonexistent nested fields, and fixed the code so it doesn't blow up in the face of that
| John A Meinel (jameinel) wrote : | # |
138 + def tested_
139 + doc = self.db.
140 + # sub exists, but sub.foo does not:
141 + self.db.
142 + self.assertEqua
143 +
144 + def tested_
145 + doc = self.db.
146 + # sub exists, but sub.foo does not:
147 + self.db.
148 + self.assertEqua
You have the test name duplicated. I don't know if you just want the second test, or if you want both of them. Otherwise this is good.
| Eric Casteleijn (thisfred) wrote : | # |
Oops, fixed.
- 225. By Eric Casteleijn on 2012-03-08
-
fixed test name

This is a very rough attempt to get the tests to pass. Please turn review harshness up to 11, as there may be performance issues or even memory management bugs. I added some XXX comments where I had questions, which I'll remove once they're addressed.