MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / eval_condition

Function eval_condition

src/cypher/cypher.c:2623–2700  ·  view source on GitHub ↗

Evaluate a WHERE condition against a binding */

Source from the content-addressed store, hash-verified

2621
2622/* Evaluate a WHERE condition against a binding */
2623static bool eval_condition(const cbm_condition_t *c, binding_t *b) {
2624 /* Label test: WHERE n:Label (#241) — compare the bound node's label
2625 * directly rather than a property value. */
2626 if (strcmp(c->op, "HAS_LABEL") == 0) {
2627 cbm_node_t *n = binding_get(b, c->variable);
2628 bool result = n && n->label && c->value && strcmp(n->label, c->value) == 0;
2629 return c->negated ? !result : result;
2630 }
2631
2632 /* EXISTS { (var)-[:TYPE]->() }: does the bound node have any edge of the
2633 * given type in the requested direction? (dir 0=out, 1=in, 2=any) */
2634 if (strcmp(c->op, "EXISTS") == 0) {
2635 cbm_node_t *n = binding_get(b, c->variable);
2636 bool result = false;
2637 if (n && b->store) {
2638 cbm_edge_t *edges = NULL;
2639 int cnt = 0;
2640 if (c->exists_dir != 1) { /* outbound or any */
2641 if (c->value) {
2642 cbm_store_find_edges_by_source_type(b->store, n->id, c->value, &edges, &cnt);
2643 } else {
2644 cbm_store_find_edges_by_source(b->store, n->id, &edges, &cnt);
2645 }
2646 result = cnt > 0;
2647 cbm_store_free_edges(edges, cnt);
2648 }
2649 if (!result && c->exists_dir != 0) { /* inbound or any */
2650 edges = NULL;
2651 cnt = 0;
2652 if (c->value) {
2653 cbm_store_find_edges_by_target_type(b->store, n->id, c->value, &edges, &cnt);
2654 } else {
2655 cbm_store_find_edges_by_target(b->store, n->id, &edges, &cnt);
2656 }
2657 result = cnt > 0;
2658 cbm_store_free_edges(edges, cnt);
2659 }
2660 }
2661 return c->negated ? !result : result;
2662 }
2663
2664 const char *actual = resolve_condition_value(c, b);
2665 /* coalesce(var.prop, literal) (#874): a missing/empty property value
2666 * falls back to the literal default before the operator runs. */
2667 if (c->coalesce_default && (!actual || actual[0] == '\0')) {
2668 actual = c->coalesce_default;
2669 }
2670 if (!actual) {
2671 return true;
2672 }
2673
2674 bool result;
2675
2676 /* IS NULL / IS NOT NULL */
2677 if (strcmp(c->op, "IS NULL") == 0) {
2678 result = (actual[0] == '\0');
2679 return c->negated ? !result : result;
2680 }

Callers 2

eval_exprFunction · 0.85
eval_whereFunction · 0.85

Calls 8

binding_getFunction · 0.85
cbm_store_free_edgesFunction · 0.85
resolve_condition_valueFunction · 0.85
eval_comparison_opFunction · 0.85

Tested by

no test coverage detected