Skip to content

feat(core): port cli/commands_monitor.py stats queries#23

Merged
joy-software merged 1 commit into
developfrom
feature/duckdb-cli-stats
Jun 2, 2026
Merged

feat(core): port cli/commands_monitor.py stats queries#23
joy-software merged 1 commit into
developfrom
feature/duckdb-cli-stats

Conversation

@joy-software
Copy link
Copy Markdown
Contributor

Summary

Seventh PR in the Kuzu → DuckDB migration. `cgh stats` (table + JSON) and `cgh status` use backend-neutral helpers.

What lands

File What changed
`core/protocol.py` / `db_kuzu.py` / `db_duckdb.py` New helper: `count_edges(edge_type)` mirroring `count_nodes`
`cli/commands_monitor.py` Per-label `MATCH (n:Label) RETURN count(n)` → `conn.count_nodes(label)`; per-edge-type `MATCH ()-[r:EDGE]->() RETURN count(r)` → `conn.count_edges(edge_type)`. `_rows` import gone.

The remaining `.execute()` calls in `commands_monitor.py` are against the SQLite FTS database (`fts_conn`) or the SQLite call_log database — neither is part of the graph backend swap.

Verification

Identical `cgh stats --json` output on both backends after a fresh index:

```json
{"graph": {
"nodes": {"File":5,"Function":2,"Class":2,...},
"edges": {"IMPORTS":2,"DEFINES_FN":2,"CALLS":1,"INHERITS":1,...}
}}
```

Tests

298 / 298 pass, lint clean. No new tests added — the existing 40-test parity sweep already covers `count_nodes` and the new `count_edges` is structurally identical.

What's left

Seventh step of the Kuzu -> DuckDB migration. cgh stats (table form
and --json) now uses backend-neutral helpers. Both backends produce
identical node + edge counts.

What lands:

- codegraph/core/protocol.py + db_kuzu.py + db_duckdb.py: one new
  helper, count_edges(edge_type). Kuzu uses
  `MATCH ()-[r:EDGE]->() RETURN count(r)`; DuckDB uses
  `SELECT count(*) FROM edge_<rel>`. Mirrors the existing count_nodes
  helper.

- codegraph/cli/commands_monitor.py:
  - _stats_content: the per-label MATCH count() calls become
    conn.count_nodes() calls; the per-edge-type MATCH ()-[]->()
    counts become conn.count_edges() calls. Same exception swallow
    behavior preserved (count_nodes / count_edges raise ValueError
    for unknown labels / edge types, caught and skipped).
  - _stats_json: same refactor — single helper call per label and
    edge type instead of building Cypher strings.
  - cmd_status: the File + Endpoint count queries used as the RO
    fallback path now call conn.count_nodes().
  - Drops the unused _rows import.

Verification — identical output on both backends:

  $ cgh stats --json --root /tmp/repo
  {"graph": {"nodes": {"File":5,"Function":2,...},
             "edges": {"IMPORTS":2,"DEFINES_FN":2,"CALLS":1,...}}}

  $ CGH_DB=duckdb cgh stats --json --root /tmp/repo
  {"graph": {"nodes": {"File":5,"Function":2,...},
             "edges": {"IMPORTS":2,"DEFINES_FN":2,"CALLS":1,...}}}

The remaining .execute() calls in commands_monitor.py are against
either the SQLite FTS db (fts_conn) or the SQLite call_log db —
neither is part of the graph backend swap.

What's left for the migration:

- federation.py (kuzu-direct child DB opens — task #11, the last one)
@joy-software joy-software merged commit 6813940 into develop Jun 2, 2026
1 check passed
@joy-software joy-software deleted the feature/duckdb-cli-stats branch June 2, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant