-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
WithAcceptanceTest.scala
260 lines (216 loc) · 7.74 KB
/
WithAcceptanceTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.internal.cypher.acceptance
import org.neo4j.cypher.{ExecutionEngineFunSuite, NewPlannerTestSupport}
class WithAcceptanceTest extends ExecutionEngineFunSuite with NewPlannerTestSupport {
// TCK'd
test("only passing on pattern nodes work") {
val a = createNode()
val b = createNode()
relate(a, b)
val result = executeWithAllPlannersAndRuntimesAndCompatibilityMode(
"MATCH (a) WITH a MATCH (a)-->(b) RETURN *"
)
result.toList should equal(List(Map("a" -> a, "b" -> b)))
}
// TCK'd
test("order by and limit can be used") {
val a = createNode("A")
createNode("B")
createNode("C")
relate(a,createNode())
val result = executeWithAllPlannersAndCompatibilityMode(
"MATCH (a) WITH a ORDER BY a.name LIMIT 1 MATCH (a)-->(b) RETURN a"
)
result.toList should equal(List(Map("a" -> a)))
}
// TCK'd
test("without dependencies between the query parts works") {
val a = createNode()
val b = createNode()
val result = executeWithAllPlannersAndRuntimesAndCompatibilityMode(
"MATCH (a) WITH a MATCH (b) RETURN *"
)
result.toSet should equal(Set(
Map("a" -> a, "b" -> b),
Map("a" -> b, "b" -> a),
Map("a" -> a, "b" -> a),
Map("a" -> b, "b" -> b)
))
}
// TCK'd
test("with aliasing") {
createLabeledNode(Map("prop"->42), "Start")
val b = createLabeledNode(Map("prop"->42), "End")
createLabeledNode(Map("prop"->3), "End")
val result = executeWithAllPlannersAndCompatibilityMode(
"MATCH (a:Start) WITH a.prop AS property MATCH (b:End) WHERE property = b.prop RETURN b"
)
result.toSet should equal(Set(Map("b" -> b)))
}
// TCK'd
test("should handle dependencies across WITH") {
val b = createLabeledNode(Map("prop" -> 42), "End")
createLabeledNode(Map("prop" -> 3), "End")
createLabeledNode(Map("prop" -> b.getId), "Start")
val result = executeWithAllPlannersAndCompatibilityMode(
"MATCH (a:Start) WITH a.prop AS property LIMIT 1 MATCH (b) WHERE id(b) = property RETURN b"
)
result.toSet should equal(Set(Map("b" -> b)))
}
// TCK'd
test("should handle dependencies across WITH with SKIP") {
val a = createNode("prop" -> "A", "id" -> 0)
createNode("prop" -> "B", "id" -> a.getId)
createNode("prop" -> "C", "id" -> 0)
val result = executeWithAllPlannersAndCompatibilityMode(
"""MATCH (a)
|WITH a.prop AS property, a.id as idToUse
|ORDER BY property
|SKIP 1
|MATCH (b)
|WHERE id(b) = idToUse
|RETURN b""".stripMargin
)
result.toSet should equal(Set(Map("b" -> a)))
}
// TCK'd
test("WHERE after WITH filters as expected") {
createNode("A")
val b = createNode("B")
createNode("C")
val result = executeWithAllPlannersAndCompatibilityMode(
"MATCH (a) WITH a WHERE a.name = 'B' RETURN a"
)
result.toSet should equal(Set(Map("a" -> b)))
}
// TCK'd
test("WHERE after WITH can filter on top of aggregation") {
val a = createNode("A")
val b = createNode("B")
relate(a, createNode())
relate(a, createNode())
relate(a, createNode())
relate(b, createNode())
val result = executeWithAllPlannersAndCompatibilityMode(
"MATCH (a)-->() WITH a, count(*) as relCount WHERE relCount > 1 RETURN a"
)
result.toSet should equal(Set(Map("a" -> a)))
}
// TCK'd
test("Can ORDER BY an aggregating key") {
createNode("bar" -> "A")
createNode("bar" -> "A")
createNode("bar" -> "B")
val result = executeWithAllPlannersAndCompatibilityMode(
"MATCH (a) WITH a.bar as bars, count(*) as relCount ORDER BY a.bar RETURN *"
)
result should not be empty
}
// TCK'd except for the "not using Projection" part
test("Can ORDER BY a DISTINCT column") {
createNode("bar" -> "A")
createNode("bar" -> "A")
createNode("bar" -> "B")
val result = executeWithAllPlannersAndCompatibilityMode(
"MATCH (a) WITH DISTINCT a.bar as bars ORDER BY a.bar RETURN *"
)
result should not be empty
result should not(use("Projection"))
}
// TCK'd
test("Can use WHERE on distinct columns") {
createNode("bar" -> "A")
createNode("bar" -> "A")
createNode("bar" -> "B")
val result = executeWithAllPlannersAndCompatibilityMode(
"MATCH (a) WITH DISTINCT a.bar as bars WHERE a.bar = 'B' RETURN *"
)
result should not be empty
}
// TCK'd
test("Can solve a simple pattern with the relationship and one endpoint bound") {
val node1 = createNode()
val node2 = createNode()
val rel = relate(node1, node2)
val result = executeWithAllPlannersAndCompatibilityMode(
"WITH {a} AS b, {b} AS tmp, {r} AS r WITH b AS a, r LIMIT 1 MATCH (a)-[r]->(b) RETURN a, r, b",
"a" -> node1, "b" -> node2, "r" -> rel
)
result.toList should equal(List(
Map("a" -> node1, "b" -> node2, "r" -> rel)
))
}
// TCK'd
test("nulls passing through WITH") {
executeWithAllPlannersAndCompatibilityMode("optional match (a:Start) with a match (a)-->(b) return *") should be (empty)
}
// TCK'd
test("WITH {foo: {bar: 'baz'}} AS nestedMap RETURN nestedMap.foo.bar") {
val result = executeWithAllPlannersAndCompatibilityMode(
"WITH {foo: {bar: 'baz'}} AS nestedMap RETURN nestedMap.foo.bar"
)
result.toSet should equal(Set(Map("nestedMap.foo.bar" -> "baz")))
}
// TCK'd
test("connected components after WITH") {
val n = createLabeledNode("A")
val m = createLabeledNode("B")
val x = createNode()
relate(n, x)
val result = executeWithAllPlannersAndCompatibilityMode("MATCH (n:A) WITH n LIMIT 1 MATCH (m:B), (n)-->(x) RETURN *")
result.toList should equal(List(Map("m" -> m, "n" -> n, "x" -> x)))
}
// TCK'd
test("WITH with predicate and aggregation should be handled by all planners") {
// GIVEN
createNode(Map("prop" -> 43))
createNode(Map("prop" -> 42))
// WHEN
val query = "MATCH (n) WITH n WHERE n.prop = 42 RETURN count(*)"
val result = executeScalarWithAllPlannersAndCompatibilityMode[Long](query)
// THEN
result should equal(1)
}
// TCK'd
test("multiple WITHs with predicates and aggregation should be handled by all planners") {
// GIVEN
val david = createNode("name" -> "David")
val other = createNode("name" -> "Other")
val notOther = createNode("name" -> "NotOther")
val notOther2 = createNode("name" -> "NotOther2")
relate(david, other)
relate(david, notOther)
relate(david, notOther2)
relate(other, createNode())
relate(other, createNode())
relate(notOther, createNode())
relate(notOther, createNode())
relate(notOther2, createNode())
// WHEN
val query = """MATCH (david { name: "David" })--(otherPerson)-->()
|WITH otherPerson, count(*) AS foaf WHERE foaf > 1
|WITH otherPerson WHERE otherPerson.name <> 'NotOther'
|RETURN count(*)""".stripMargin
val result = executeScalarWithAllPlannersAndCompatibilityMode[Long](query)
//THEN
result should equal(1)
}
}