Skip to content

Commit

Permalink
added params support for indexed array lookup (RedisGraph#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
DvirDukhan committed Jun 23, 2020
1 parent f6ab51b commit da3a000
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/execution_plan/optimizations/utilize_indices.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ static bool _validateInExpression(AR_ExpNode *exp) {
assert(exp->op.child_count == 2);

AR_ExpNode *list = exp->op.children[1];
// In case the array is a parameter such as "WHERE x IN $arr", evaluate the parameter for in-place replacement.
if(AR_EXP_IsParameter(list)) AR_EXP_Evaluate(list, NULL);
if(list->operand.type != AR_EXP_CONSTANT || list->operand.constant.type != T_ARRAY) return false;

SIValue listValue = list->operand.constant;
Expand Down
10 changes: 10 additions & 0 deletions tests/flow/test_index_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,13 @@ def test09_index_scan_with_params(self):
expected_result = ["Lucy Yanfital"]
self.env.assertEquals(query_result.result_set[0], expected_result)

def test10_index_scan_with_param_array(self):
query = "MATCH (p:person) WHERE p.age in $ages RETURN p.name"
params = {'ages':[30]}
query = redis_graph.build_params_header(params) + query
plan = redis_graph.execution_plan(query)
self.env.assertIn('Index Scan', plan)
query_result = redis_graph.query(query)
expected_result = ["Lucy Yanfital"]
self.env.assertEquals(query_result.result_set[0], expected_result)

0 comments on commit da3a000

Please sign in to comment.