Repository navigation
Description
Follow-up from #1873. That fix takes the right immediate call — reject a read clause written after a write clause, because the parser was silently hoisting it in front of every write and executing a different statement. This is the other half: making the interleaved form actually run.
What is in the way
Update (fluree-db-cypher/src/ast/stmt.rs:109) is two vectors:
pub struct Update {
pub read_clauses: Vec<ReadClause>,
pub write_clauses: Vec<WriteClause>,
pub return_clause: Option<ReturnClause>,
pub span: SourceSpan,
}There is nowhere to record that a clause came after a write, so the parser's loop (parse/stmt.rs:47-120) buckets by keyword and the interleaving is gone by the time the struct exists. Every downstream consumer then assumes reads-then-writes, and most of them are right to, because that is what the type says.
Making MATCH … MERGE … WITH … SET … work means giving Update a real clause sequence — one Vec<Clause> where Clause is read-or-write — and then teaching both lowerings to walk it in order. That is not a small change:
fluree-db-transact/src/lower_cypher_update.rsbuilds a singleTxnfromread_clausesthenwrite_clauses(lower_read_clauses, then the write loop). Ordered clauses mean interleaving where-pattern accumulation with write-template emission, andbound_varsnarrowing would have to move with it rather than happening once.fluree-db-api/src/cypher_seq.rsstages clause-by-clause already, which is the closer fit — butread_prefix_query(:1503) builds the row table fromupdate.read_clausesas a block, up front, anddetect_sequential(:88) gates onread_clausesbeing non-empty. Both assume the split.validate_members(:1338) and thevisible_varswalk (:1436) both iterate the two vectors independently.
Why it is worth doing eventually
MATCH … SET … WITH … SET … and MERGE … WITH … SET … are ordinary openCypher, and Neo4j runs them. A user porting a multi-stage write hits the rejection immediately, and the workaround — split into two statements — gives up atomicity, which is a real cost rather than a cosmetic one.
It would also let MERGE … WITH n SET … work, which is the shape #1873 was filed about and is the natural way to express "upsert this, then derive something from it".
Why it is not in #1886
Two reasons, and the second is the one that decided it. It is a large change to a type every Cypher write path depends on, riding a P2 bug fix. And the rejection has to land first regardless: until the sequence exists, the statements are being silently miscompiled, and one shape commits wrong data while another commits nothing. Rejecting is correct on its own timeline.
Scope note
This is Cypher-only. SPARQL UPDATE's AST is UpdateOperation (fluree-db-sparql/src/ast/update.rs:77), an enum of fixed-shape operations with no read/write bucketing and so no ordering to lose; JSON-LD has no clause-sequence grammar. Verified by grep — read_clauses/write_clauses appear nowhere in fluree-db-sparql/src/.
Activity