|
29 | 29 | import org.junit.jupiter.api.BeforeEach; |
30 | 30 | import org.junit.jupiter.api.Test; |
31 | 31 |
|
| 32 | +import java.util.ArrayList; |
| 33 | +import java.util.List; |
| 34 | + |
32 | 35 | import static org.assertj.core.api.Assertions.assertThat; |
33 | 36 |
|
34 | 37 |
|
@@ -180,4 +183,62 @@ void vlpPropertyPredicate() { |
180 | 183 | db2.drop(); |
181 | 184 | } |
182 | 185 | } |
| 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 | + } |
183 | 244 | } |
0 commit comments