Skip to content

Commit a99a419

Browse files
committed
fix(cypher): preserve node and edge properties in non-aggregate WITH projections
Refactor execute_with_simple to deep-copy the full node/edge structure rather than projecting them down to flat string names. This prevents bare variables from losing their properties (e.g. file_path, qualified_name) across WITH boundaries. Added cypher_exec_with_node_bare_prop regression unit test. Signed-off-by: Zbyněk Winkler <[email protected]>
1 parent b075f05 commit a99a419

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎src/cypher/cypher.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3642,9 +3642,25 @@ static void execute_with_simple(cbm_return_clause_t *wc, binding_t *bindings, in
36423642
for (int ci = 0; ci < wc->count; ci++) {
36433643
char name_buf[CBM_SZ_256];
36443644
const char *alias = resolve_item_alias(&wc->items[ci], name_buf, sizeof(name_buf));
3645+
cbm_return_item_t *item = &wc->items[ci];
3646+
3647+
if (!item->property && !item->func && !item->kase) {
3648+
const char *pname = item->alias ? item->alias : item->variable;
3649+
cbm_node_t *n = binding_get(&bindings[bi], item->variable);
3650+
if (n) {
3651+
binding_set(&vb, pname, n);
3652+
continue;
3653+
}
3654+
cbm_edge_t *e = binding_get_edge(&bindings[bi], item->variable);
3655+
if (e) {
3656+
binding_set_edge(&vb, pname, e);
3657+
continue;
3658+
}
3659+
}
3660+
36453661
char func_buf[CBM_SZ_512];
36463662
const char *val =
3647-
project_item(&bindings[bi], &wc->items[ci], func_buf, sizeof(func_buf));
3663+
project_item(&bindings[bi], item, func_buf, sizeof(func_buf));
36483664
with_add_vbinding_var(&vb, alias, val);
36493665
}
36503666
vbindings[(*vcount)++] = vb;

‎tests/test_cypher.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,6 +2222,26 @@ TEST(cypher_exec_with_where) {
22222222
PASS();
22232223
}
22242224

2225+
TEST(cypher_exec_with_node_bare_prop) {
2226+
cbm_store_t *s = setup_cypher_store();
2227+
cbm_cypher_result_t r = {0};
2228+
int rc = cbm_cypher_execute(s,
2229+
"MATCH (f:Function) "
2230+
"WHERE f.name = \"HandleOrder\" "
2231+
"WITH f "
2232+
"RETURN f.qualified_name",
2233+
"test", 0, &r);
2234+
ASSERT_EQ(rc, 0);
2235+
ASSERT_EQ(r.row_count, 1);
2236+
/* In the bugged version, this returned "f" because the node was stripped.
2237+
* With our fix, the bare node variable passed through WITH retains its
2238+
* properties, including the actual qualified_name. */
2239+
ASSERT_STR_EQ(r.rows[0][0], "pkg/orders.HandleOrder");
2240+
cbm_cypher_result_free(&r);
2241+
cbm_store_close(s);
2242+
PASS();
2243+
}
2244+
22252245
TEST(cypher_exec_with_orderby_limit) {
22262246
cbm_store_t *s = setup_cypher_store();
22272247
cbm_cypher_result_t r = {0};
@@ -2665,6 +2685,7 @@ SUITE(cypher) {
26652685
RUN_TEST(cypher_exec_with_count);
26662686
RUN_TEST(cypher_exec_with_node_groupvar_prop);
26672687
RUN_TEST(cypher_exec_with_where);
2688+
RUN_TEST(cypher_exec_with_node_bare_prop);
26682689
RUN_TEST(cypher_exec_with_orderby_limit);
26692690
RUN_TEST(cypher_parse_with);
26702691
RUN_TEST(cypher_parse_with_where);

0 commit comments

Comments
 (0)