@@ -599,32 +599,35 @@ private AbstractExecutionStep buildExecutionStepsWithOrder(final CommandContext
599599 if (typeCountStep != null )
600600 return typeCountStep ;
601601
602- // Special case: RETURN without MATCH (standalone expressions)
603- // E.g., RETURN abs(-42), RETURN 1+1
604- if (statement .getMatchClauses ().isEmpty () && statement .getReturnClause () != null &&
605- clausesInOrder .stream ().noneMatch (c -> c .getType () == ClauseEntry .ClauseType .UNWIND )) {
606- // Create a dummy row to evaluate expressions against
607- final ResultInternal dummyRow = new ResultInternal ();
608- final List <Result > singleRow = List .of (dummyRow );
609-
610- // Return the single row via an initial step
611- currentStep = new AbstractExecutionStep (context ) {
612- private boolean consumed = false ;
613-
614- @ Override
615- public ResultSet syncPull (final CommandContext ctx , final int nRecords ) {
616- if (consumed ) {
617- return new IteratorResultSet (List .<ResultInternal >of ().iterator ());
602+ // Special case: Standalone WITH, UNWIND, or RETURN
603+ if (!clausesInOrder .isEmpty ()) {
604+ final ClauseEntry .ClauseType firstClauseType = clausesInOrder .get (0 ).getType ();
605+ if (firstClauseType == ClauseEntry .ClauseType .WITH ||
606+ firstClauseType == ClauseEntry .ClauseType .UNWIND ||
607+ (firstClauseType == ClauseEntry .ClauseType .RETURN && statement .getMatchClauses ().isEmpty ())) {
608+ // Create a dummy row to evaluate expressions against
609+ final ResultInternal dummyRow = new ResultInternal ();
610+ final List <Result > singleRow = List .of (dummyRow );
611+
612+ // Return the single row via an initial step
613+ currentStep = new AbstractExecutionStep (context ) {
614+ private boolean consumed = false ;
615+
616+ @ Override
617+ public ResultSet syncPull (final CommandContext ctx , final int nRecords ) {
618+ if (consumed ) {
619+ return new IteratorResultSet (List .<ResultInternal >of ().iterator ());
620+ }
621+ consumed = true ;
622+ return new IteratorResultSet (singleRow .iterator ());
618623 }
619- consumed = true ;
620- return new IteratorResultSet (singleRow .iterator ());
621- }
622624
623- @ Override
624- public String prettyPrint (final int depth , final int indent ) {
625- return " " .repeat (Math .max (0 , depth * indent )) + "+ DUMMY ROW (for standalone expressions)" ;
626- }
627- };
625+ @ Override
626+ public String prettyPrint (final int depth , final int indent ) {
627+ return " " .repeat (Math .max (0 , depth * indent )) + "+ DUMMY ROW (for standalone expressions)" ;
628+ }
629+ };
630+ }
628631 }
629632
630633 // Process clauses in order
0 commit comments