2020
2121import com .arcadedb .database .Document ;
2222import com .arcadedb .database .MutableDocument ;
23+ import com .arcadedb .database .RID ;
2324import com .arcadedb .exception .TimeoutException ;
2425import com .arcadedb .graph .Edge ;
2526import com .arcadedb .graph .MutableVertex ;
2627import com .arcadedb .graph .Vertex ;
2728import com .arcadedb .query .opencypher .Labels ;
28- import com .arcadedb .query .opencypher .ast .Expression ;
2929import com .arcadedb .query .opencypher .ast .SetClause ;
3030import com .arcadedb .query .opencypher .executor .CypherFunctionFactory ;
3131import com .arcadedb .query .opencypher .executor .ExpressionEvaluator ;
@@ -178,8 +178,9 @@ private void applyPropertySet(final SetClause.SetItem item, final Result result)
178178 mutableDoc .set (item .getProperty (), value );
179179 }
180180 mutableDoc .save ();
181-
182- if (variableToUpdate != null )
181+ propagateUpdateToSameNodeAliases (result , doc , mutableDoc );
182+ // Fallback: ensure the named variable is updated even when doc has no identity yet
183+ if (variableToUpdate != null && doc .getIdentity () == null )
183184 ((ResultInternal ) result ).setProperty (variableToUpdate , mutableDoc );
184185 }
185186
@@ -210,7 +211,9 @@ private void applyReplaceMap(final SetClause.SetItem item, final Result result)
210211 }
211212
212213 mutableDoc .save ();
213- ((ResultInternal ) result ).setProperty (item .getVariable (), mutableDoc );
214+ propagateUpdateToSameNodeAliases (result , doc , mutableDoc );
215+ if (doc .getIdentity () == null )
216+ ((ResultInternal ) result ).setProperty (item .getVariable (), mutableDoc );
214217 }
215218
216219 @ SuppressWarnings ("unchecked" )
@@ -235,7 +238,24 @@ private void applyMergeMap(final SetClause.SetItem item, final Result result) {
235238 }
236239
237240 mutableDoc .save ();
238- ((ResultInternal ) result ).setProperty (item .getVariable (), mutableDoc );
241+ propagateUpdateToSameNodeAliases (result , doc , mutableDoc );
242+ if (doc .getIdentity () == null )
243+ ((ResultInternal ) result ).setProperty (item .getVariable (), mutableDoc );
244+ }
245+
246+ /**
247+ * After mutating a document, update every alias in the result row that points to the same node
248+ * (identified by RID) so all aliases observe the new state within the same query.
249+ */
250+ private void propagateUpdateToSameNodeAliases (final Result result , final Document originalDoc , final Document updatedDoc ) {
251+ final RID originalRid = originalDoc .getIdentity ();
252+ if (originalRid == null )
253+ return ;
254+ for (final String propName : result .getPropertyNames ()) {
255+ final Object prop = result .getProperty (propName );
256+ if (prop instanceof Document other && other != updatedDoc && originalRid .equals (other .getIdentity ()))
257+ ((ResultInternal ) result ).setProperty (propName , updatedDoc );
258+ }
239259 }
240260
241261 private void applyLabels (final SetClause .SetItem item , final Result result ) {
@@ -273,7 +293,7 @@ private void applyLabels(final SetClause.SetItem item, final Result result) {
273293 // Delete old vertex
274294 vertex .delete ();
275295
276- (( ResultInternal ) result ). setProperty ( item . getVariable () , newVertex );
296+ propagateUpdateToSameNodeAliases ( result , vertex , newVertex );
277297 }
278298
279299 private void validatePropertyValue (final Object value ) {
0 commit comments