Repository navigation
feat(export): export the subgraph a cypher query selects - #203
Merged
Merged
Conversation
`CypherEngine.export_subgraph(query, params, ...)` (`exportSubgraph` in TypeScript) runs a Cypher query whose first two columns are the source and target node keys, one row per edge, and builds the same dense CSR arrays as `export_graph`, by the same edge rules: repeated edges combined by `combine_edges`, undirected pairs merged, self-loops once, null endpoints skipped and null weights dropped and counted. Options are those of `export_graph` without `rel_types`; `weight` names a column of the result, and `default_weight` alone weights every row, so 1.0 counts the rows behind each edge. The nodes are the keys present in the result. When both key columns are a labeled node's key (`RETURN a.id, b.id` with `(a:Person)` and `id` its key), ids are grouped per label as in `export_graph`, so equal keys in two labels stay apart and `write_node_column` can write results back. Otherwise all keys share one id space, `label_ranges` is empty, and `write_node_column` refuses the export with an error. Both exports now share one edge builder: mapping endpoints to dense ids, the packed-key or (key, weight) vectors, the sort and the in-edge transpose. The Node binding shares its conversion of the result too. Closes #202
Deploying lance-csr with
|
| Latest commit: |
de5e103
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://05342a6e.lance-csr.pages.dev |
| Branch Preview URL: | https://feat-export-edges.lance-csr.pages.dev |
prrao87
marked this pull request as ready for review
November 25, 2026 01:29
The Node crate has its own manifest, outside the workspace, so `cargo fmt --all` and workspace clippy don't cover it; CI's rust-lint job checks it separately.
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.
Why
Closes #202.
export_graphexports whole relationship types, but many graph-algorithm pipelines run on part of the graph: select edges with a query, run PageRank on just those, then filter by score. Until now the query result had to be turned into CSR by hand (key-to-id mapping, symmetrising, deduplication, weights), repeating the rulesexport_graphalready implements, and more slowly.What changed
CypherEngine.export_subgraph(exportSubgraphin TypeScript) runs a Cypher query that returns one row per edge, with the source and target node keys as its first two columns, and returns the sameGraphExportasexport_graph:export_graph: repeated edges combined bycombine_edges, undirecteda -> bandb -> amerged, self-loops once, null endpoints skipped, null weights dropped and counted. The options areexport_graph's withoutrel_types;weightnames a column of the result, anddefault_weighton its own weights every row.a.idwith(a:Person)andidits key), ids are grouped per label as inexport_graph, so equal keys in two labels stay apart,label_rangesis filled, andwrite_node_columncan write results back (nodes outside the subgraph get null). Otherwise (a computed column, an unlabeled node, a WITH or UNION in between) all keys share one id space,label_rangesis empty, andwrite_node_columnrefuses the export with an error.export_graphandexport_subgraphshare the code that maps endpoints to dense ids, collects packed keys or(key, weight)pairs, sorts and transposes. The Node binding shares its result conversion too.Validation
cargo test --workspace,cargo clippy --workspace --all-targets -- -D warnings,cargo fmt --check: pass. New Rust tests cover filters, weights from a result column, row counting, the unlabeled fallback, colliding keys across two labels, and the error cases.make testexport tests (including write-back from a labeled subgraph to a Lance node table) andmake lint: pass.npm test(90) andnpm run lint: pass.docs/check_snippets.py,zensical build --strict,typos: pass.Tested on the SNAP Twitter graph (ego-Twitter, download: https://snap.stanford.edu/data/twitter_combined.txt.gz, 81,306 nodes and 2,420,766 edge rows), in a filter → PageRank → filter pipeline with undirected PageRank weighted by row count. The benchmark script isn't part of this PR.
The seed step selects every edge touching a node at or above a degree cutoff. Replacing "run the query, then build the CSR in numpy" with one
export_subgraphcall gave identical arrays, weights, PageRank scores and final node sets (asserted before timing), and these warm medians (5 runs after 2 warm-ups, variants alternated run by run, release build, Apple Silicon, load 5 to 6 with other work running):export_subgraphThe final filter also got cheaper (0.010 → 0.002 s at p90), because it reads the undirected CSR's rows instead of rescanning the edge rows. PageRank time is unchanged. Peak memory isn't compared: both variants ran in one process.
🤖 Generated with Claude Code