Skip to content

Commit 5b18529

Browse files
robfranktae898
authored andcommitted
ArcadeData#3997 test(cypher): regression tests for collect(r)+VLP row-drop bug (ArcadeData#4010)
1 parent cc18099 commit 5b18529

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

engine/src/test/java/com/arcadedb/query/opencypher/OpenCypherVariableLengthPathTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import org.junit.jupiter.api.BeforeEach;
3030
import org.junit.jupiter.api.Test;
3131

32+
import java.util.ArrayList;
33+
import java.util.List;
34+
3235
import static org.assertj.core.api.Assertions.assertThat;
3336

3437

@@ -180,4 +183,62 @@ void vlpPropertyPredicate() {
180183
db2.drop();
181184
}
182185
}
186+
187+
@Test
188+
void collectRelThenVlpReturnsRows() {
189+
// Issue #3997: collect(r) carried via WITH drops all rows when a later MATCH uses VLP
190+
final List<Result> rows = new ArrayList<>();
191+
try (final ResultSet rs = database.query("opencypher",
192+
"""
193+
MATCH (a:Person {name: 'Alice'})-[r:KNOWS]->(b:Person)
194+
WITH a, collect(r) AS rels
195+
MATCH path = (a)-[:KNOWS*1..2]->(c:Person)
196+
RETURN length(path) AS len, size(rels) AS relationCount
197+
ORDER BY len""")) {
198+
rs.forEachRemaining(rows::add);
199+
}
200+
201+
assertThat(rows).as("collect(r) + VLP should return 2 rows (len=1 and len=2)").hasSize(2);
202+
assertThat(rows.get(0).<Long>getProperty("len")).isEqualTo(1L);
203+
assertThat(rows.get(0).<Long>getProperty("relationCount")).isEqualTo(1L);
204+
assertThat(rows.get(1).<Long>getProperty("len")).isEqualTo(2L);
205+
assertThat(rows.get(1).<Long>getProperty("relationCount")).isEqualTo(1L);
206+
}
207+
208+
@Test
209+
void collectDistinctRelThenVlpReturnsRows() {
210+
// Issue #3997: collect(DISTINCT r) carried via WITH also drops all rows
211+
final List<Result> rows = new ArrayList<>();
212+
try (final ResultSet rs = database.query("opencypher",
213+
"""
214+
MATCH (a:Person {name: 'Alice'})
215+
OPTIONAL MATCH (a)-[r:KNOWS]->(b:Person)
216+
WITH a, collect(DISTINCT r) AS rels
217+
MATCH path = (a)-[:KNOWS*1..2]->(c:Person)
218+
RETURN length(path) AS len, size(rels) AS relationCount
219+
ORDER BY len""")) {
220+
rs.forEachRemaining(rows::add);
221+
}
222+
223+
assertThat(rows).as("collect(DISTINCT r) + VLP should return 2 rows").hasSize(2);
224+
assertThat(rows.get(0).<Long>getProperty("len")).isEqualTo(1L);
225+
assertThat(rows.get(1).<Long>getProperty("len")).isEqualTo(2L);
226+
}
227+
228+
@Test
229+
void collectScalarThenVlpReturnsRows() {
230+
// Issue #3997 control case: collect(type(r)) should work (and does)
231+
final List<Result> rows = new ArrayList<>();
232+
try (final ResultSet rs = database.query("opencypher",
233+
"""
234+
MATCH (a:Person {name: 'Alice'})-[r:KNOWS]->(b:Person)
235+
WITH a, collect(type(r)) AS relTypes
236+
MATCH path = (a)-[:KNOWS*1..2]->(c:Person)
237+
RETURN length(path) AS len, relTypes
238+
ORDER BY len""")) {
239+
rs.forEachRemaining(rows::add);
240+
}
241+
242+
assertThat(rows).as("collect(type(r)) + VLP control case should also return 2 rows").hasSize(2);
243+
}
183244
}

0 commit comments

Comments
 (0)