@@ -2652,6 +2652,28 @@ TEST(cypher_exec_count_star) {
26522652 PASS ();
26532653}
26542654
2655+ /* #1111: type(r) grouped with count(*) must return the actual relationship type,
2656+ * not the row count. ret_agg_build_key/ret_agg_emit_row classified aggregate vs.
2657+ * scalar columns with a bare `item->func` truthy check, so type(r) (a non-aggregate
2658+ * function, func != NULL) was misrouted into the aggregate-value branch and
2659+ * formatted via format_agg_value's default case, silently substituting the row
2660+ * count for the relationship type. */
2661+ TEST (cypher_issue1111_return_type_count_group ) {
2662+ cbm_store_t * s = setup_cypher_store ();
2663+ cbm_cypher_result_t r = {0 };
2664+ int rc = cbm_cypher_execute (
2665+ s , "MATCH (a)-[r]->(b) RETURN type(r) AS t, count(*) AS n ORDER BY n DESC" , "test" , 0 , & r );
2666+ ASSERT_EQ (rc , 0 );
2667+ ASSERT_EQ (r .row_count , 2 );
2668+ ASSERT_STR_EQ (r .rows [0 ][0 ], "CALLS" );
2669+ ASSERT_STR_EQ (r .rows [0 ][1 ], "3" );
2670+ ASSERT_STR_EQ (r .rows [1 ][0 ], "DEFINES" );
2671+ ASSERT_STR_EQ (r .rows [1 ][1 ], "1" );
2672+ cbm_cypher_result_free (& r );
2673+ cbm_store_close (s );
2674+ PASS ();
2675+ }
2676+
26552677TEST (cypher_parse_skip ) {
26562678 cbm_query_t * q = NULL ;
26572679 char * err = NULL ;
@@ -2836,6 +2858,51 @@ TEST(cypher_exec_with_node_groupvar_prop) {
28362858 PASS ();
28372859}
28382860
2861+ /* #1111, WITH variant: the same misrouting in with_agg_build_key/with_agg_accumulate/
2862+ * execute_with_aggregate's per-column func check. */
2863+ TEST (cypher_issue1111_with_type_count_group ) {
2864+ cbm_store_t * s = setup_cypher_store ();
2865+ cbm_cypher_result_t r = {0 };
2866+ int rc = cbm_cypher_execute (
2867+ s ,
2868+ "MATCH (a)-[r]->(b) WITH type(r) AS t, count(*) AS n RETURN t, n ORDER BY n DESC" ,
2869+ "test" , 0 , & r );
2870+ ASSERT_EQ (rc , 0 );
2871+ ASSERT_EQ (r .row_count , 2 );
2872+ ASSERT_STR_EQ (r .rows [0 ][0 ], "CALLS" );
2873+ ASSERT_STR_EQ (r .rows [0 ][1 ], "3" );
2874+ ASSERT_STR_EQ (r .rows [1 ][0 ], "DEFINES" );
2875+ ASSERT_STR_EQ (r .rows [1 ][1 ], "1" );
2876+ cbm_cypher_result_free (& r );
2877+ cbm_store_close (s );
2878+ PASS ();
2879+ }
2880+
2881+ /* #1111 follow-up (review from DeusData on #1221): with_agg_find_or_create's
2882+ * bare-node-carry check only tested `!property && variable`, so an entity-
2883+ * introspection alias like `labels(f) AS l` (variable set, property NULL, func
2884+ * set) was ALSO tagged with the source node's id. A later `l.file_path` then
2885+ * hit node_prop's stub re-fetch heuristic (id set, file_path/label both NULL on
2886+ * the virtual stub) and silently returned HandleOrder's real file_path instead
2887+ * of "" for the non-node alias `l`. */
2888+ TEST (cypher_issue1111_with_scalar_func_alias_no_node_leak ) {
2889+ cbm_store_t * s = setup_cypher_store ();
2890+ cbm_cypher_result_t r = {0 };
2891+ int rc = cbm_cypher_execute (s ,
2892+ "MATCH (f:Function) WHERE f.name = \"HandleOrder\" "
2893+ "WITH labels(f) AS l, COUNT(*) AS c "
2894+ "RETURN l, l.file_path, c" ,
2895+ "test" , 0 , & r );
2896+ ASSERT_EQ (rc , 0 );
2897+ ASSERT_EQ (r .row_count , 1 );
2898+ ASSERT_STR_EQ (r .rows [0 ][0 ], "[\"Function\"]" );
2899+ ASSERT_STR_EQ (r .rows [0 ][1 ], "" ); /* was "handler.go" before the fix */
2900+ ASSERT_STR_EQ (r .rows [0 ][2 ], "1" );
2901+ cbm_cypher_result_free (& r );
2902+ cbm_store_close (s );
2903+ PASS ();
2904+ }
2905+
28392906TEST (cypher_exec_with_where ) {
28402907 cbm_store_t * s = setup_cypher_store ();
28412908 cbm_cypher_result_t r = {0 };
@@ -3533,6 +3600,7 @@ SUITE(cypher) {
35333600 RUN_TEST (cypher_exec_max );
35343601 RUN_TEST (cypher_exec_collect );
35353602 RUN_TEST (cypher_exec_count_star );
3603+ RUN_TEST (cypher_issue1111_return_type_count_group );
35363604 RUN_TEST (cypher_parse_skip );
35373605 RUN_TEST (cypher_parse_sum_avg );
35383606 RUN_TEST (cypher_parse_collect );
@@ -3546,6 +3614,8 @@ SUITE(cypher) {
35463614 /* Phase 6: WITH clause */
35473615 RUN_TEST (cypher_exec_with_rename );
35483616 RUN_TEST (cypher_exec_with_count );
3617+ RUN_TEST (cypher_issue1111_with_type_count_group );
3618+ RUN_TEST (cypher_issue1111_with_scalar_func_alias_no_node_leak );
35493619 RUN_TEST (cypher_exec_with_node_groupvar_prop );
35503620 RUN_TEST (cypher_exec_with_where );
35513621 RUN_TEST (cypher_exec_with_orderby_limit );
0 commit comments