Conversation
Flatten QueryExpr into a generic node/edge graph with a bottom-up structural hash per node, add a CLI example to lower SQL/PromQL and dump the graph as JSON, and add a self-contained offline HTML viewer (vendored Cytoscape.js + dagre) for manual IR review/debugging and cross-query pattern/shared-subtree inspection. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@milindsrivastava1997 FYI. I haven't checked how it works lol |
Aggregate::by (GroupKeys) was renamed to Aggregate::reduction
(Reduction) on main after this branch forked, breaking dag_export's
exhaustive match. Update the build() arm and the chain_preserves_shape
unit test fixture to match; no behavior change beyond the JSON detail
key ("by" -> "reduction").
Verified: cargo build --workspace, cargo test -p asap-ir (5 dag_export
tests pass), cargo clippy -p asap-ir -p asap-lower --all-targets clean,
and a real cargo run -p asap-lower --example dag_export invocation.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Rebased on current `main` and fixed a compile break: `Aggregate::by` (`GroupKeys`) was renamed to `Aggregate::reduction` (`Reduction`) in #165/#166 after this branch forked, so `dag_export.rs`'s exhaustive match no longer compiled. Updated the `build()` arm and the `chain_preserves_shape_and_child_links` test fixture accordingly (JSON detail key: `"by"` → `"reduction"`). Verified after the fix: `cargo build --workspace`, `cargo test -p asap-ir` (all 5 `dag_export` tests pass), `cargo clippy -p asap-ir -p asap-lower --all-targets` clean, and a real `cargo run -p asap-lower --example dag_export -- --promql "topk(5, rate(http_requests_total[5m]))"` run producing correct JSON. No other gaps found — the rest of the match is exhaustive against the current `QueryExpr`, and the viewer renders `detail` generically so it needed no changes. 🤖 Generated with Claude Code |
…by a stale squash-merge (#177) PR #176's squash-merge (via gh pr merge) used a stale cached PR head on GitHub's side and landed the pre-#134-merge content: the README still had the topk_ir/{:#?} section, and none of #134's actual files (crates/ir/src/dag_export.rs, crates/lower/examples/dag_export.rs, tools/dag-viewer/) made it into main. This restores exactly the tree that was actually reviewed and verified (build/test/clippy clean, dag_export CLI run end-to-end) before the merge: the query-DAG JSON exporter + offline HTML viewer (#134, with the Aggregate::by -> reduction compile fix), and the README's 'Visualize the IR' section pointing at it instead of topk_ir. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
|
Closing as superseded — this content is already on `main` (landed via #177 after #176's squash-merge initially dropped it due to a stale-cache issue on GitHub's merge endpoint; #177 restored it, see that PR for the full story). Verified: `crates/ir/src/dag_export.rs`, `crates/lower/examples/dag_export.rs`, and `tools/dag-viewer/` are all present and building on current `main`, including the `Aggregate::by` → `reduction` fix from this branch. The only remaining diff between this branch and `main` is that `main` additionally has the README pointing at `dag_export`/`tools/dag-viewer` (from #176/#177) — merging this branch as-is would actually remove that doc section, so closing rather than merging. 🤖 Generated with Claude Code |
Summary
Closes #133 (a query DAG visualization for manual code review/debugging, common query pattern analysis, and — later — CSE analysis, in the spirit of Hamna's
bgp-query-dag-explorer).crates/ir/src/dag_export.rs— flattensQueryExprinto a generic node/edge graph (exhaustive match over every variant), with a bottom-up structural hash per node so identical subtrees across queries can be spotted cheaply.crates/lower/examples/dag_export.rs— lowers one or more--sql/--promqlqueries and prints aWorkloadGraphas JSON (cargo run -p asap-lower --example dag_export -- --sql "..." --name q1 > dag.json).tools/dag-viewer/— a self-contained, offline HTML viewer (vendored Cytoscape.js + dagre, MIT-licensed, no CDN) with drag-and-drop JSON loading, per-query tabs, a node-detail inspector, and shared-subtree highlighting.QueryExpralready fully derivedSerialize, so the exporter is a thin flattening layer, not a new data model.serde_jsonmoved from a dev-dependency to a real dependency ofasap-irsince the exporter needs it at runtime.Explicitly out of scope (see doc comments / the viewer's README): the shared-subtree highlighting is a client-side structural-hash proxy, not real CSE —
asap_plan::cse::dedupe_subtrees/CseWorkloadPlanisn't wired into any end-to-end multi-root planning pipeline today (no caller outside its own unit tests). Wiring that up is a separate, larger effort worth its own issue; once it lands, this viewer is a natural place to render itsbindings/Refoutput as real converging DAG edges instead of this proxy.Test plan
cargo test -p asap-ir— newdag_exportunit tests (leaf, chain, n-aryMerge, hash-equality/inequality across identical/differing subtrees) pass; full existing suite still green (41 passed).cargo build/test/clippy --workspaceandcargo fmt --checkall clean.Scannode between two queries is correctly outlined and cross-referenced.🤖 Generated with Claude Code