Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash when consume depleted ops #3194

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to place a NULL as a marker
so you pop the last element which is NULL and we're done

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that op_cond_traverse can call to this consume after it get the marker null and we can't do anything to change it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why the operation continues on asking for more data after it received 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""")
Loading