Skip to content

Commit

Permalink
Added non existing entity runtime error (#919)
Browse files Browse the repository at this point in the history
* Added non existing entity runtime error

* fixed PR comments

Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
  • Loading branch information
DvirDukhan and swilly22 committed Feb 13, 2020
1 parent e54ce35 commit db0f55c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
19 changes: 15 additions & 4 deletions src/arithmetic/arithmetic_expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,19 @@ static AR_EXP_Result _AR_EXP_EvaluateFunctionCall(AR_ExpNode *node, const Record
return res;
}

static inline void _AR_EXP_UpdateEntityIdx(AR_OperandNode *node, const Record r) {
node->variadic.entity_alias_idx = Record_GetEntryIdx(r, node->variadic.entity_alias);
static bool _AR_EXP_UpdateEntityIdx(AR_OperandNode *node, const Record r) {
int entry_alias_idx = Record_GetEntryIdx(r, node->variadic.entity_alias);
if(entry_alias_idx == INVALID_INDEX) {
char *error;
asprintf(&error,
"_AR_EXP_UpdateEntityIdx: Unable to locate a value with alias %s within the record",
node->variadic.entity_alias);
QueryCtx_SetError(error); // Set the query-level error.
return false;
} else {
node->variadic.entity_alias_idx = entry_alias_idx;
return true;
}
}

static AR_EXP_Result _AR_EXP_EvaluateProperty(AR_ExpNode *node, const Record r, SIValue *result) {
Expand Down Expand Up @@ -334,10 +345,10 @@ static AR_EXP_Result _AR_EXP_EvaluateProperty(AR_ExpNode *node, const Record r,
static AR_EXP_Result _AR_EXP_EvaluateVariadic(AR_ExpNode *node, const Record r, SIValue *result) {
// Make sure entity record index is known.
if(node->operand.variadic.entity_alias_idx == IDENTIFIER_NOT_FOUND) {
_AR_EXP_UpdateEntityIdx(&node->operand, r);
if(!_AR_EXP_UpdateEntityIdx(&node->operand, r)) return EVAL_ERR;
}

// Fetch entity property value.
// Fetch entity property value.
if(node->operand.variadic.entity_prop != NULL) {
return _AR_EXP_EvaluateProperty(node, r, result);
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/execution_plan/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ int Record_GetEntryIdx(Record r, const char *alias) {
assert(r && alias);

void *idx = raxFind(r->mapping, (unsigned char *)alias, strlen(alias));
assert(idx != raxNotFound && "ERR: tried to resolve unexpected alias");

return (intptr_t)idx;
return idx != raxNotFound ? (intptr_t)idx : INVALID_INDEX;
}

void Record_Clone(const Record r, Record clone) {
Expand Down
3 changes: 3 additions & 0 deletions src/execution_plan/record.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "../graph/entities/edge.h"
#include <sys/types.h>

// Return value in case of call to Record_GetEntryIdx with invalid entry alias.
#define INVALID_INDEX -1

typedef enum {
REC_TYPE_UNKNOWN = 0,
REC_TYPE_SCALAR = 1 << 0,
Expand Down
10 changes: 10 additions & 0 deletions tests/flow/test_query_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,13 @@ def test13_create_bound_variables(self):
except redis.exceptions.ResponseError:
# Expecting an error.
pass

def test14_treat_path_as_entity(self):
redis_graph.query("CREATE ()-[:R]->()")
try:
query= """MATCH x=()-[]->() RETURN x.name"""
redis_graph.query(query)
assert(False)
except redis.exceptions.ResponseError:
# Expecting an error.
pass

0 comments on commit db0f55c

Please sign in to comment.