Skip to content

Commit

Permalink
* #239
Browse files Browse the repository at this point in the history
  • Loading branch information
adamansky committed Apr 8, 2019
1 parent 1333fc1 commit 4ed6371
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 10 deletions.
2 changes: 2 additions & 0 deletions hints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
## GDB
handle SIGINT nostop print pass

export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer

## WS

wscat --slash -H 'X-Access-Token:access' -q -c http://localhost:9191
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/ejdb2_dart/lib/ejdb2_dart.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ static void jql_set(Dart_NativeArguments args) {
if (type == 1) { // JSON
EJTH(Dart_StringToCString(hvalue, &svalue));
JBL_NODE node;
IWPOOL *pool = iwpool_create(0);
IWPOOL *pool = iwpool_create(1024);
if (!pool) {
rc = IW_ERROR_ALLOC;
goto finish;
Expand Down
3 changes: 2 additions & 1 deletion src/bindings/ejdb2_dart/test/ejdb2_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ void main() async {
.execute()
.first;

doc = await db.createQuery('@mycoll/[foo = :?]').setRegExp(0, RegExp('.*')).execute().first;
///doc = await db.createQuery('@mycoll/[foo re :?]').setRegExp(0, RegExp('.*')).execute().first;
doc = await db.createQuery('@mycoll/[foo re .*]').execute().first;
print('doc2=$doc');

await db.removeStringIndex('mycoll', '/foo', unique: true);
Expand Down
10 changes: 5 additions & 5 deletions src/ejdb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ static iwrc _jb_idx_record_add(JBIDX idx, int64_t id, JBL jbl, JBL jblprev) {
if (compound
&& jbv_type == jbvprev_type
&& jbvprev_type == JBV_ARRAY) { // compare next/prev obj arrays
pool = iwpool_create(0);
pool = iwpool_create(1024);
if (!pool) {
rc = iwrc_set_errno(IW_ERROR_ALLOC, errno);
goto finish;
Expand All @@ -526,7 +526,7 @@ static iwrc _jb_idx_record_add(JBIDX idx, int64_t id, JBL jbl, JBL jblprev) {
if (jbvprev_type == JBV_ARRAY) { // TODO: array modification delta?
JBL_NODE n;
if (!pool) {
pool = iwpool_create(0);
pool = iwpool_create(1024);
if (!pool) {
rc = iwrc_set_errno(IW_ERROR_ALLOC, errno);
}
Expand Down Expand Up @@ -565,7 +565,7 @@ static iwrc _jb_idx_record_add(JBIDX idx, int64_t id, JBL jbl, JBL jblprev) {
if (jbv_type == JBV_ARRAY) { // TODO: array modification delta?
JBL_NODE n;
if (!pool) {
pool = iwpool_create(0);
pool = iwpool_create(1024);
if (!pool) {
rc = iwrc_set_errno(IW_ERROR_ALLOC, errno);
}
Expand Down Expand Up @@ -876,7 +876,7 @@ iwrc ejdb_list3(EJDB db, const char *coll, const char *query, int64_t limit, IWX
}
iwrc rc = 0;
*listp = 0;
IWPOOL *pool = iwpool_create(0);
IWPOOL *pool = iwpool_create(1024);
if (!pool) {
return iwrc_set_errno(IW_ERROR_ALLOC, errno);
}
Expand Down Expand Up @@ -907,7 +907,7 @@ iwrc ejdb_list4(EJDB db, JQL q, int64_t limit, IWXSTR *log, EJDB_LIST *listp) {
}
iwrc rc = 0;
*listp = 0;
IWPOOL *pool = iwpool_create(0);
IWPOOL *pool = iwpool_create(1024);
if (!pool) {
return iwrc_set_errno(IW_ERROR_ALLOC, errno);
}
Expand Down
3 changes: 3 additions & 0 deletions src/jbi/jbi_selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ static iwrc _jbi_collect_indexes(JBEXEC *ctx,
mctx.orderby_support = (i == j);
rc = _jbi_compute_index_rules(ctx, &mctx);
RCRET(rc);
if (!mctx.expr1) { // Cannot find matching expressions
return 0;
}
if (ctx->ux->log) {
iwxstr_cat2(ctx->ux->log, "[INDEX] MATCHED ");
_jbi_log_index_rules(ctx->ux->log, &mctx);
Expand Down
2 changes: 1 addition & 1 deletion src/jbl/tests/jbl_test1.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void _jbl_test1_1(int num, iwrc expected, jbl_print_flags_t pf) {
data = iwu_file_read_as_buf(path);
CU_ASSERT_PTR_NOT_NULL_FATAL(data);

pool = iwpool_create(0);
pool = iwpool_create(1024);
CU_ASSERT_PTR_NOT_NULL_FATAL(pool);

rc = jbl_node_from_json(data, &node, pool);
Expand Down
2 changes: 2 additions & 0 deletions src/jql/jql.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ IW_INLINE void _jql_jqval_destroy(JQP_STRING *pv) {
}
if (ptr && qv->freefn) {
qv->freefn(ptr, qv->freefn_op);

}
pv->opaque = 0;
free(qv);
}
}
Expand Down
66 changes: 64 additions & 2 deletions src/tests/ejdb_test3.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ static void ejdb_test3_4() {
EJDB_LIST list = 0;
int64_t docId = 0;

IWPOOL *pool = iwpool_create(0);
IWPOOL *pool = iwpool_create(1024);
CU_ASSERT_PTR_NOT_NULL_FATAL(pool);
IWXSTR *log = iwxstr_new();
CU_ASSERT_PTR_NOT_NULL_FATAL(log);
Expand Down Expand Up @@ -922,6 +922,67 @@ void ejdb_test3_5() {
iwxstr_destroy(xstr);
}

static void jql_free_str(void *ptr, void *op) {
if (ptr) free(ptr);
}

void ejdb_test3_6() {
EJDB_OPTS opts = {
.kv = {
.path = "ejdb_test3_6.db",
.oflags = IWKV_TRUNC
}
};

JQL q;
EJDB db;
EJDB_LIST list = 0;
IWXSTR *xstr = iwxstr_new();
CU_ASSERT_PTR_NOT_NULL_FATAL(xstr);

iwrc rc = ejdb_open(&opts, &db);
CU_ASSERT_EQUAL_FATAL(rc, 0);

rc = ejdb_ensure_index(db, "mycoll", "/foo", EJDB_IDX_UNIQUE | EJDB_IDX_STR);
CU_ASSERT_EQUAL_FATAL(rc, 0);


rc = put_json(db, "mycoll", "{\"foo\":\"baz\",\"baz\":\"qux\"}");
CU_ASSERT_EQUAL_FATAL(rc, 0);

rc = jql_create(&q, 0, "@mycoll/[foo re :?]");
CU_ASSERT_EQUAL_FATAL(rc, 0);

rc = jql_set_regexp(q, 0, 0, ".*");
CU_ASSERT_EQUAL_FATAL(rc, 0);

rc = ejdb_list4(db, q, 0, 0, &list);
CU_ASSERT_EQUAL_FATAL(rc, 0);
CU_ASSERT_PTR_NOT_NULL_FATAL(list->first);

iwxstr_clear(xstr);
rc = jbl_as_json(list->first->raw, jbl_xstr_json_printer, xstr, 0);
CU_ASSERT_EQUAL_FATAL(rc, 0);
CU_ASSERT_STRING_EQUAL(iwxstr_ptr(xstr), "{\"foo\":\"baz\",\"baz\":\"qux\"}");
ejdb_list_destroy(&list);

// Now set regexp again
rc = jql_set_regexp2(q, 0, 0, strdup(".*"), jql_free_str, 0);
CU_ASSERT_EQUAL_FATAL(rc, 0);

rc = ejdb_list4(db, q, 0, 0, &list);
CU_ASSERT_EQUAL_FATAL(rc, 0);
CU_ASSERT_PTR_NOT_NULL_FATAL(list->first);

ejdb_list_destroy(&list);

rc = ejdb_close(&db);
CU_ASSERT_EQUAL_FATAL(rc, 0);
iwxstr_destroy(xstr);
jql_destroy(&q);

}

int main() {
CU_pSuite pSuite = NULL;
if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error();
Expand All @@ -935,7 +996,8 @@ int main() {
(NULL == CU_add_test(pSuite, "ejdb_test3_2", ejdb_test3_2)) ||
(NULL == CU_add_test(pSuite, "ejdb_test3_3", ejdb_test3_3)) ||
(NULL == CU_add_test(pSuite, "ejdb_test3_4", ejdb_test3_4)) ||
(NULL == CU_add_test(pSuite, "ejdb_test3_5", ejdb_test3_5))
(NULL == CU_add_test(pSuite, "ejdb_test3_5", ejdb_test3_5)) ||
(NULL == CU_add_test(pSuite, "ejdb_test3_6", ejdb_test3_6))
) {
CU_cleanup_registry();
return CU_get_error();
Expand Down

0 comments on commit 4ed6371

Please sign in to comment.