Skip to content

Commit ec29cd5

Browse files
committed
fix(cypher): unify repeated variable-length nodes
Signed-off-by: King Star <mcxin.y@gmail.com>
1 parent d6be58e commit ec29cd5

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
@@ -3151,6 +3151,8 @@ static void expand_var_length(cbm_store_t *store, cbm_rel_pattern_t *rel,
31513151
cbm_traverse_result_t tr = {0};
31523152
const char *dir = rel->direction ? rel->direction : "outbound";
31533153
cbm_store_bfs(store, src->id, dir, rel->types, rel->type_count, max_depth, CBM_PERCENT, &tr);
3154+
cbm_node_t *bound_to = binding_get(b, to_var);
3155+
int64_t bound_to_id = bound_to ? bound_to->id : 0;
31543156
/* Same contract as process_edges: the budget caps materialisation, never
31553157
* detection, so a saturated source cannot report match_count == 0 and get a
31563158
* fabricated OPTIONAL "no match" row. */
@@ -3159,6 +3161,9 @@ static void expand_var_length(cbm_store_t *store, cbm_rel_pattern_t *rel,
31593161
if (hop->hop < rel->min_hops) {
31603162
continue;
31613163
}
3164+
if (bound_to && hop->node.id != bound_to_id) {
3165+
continue;
3166+
}
31623167
if (target_node->label && !label_alt_matches(hop->node.label, target_node->label)) {
31633168
continue;
31643169
}

‎tests/test_cypher.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,22 @@ TEST(cypher_exec_variable_length) {
13711371
PASS();
13721372
}
13731373

1374+
TEST(cypher_exec_variable_length_repeated_node_var_unifies) {
1375+
cbm_store_t *s = setup_cypher_store();
1376+
cbm_cypher_result_t r = {0};
1377+
1378+
int rc = cbm_cypher_execute(s,
1379+
"MATCH (f:Function)-[:CALLS*1..2]->(f:Function) "
1380+
"RETURN f.name",
1381+
"test", 0, &r);
1382+
ASSERT_EQ(rc, 0);
1383+
ASSERT_EQ(r.row_count, 0);
1384+
1385+
cbm_cypher_result_free(&r);
1386+
cbm_store_close(s);
1387+
PASS();
1388+
}
1389+
13741390
/* Reproduce-first (#887): an EXPLICIT variable-length upper bound must still be
13751391
* capped at the engine ceiling (cbm_cypher_max_depth(), default 10). On
13761392
* origin/main, expand_var_length honoured an explicit `*1..N` verbatim (only the
@@ -3612,6 +3628,7 @@ SUITE(cypher) {
36123628
RUN_TEST(cypher_exec_limit);
36133629
RUN_TEST(cypher_exec_order_by);
36143630
RUN_TEST(cypher_exec_variable_length);
3631+
RUN_TEST(cypher_exec_variable_length_repeated_node_var_unifies);
36153632
RUN_TEST(cypher_exec_var_length_explicit_bound_capped);
36163633
RUN_TEST(cypher_exec_defines_edge);
36173634
RUN_TEST(cypher_exec_no_results);

0 commit comments

Comments
 (0)