Skip to content

Commit e51f7b5

Browse files
authored
Merge pull request DeusData#1394 from jstar0/fix/cypher-repeated-node-unification
fix(cypher): unify repeated variable-length nodes
2 parents a3ae751 + ec29cd5 commit e51f7b5

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎src/cypher/cypher.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,6 +3198,8 @@ static void expand_var_length(cbm_store_t *store, cbm_rel_pattern_t *rel,
31983198
cbm_traverse_result_t tr = {0};
31993199
const char *dir = rel->direction ? rel->direction : "outbound";
32003200
cbm_store_bfs(store, src->id, dir, rel->types, rel->type_count, max_depth, CBM_PERCENT, &tr);
3201+
cbm_node_t *bound_to = binding_get(b, to_var);
3202+
int64_t bound_to_id = bound_to ? bound_to->id : 0;
32013203
/* Same contract as process_edges: the budget caps materialisation, never
32023204
* detection, so a saturated source cannot report match_count == 0 and get a
32033205
* fabricated OPTIONAL "no match" row. */
@@ -3206,6 +3208,9 @@ static void expand_var_length(cbm_store_t *store, cbm_rel_pattern_t *rel,
32063208
if (hop->hop < rel->min_hops) {
32073209
continue;
32083210
}
3211+
if (bound_to && hop->node.id != bound_to_id) {
3212+
continue;
3213+
}
32093214
if (target_node->label && !label_alt_matches(hop->node.label, target_node->label)) {
32103215
continue;
32113216
}

‎tests/test_cypher.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,22 @@ TEST(cypher_exec_variable_length) {
16051605
PASS();
16061606
}
16071607

1608+
TEST(cypher_exec_variable_length_repeated_node_var_unifies) {
1609+
cbm_store_t *s = setup_cypher_store();
1610+
cbm_cypher_result_t r = {0};
1611+
1612+
int rc = cbm_cypher_execute(s,
1613+
"MATCH (f:Function)-[:CALLS*1..2]->(f:Function) "
1614+
"RETURN f.name",
1615+
"test", 0, &r);
1616+
ASSERT_EQ(rc, 0);
1617+
ASSERT_EQ(r.row_count, 0);
1618+
1619+
cbm_cypher_result_free(&r);
1620+
cbm_store_close(s);
1621+
PASS();
1622+
}
1623+
16081624
/* Reproduce-first (#887): an EXPLICIT variable-length upper bound must still be
16091625
* capped at the engine ceiling (cbm_cypher_max_depth(), default 10). On
16101626
* origin/main, expand_var_length honoured an explicit `*1..N` verbatim (only the
@@ -3910,6 +3926,7 @@ SUITE(cypher) {
39103926
RUN_TEST(cypher_exec_limit);
39113927
RUN_TEST(cypher_exec_order_by);
39123928
RUN_TEST(cypher_exec_variable_length);
3929+
RUN_TEST(cypher_exec_variable_length_repeated_node_var_unifies);
39133930
RUN_TEST(cypher_exec_var_length_explicit_bound_capped);
39143931
RUN_TEST(cypher_exec_defines_edge);
39153932
RUN_TEST(cypher_exec_no_results);

0 commit comments

Comments
 (0)