Skip to content

Commit

Permalink
fix crash when consume depleted ops (#3194)
Browse files Browse the repository at this point in the history
  • Loading branch information
AviAvni committed Sep 26, 2023
1 parent 1e3b249 commit 3e4f953
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/execution_plan/ops/op_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static Record _handoff
(
OpCreate *op
) {
return array_pop(op->records);
return (array_len(op->records)) ? array_pop(op->records) : NULL;
}

static Record CreateConsume
Expand Down
2 changes: 1 addition & 1 deletion src/execution_plan/ops/op_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static inline void _CollectDeletedEntities(Record r, OpBase *opBase) {
}

static inline Record _handoff(OpDelete *op) {
return array_pop(op->records);
return (array_len(op->records)) ? array_pop(op->records) : NULL;
}

static Record DeleteConsume(OpBase *opBase) {
Expand Down
2 changes: 1 addition & 1 deletion src/execution_plan/ops/op_foreach.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static OpResult ForeachInit
// otherwise, returns NULL (last value in op->records)
static Record _handoff(OpForeach *op) {
ASSERT(op->records != NULL);
return array_pop(op->records);
return (array_len(op->records)) ? array_pop(op->records) : NULL;
}

// the Foreach consume function aggregates all the records from the supplier if
Expand Down
27 changes: 27 additions & 0 deletions tests/flow/test_traversal_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,30 @@ def test_traverse_zero_length_edge(self):
result = graph.query(q).result_set
self.env.assertTrue(result == expected)

def test_consume_depleted_ops(self):
# as op conditional traverse can call consume on its children
# validate that the children not crash

graph.query("CREATE (:A)-[:R]->(:B)")

# test op_create
graph.query("""CREATE (x:X)
WITH *
MATCH (:A)-[r:R]->(b:B)
RETURN x""")

# test op_delete
graph.query("""MATCH (x:X)
DELETE x
WITH *
MATCH (a)-[r:R]->(b:B)
RETURN x""")

graph.query("CREATE (x:X)")

# test op_foreach
graph.query("""MATCH (x:X)
FOREACH(i in range(0, 4) | CREATE (x1:X))
WITH *
MATCH (a)-[r:R]->(b:B)
RETURN x""")

0 comments on commit 3e4f953

Please sign in to comment.