Skip to content

Commit

Permalink
fix optional consume (FalkorDB#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
AviAvni authored Aug 1, 2024
1 parent 5ee6a19 commit 6935065
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/execution_plan/ops/op_optional.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ OpBase *NewOptionalOp(const ExecutionPlan *plan) {
return (OpBase *)op;
}

static Record _DepleteConsume(OpBase *opBase) {
return NULL;
}

static Record OptionalConsume(OpBase *opBase) {
Optional *op = (Optional *)opBase;
// try to produce a Record from the child op.
Expand All @@ -31,6 +35,7 @@ static Record OptionalConsume(OpBase *opBase) {
// and this op has not yet returned data.
if(!r && !op->emitted_record) {
r = OpBase_CreateRecord(opBase);
OpBase_UpdateConsume(opBase, _DepleteConsume);
}

// don't produce multiple empty Records.
Expand All @@ -42,6 +47,7 @@ static Record OptionalConsume(OpBase *opBase) {
static OpResult OptionalReset(OpBase *opBase) {
Optional *op = (Optional *)opBase;
op->emitted_record = false;
OpBase_UpdateConsume(opBase, OptionalConsume);
return OP_OK;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/flow/test_optional_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,11 @@ def test23_optional_after_apply(self):
query = """WITH [0, 0] AS n0 OPTIONAL MATCH () MERGE ()"""
actual_result = self.graph.query(query)
self.env.assertEquals(actual_result.nodes_created, 1)

def test24_optional_and_cartesian_product(self):
self.graph.delete()
self.graph.query("CREATE ()<-[:A]-()")
query = """OPTIONAL MATCH (), ({x:0, x:1}) RETURN 0"""
actual_result = self.graph.query(query)
expected_result = [[0]]
self.env.assertEquals(actual_result.result_set, expected_result)

0 comments on commit 6935065

Please sign in to comment.