fix(rvlite): CypherEngine MATCH returns all matched rows with properties#270
Open
dmoellenbeck wants to merge 1 commit intoruvnet:mainfrom
Open
fix(rvlite): CypherEngine MATCH returns all matched rows with properties#270dmoellenbeck wants to merge 1 commit intoruvnet:mainfrom
dmoellenbeck wants to merge 1 commit intoruvnet:mainfrom
Conversation
Previously, execute_match() merged all matched node contexts into a
single ExecutionContext via context.bind(). Each call to bind() overwrote
the variable, so only the last matched node survived into RETURN.
This meant any MATCH query returned at most 1 row with empty properties.
Changes in executor.rs:
- execute_match() now returns Vec<ExecutionContext> (one per matched row)
- execute_return() iterates all contexts to produce multiple result rows
- Column names use expression text ("p.name") instead of "?column?"
- Added ContextValue::to_json_value() for proper WASM serialization
- Added value_to_json() helper covering all Value variants incl List/Map
Changes in mod.rs (WASM binding):
- Serializes via serde_json + js_sys::JSON::parse instead of
serde_wasm_bindgen::to_value which failed on ContextValue enums
Tests added (cypher_integration_test.rs):
- test_match_return_multiple_rows
- test_match_where_return_multiple_rows
- test_match_return_variable_node
All 24 existing cypher unit tests pass.
Fixes ruvnet#269
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
Fixes #269 —
CypherEngine.execute()now correctly returns multiple rows fromMATCH ... RETURNqueries, with all node properties properly serialized to JavaScript.Problem
Any
MATCH (n:Label) RETURN n.propquery returned at most 1 row with empty properties{}, regardless of how many nodes matched:Root Cause
Two separate bugs in the Cypher executor:
Context merge in
execute_match()(executor.rs): All matched node contexts were merged into a singleExecutionContextviacontext.bind(). Each call overwrote the previous binding, so only the last matched node survived into the RETURN phase.WASM serialization in
CypherEngine::execute()(mod.rs):serde_wasm_bindgen::to_value()silently droppedContextValueenum variants during serialization to JavaScript, producing empty{}objects.Solution
executor.rs
execute_match()returnsVec<ExecutionContext>— one context per matched row, instead of merging into oneexecute_return()iterates all contexts, producing one result row per matchexpression_to_column_name()— generates readable column names ("p.name") instead of"?column?"ContextValue::to_json_value()andvalue_to_json()— flattensContextValueenums to plainserde_json::Valuefor reliable serializationmod.rs
CypherEngine::execute()now serializes viaserde_json::to_string()+js_sys::JSON::parse()instead ofserde_wasm_bindgen::to_value(), avoiding the silent enum serialization failureTesting
cargo test -p rvlite -- cypher)tests/cypher_integration_test.rs:test_match_return_multiple_rows— Creates 3 nodes, verifies 3 rows with correct column namestest_match_where_return_multiple_rows— WHERE filter returns subset of nodestest_match_return_variable_node—RETURN nreturns full node objects with propertieswasm-pack buildon macOS Apple Siliconrvlite_cyphertool)Breaking Changes
None. The fix only changes what was previously incorrect behavior (empty results). Existing queries that returned 0-1 rows will now correctly return all matching rows.
Related
ruvector-graph-node(NAPI bindings), but the fix was not applied to the WASMrvlitecrategraph_store.rscorrectly stores and retrieves node properties — the storage layer was not affectedAdditional Note for MCP Server
The
rvlite_cypherhandler inbin/mcp-server.jscurrently usesrequire('rvlite')(CJS), but rvlite v0.2.x is ESM-only — the CJS entry point exports an empty object. This means the MCP tool always falls through to "rvlite package not installed". A separate fix is needed to switch the handler toawait import('rvlite/wasm')with WASM init. Happy to open a follow-up issue/PR for this if helpful.