feat(core): port cli/commands_monitor.py stats queries#23
Merged
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Seventh PR in the Kuzu → DuckDB migration. `cgh stats` (table + JSON) and `cgh status` use backend-neutral helpers.
What lands
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