Skip to content

Commit

Permalink
RediSearch query error reporting (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
swilly22 committed Feb 18, 2020
1 parent db0f55c commit ed22e52
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ GRAPH.QUERY DEMO_GRAPH "DROP INDEX ON :person(age)"
## Full-text indexes
RedisGraph leverages the indexing capabilities of RediSearch to provide full-text indexes through procedure calls. To construct a full-text index on the `title` property of all nodes with label `movie`, use the syntax:
RedisGraph leverages the indexing capabilities of [RediSearch](https://oss.redislabs.com/redisearch/index.html) to provide full-text indices through procedure calls. To construct a full-text index on the `title` property of all nodes with label `movie`, use the syntax:
```sh
GRAPH.QUERY DEMO_GRAPH "CALL db.idx.fulltext.createNodeIndex('movie', 'title')"
Expand Down
13 changes: 13 additions & 0 deletions src/procedures/proc_fulltext_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ ProcedureResult Proc_FulltextQueryNodeInvoke(ProcedureCtx *ctx, const SIValue *a

// Execute query
pdata->iter = Index_Query(pdata->idx, query, &err);
// Raise runtime exception if err != NULL.
if(err) {
/* RediSearch error message is allocated using `rm_strdup`
* QueryCtx is expecting to free `error` using `free`
* in which case we have no option but to clone error. */
char *error;
asprintf(&error, "RediSearch: %s", err);
rm_free(err);
QueryCtx_SetError(error);
/* Raise the exception, we expect an exception handler to be set.
* as procedure invocation is done at runtime. */
QueryCtx_RaiseRuntimeException();
}
assert(pdata->iter);

ctx->privateData = pdata;
Expand Down
2 changes: 1 addition & 1 deletion src/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ SIValue SIValue_Modulo(const SIValue a, const SIValue n) {
case true:
// The modulo machine instruction may be used if a and n are both integers.
return SI_LongVal(a.longval % n.longval);
case false:
default:
// Otherwise, use the library function fmod to calculate the modulo and return a double.
return SI_DoubleVal(fmod(SI_GET_NUMERIC(a), SI_GET_NUMERIC(n)));
}
Expand Down
10 changes: 9 additions & 1 deletion tests/flow/test_procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,12 @@ def test_procedure_propertyKeys(self):
actual_resultset = redis_graph.call_procedure("db.propertyKeys").result_set
expected_results = [["name"], ["value"]]
self.env.assertEquals(actual_resultset, expected_results)


def test_procedure_fulltext_syntax_error(self):
try:
query = """CALL db.idx.fulltext.queryNodes('fruit', 'Orange || Apple') YIELD node RETURN node"""
redis_graph.query(query)
assert(False)
except redis.exceptions.ResponseError:
# Expecting an error.
pass

0 comments on commit ed22e52

Please sign in to comment.