-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
SpatialIndexResultsAcceptanceTest.scala
629 lines (532 loc) · 33.7 KB
/
SpatialIndexResultsAcceptanceTest.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j Enterprise Edition. The included source
* code can be redistributed and/or modified under the terms of the
* GNU AFFERO GENERAL PUBLIC LICENSE Version 3
* (http://www.fsf.org/licensing/licenses/agpl-3.0.html) with the
* Commons Clause, as found in the associated LICENSE.txt file.
*
* 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 Affero General Public License for more details.
*
* Neo4j object code can be licensed independently from the source
* under separate terms from the AGPL. Inquiries can be directed to:
* licensing@neo4j.com
*
* More information is also available at:
* https://neo4j.com/licensing/
*/
package org.neo4j.internal.cypher.acceptance
import org.neo4j.graphdb.spatial.Point
import org.neo4j.internal.cypher.acceptance.CypherComparisonSupport._
import org.neo4j.values.storable.{CoordinateReferenceSystem, PointValue, Values}
import scala.collection.Map
import scala.collection.immutable.{Map => ImmutableMap}
class SpatialIndexResultsAcceptanceTest extends IndexingTestSupport {
private val equalityConfig = Configs.Interpreted - Configs.Before3_3AndRule
private val indexConfig = Configs.Interpreted - Configs.Cost3_1 - Configs.Cost2_3 - Configs.AllRulePlanners
override def cypherComparisonSupport = true
test("inequality query should give same answer for indexed and non-indexed property") {
createIndex()
val point = Values.pointValue(CoordinateReferenceSystem.Cartesian, 0, 0)
val node = createIndexedNode(point)
setNonIndexedValue(node, point)
assertRangeScanFor("<", point)
assertLabelRangeScanFor("<", point)
assertRangeScanFor("<=", point, node)
assertLabelRangeScanFor("<=", point, node)
assertRangeScanFor("<", Values.pointValue(CoordinateReferenceSystem.Cartesian, 1, 1), node)
assertLabelRangeScanFor("<", Values.pointValue(CoordinateReferenceSystem.Cartesian, 1, 1), node)
assertRangeScanFor("<=", Values.pointValue(CoordinateReferenceSystem.Cartesian, 1, 0), node)
assertLabelRangeScanFor("<=", Values.pointValue(CoordinateReferenceSystem.Cartesian, 1, 0), node)
}
test("indexed point should be readable from node property") {
// Given
graph.createIndex("Place", "location")
createLabeledNode("Place")
graph.execute("MATCH (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point")
// When
val localConfig = Configs.Interpreted - Configs.Version2_3 - Configs.AllRulePlanners
val result = executeWith(localConfig,
"MATCH (p:Place) WHERE p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion({ plan =>
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeek").containingArgument(":Place(location)"))
}, expectPlansToFail = Configs.AbsolutelyAll - Configs.Version3_5 - Configs.Version3_4))
// Then
val point = result.columnAs("point").toList.head.asInstanceOf[Point]
point should equal(Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))
// And CRS names should equal
point.getCRS.getHref should equal("http://spatialreference.org/ref/epsg/4326/")
}
test("indexed point should be readable from parameterized node property") {
// Given
graph.createIndex("Place", "location")
createLabeledNode("Place")
graph.execute("MATCH (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point")
// When
val localConfig = Configs.All - Configs.Before3_3AndRule
val result = executeWith(localConfig,
"MATCH (p:Place) WHERE p.location = $param RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion({ plan =>
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeek").containingArgument(":Place(location)"))
}, expectPlansToFail = Configs.AbsolutelyAll - Configs.Version3_5 - Configs.Version3_4),
params = ImmutableMap("param" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7)))
// Then
val point = result.columnAs("point").toList.head.asInstanceOf[Point]
point should equal(Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))
// And CRS names should equal
point.getCRS.getHref should equal("http://spatialreference.org/ref/epsg/4326/")
}
test("indexed point array of size 1 should be readable from parameterized node property") {
// Given
graph.createIndex("Place", "location")
createLabeledNode("Place")
graph.execute("MATCH (p:Place) SET p.location = [point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'})] RETURN p.location as point")
// When
val localConfig = Configs.All - Configs.Before3_3AndRule
val result = executeWith(localConfig,
"MATCH (p:Place) WHERE p.location = $param RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion({ plan =>
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeek").containingArgument(":Place(location)"))
}, expectPlansToFail = Configs.AbsolutelyAll - Configs.Version3_5 - Configs.Version3_4),
params = ImmutableMap("param" -> Array(Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
// Then
val pointList = result.columnAs("point").toList.head.asInstanceOf[Iterable[PointValue]].toList
pointList should equal(List(Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7)))
// And CRS names should equal
pointList.head.getCRS.getHref should equal("http://spatialreference.org/ref/epsg/4326/")
}
test("indexed point array should be readable from parameterized node property") {
// Given
graph.createIndex("Place", "location")
createLabeledNode("Place")
graph.execute(
"""MATCH (p:Place) SET p.location =
|[point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}),
| point({y: 56.7, x: 13.78, crs: 'WGS-84'})]
|RETURN p.location as point""".stripMargin)
// When
val localConfig = Configs.All - Configs.Before3_3AndRule
val result = executeWith(localConfig,
"MATCH (p:Place) WHERE p.location = $param RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion({ plan =>
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeek").containingArgument(":Place(location)"))
}, expectPlansToFail = Configs.AbsolutelyAll - Configs.Version3_5 - Configs.Version3_4),
params = ImmutableMap("param" ->
Array(Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7),
Values.pointValue(CoordinateReferenceSystem.WGS84, 13.78, 56.7))))
// Then
val pointList = result.columnAs("point").toList.head.asInstanceOf[Iterable[PointValue]].toList
pointList should equal(List(
Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7),
Values.pointValue(CoordinateReferenceSystem.WGS84, 13.78, 56.7))
)
// And CRS names should equal
pointList.head.getCRS.getHref should equal("http://spatialreference.org/ref/epsg/4326/")
}
test("indexed point array should be readable from parameterized (as list) node property") {
// Given
graph.createIndex("Place", "location")
createLabeledNode("Place")
graph.execute(
"""MATCH (p:Place) SET p.location =
|[point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}),
| point({y: 56.7, x: 13.78, crs: 'WGS-84'})]
|RETURN p.location as point""".stripMargin)
// When
val localConfig = Configs.All - Configs.Before3_3AndRule
val result = executeWith(localConfig,
"MATCH (p:Place) WHERE p.location = $param RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion({ plan => plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeek").containingArgument(":Place(location)"))
}, expectPlansToFail = Configs.AbsolutelyAll - Configs.Version3_5 - Configs.Version3_4),
params = ImmutableMap("param" ->
List(Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7),
Values.pointValue(CoordinateReferenceSystem.WGS84, 13.78, 56.7))))
// Then
val pointList = result.columnAs("point").toList.head.asInstanceOf[Iterable[PointValue]].toList
pointList should equal(List(
Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7),
Values.pointValue(CoordinateReferenceSystem.WGS84, 13.78, 56.7))
)
// And CRS names should equal
pointList.head.getCRS.getHref should equal("http://spatialreference.org/ref/epsg/4326/")
}
test("seeks should work for indexed point arrays") {
createIndex()
val point1 = Values.pointValue(CoordinateReferenceSystem.Cartesian, 1.2, 3.4).asObjectCopy()
val point2 = Values.pointValue(CoordinateReferenceSystem.Cartesian, 1.2, 5.6).asObjectCopy()
val pointArray1 = Values.pointArray(Array(point1, point2))
val pointArray2 = Values.pointArray(Array(point2, point1))
val pointArray3 = Values.pointArray(Array(point1, point2, point1))
val n1 = createIndexedNode(pointArray1)
createIndexedNode(pointArray2)
createIndexedNode(pointArray3)
assertSeekMatchFor(pointArray1, n1)
}
test("with multiple indexed points only exact match should be returned") {
// Given
graph.createIndex("Place", "location")
createLabeledNode("Place")
graph.execute("MATCH (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 40.7, longitude: -35.78, crs: 'WGS-84'})")
val configuration = TestConfiguration(Versions(Versions.V3_4, Versions.v3_5, Versions.Default), Planners(Planners.Cost, Planners.Default), Runtimes(Runtimes.Interpreted, Runtimes.Slotted, Runtimes.Default))
val query = "MATCH (p:Place) WHERE p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point"
// When
val result = executeWith(configuration + Configs.Cost3_1, query,
planComparisonStrategy = ComparePlansWithAssertion({ plan =>
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeek").containingArgument(":Place(location)"))
}, expectPlansToFail = Configs.AbsolutelyAll - configuration))
// Then
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
}
test("3D indexed point should be readable from node property") {
// Given
graph.createIndex("Place", "location")
createLabeledNode("Place")
graph.execute("MATCH (p:Place) SET p.location = point({x: 1.2, y: 3.4, z: 5.6}) RETURN p.location as point")
// When
val result = executeWith(Configs.Interpreted - Configs.Version3_1 - Configs.Version2_3 - Configs.AllRulePlanners,
"MATCH (p:Place) WHERE p.location = point({x: 1.2, y: 3.4, z: 5.6}) RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion({ plan =>
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeek").containingArgument(":Place(location)"))
}, expectPlansToFail = Configs.AbsolutelyAll - Configs.Version3_5 - Configs.Version3_4))
// Then
val point = result.columnAs("point").toList.head.asInstanceOf[Point]
point should equal(Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 1.2, 3.4, 5.6))
// And CRS names should equal
point.getCRS.getHref should equal("http://spatialreference.org/ref/sr-org/9157/")
}
test("with multiple 3D indexed points only exact match should be returned") {
// Given
graph.createIndex("Place", "location")
createLabeledNode("Place")
graph.execute("MATCH (p:Place) SET p.location = point({x: 1.2, y: 3.4, z: 5.6}) RETURN p.location as point")
graph.execute("CREATE (p:Place) SET p.location = point({x: 1.2, y: 3.4, z: 5.601})")
val configuration = TestConfiguration(Versions(Versions.V3_4, Versions.v3_5, Versions.Default), Planners(Planners.Cost, Planners.Default), Runtimes(Runtimes.Interpreted, Runtimes.Slotted, Runtimes.Default))
// When
val result = executeWith(configuration,
"MATCH (p:Place) WHERE p.location = point({x: 1.2, y: 3.4, z: 5.6}) RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion({ plan =>
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeek").containingArgument(":Place(location)"))
}, expectPlansToFail = Configs.AbsolutelyAll - configuration))
// Then
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 1.2, 3.4, 5.6))))
}
test("indexed points far apart in cartesian space - range query greaterThan") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({x: 100000, y: 100000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: -100000, y: 100000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: -100000, y: -100000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: 100000, y: -100000})")
// When
val result = executeWith(indexConfig, "CYPHER MATCH (p:Place) WHERE p.location > point({x: 0, y: 0}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeekByRange").containingArgumentRegex(":Place\\(location\\) > point.*".r))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.Cartesian, 100000, 100000))))
}
test("indexed points far apart in cartesian space - range query lessThan") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({x: 100000, y: 100000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: -100000, y: 100000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: -100000, y: -100000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: 100000, y: -100000})")
// When
val result = executeWith(indexConfig, "CYPHER MATCH (p:Place) WHERE p.location < point({x: 0, y: 0}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeekByRange").containingArgumentRegex(":Place\\(location\\) < point.*".r))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.Cartesian, -100000, -100000))))
}
test("indexed points far apart in cartesian space - range query within") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({x: 500000, y: 500000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: 100000, y: 100000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: -100000, y: 100000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: -100000, y: -100000})")
graph.execute("CREATE (p:Place) SET p.location = point({x: 100000, y: -100000})")
// When
val result = executeWith(indexConfig, "CYPHER MATCH (p:Place) WHERE p.location > point({x: 0, y: 0}) AND p.location < point({x: 200000, y: 200000}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeekByRange").containingArgumentRegex(":Place\\(location\\) > point.* AND :Place\\(location\\) < point.*".r))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.Cartesian, 100000, 100000))))
}
test("indexed points far apart in WGS84 - range query greaterThan") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 5.7, longitude: 116.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: -50.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: -10.78, crs: 'WGS-84'})")
// When
val result = executeWith(indexConfig, "CYPHER MATCH (p:Place) WHERE p.location > point({latitude: 56.0, longitude: 12.0, crs: 'WGS-84'}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeekByRange").containingArgumentRegex(":Place\\(location\\) > point.*".r))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
}
test("indexed points close together in WGS84 - equality query") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.700001, longitude: 12.7800001, crs: 'WGS-84'})")
// When
val result = executeWith(equalityConfig, "CYPHER MATCH (p:Place) WHERE p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere.aPlan("NodeIndexSeek").containingArgument(":Place(location)")
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
}
test("Index query with MERGE") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.700001, longitude: 12.7800001, crs: 'WGS-84'})")
// When matching in merge
val result = executeWith(equalityConfig, "MERGE (p:Place {location: point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) }) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere.aPlan("NodeIndexSeek").containingArgument(":Place(location)")
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
// And when creating in merge
val result2 = executeWith(equalityConfig, "MERGE (p:Place {location: point({latitude: 156.7, longitude: 112.78, crs: 'WGS-84'}) }) RETURN p.location as point")
// Then
val plan2 = result2.executionPlanDescription()
plan2 should includeSomewhere.aPlan("NodeIndexSeek").containingArgument(":Place(location)")
result2.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 112.78, 156.7))))
}
test("indexed points close together in WGS84 - range query greaterThan") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 55.7, longitude: 11.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 50.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 10.78, crs: 'WGS-84'})")
// When
val result = executeWith(indexConfig, "CYPHER MATCH (p:Place) WHERE p.location > point({latitude: 56.0, longitude: 12.0, crs: 'WGS-84'}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeekByRange").containingArgumentRegex(":Place\\(location\\) > point.*".r))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
}
test("indexed points close together in WGS84 - range query greaterThanOrEqualTo") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 55.7, longitude: 11.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 50.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 10.78, crs: 'WGS-84'})")
// When
val result = executeWith(indexConfig, "CYPHER MATCH (p:Place) WHERE p.location >= point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeekByRange").containingArgumentRegex(":Place\\(location\\) >= point.*".r))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
}
test("indexed points close together in WGS84 - range query greaterThan with no results") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 55.7, longitude: 11.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 50.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 10.78, crs: 'WGS-84'})")
// When
val result = executeWith(indexConfig, "CYPHER MATCH (p:Place) WHERE p.location > point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeekByRange").containingArgumentRegex(":Place\\(location\\) > point.*".r))
assert(result.isEmpty)
}
test("indexed points close together in WGS84 - range query greaterThan with multiple CRS") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({y: 56.7, x: 12.78, crs: 'cartesian'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 55.7, longitude: 11.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 50.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 10.78, crs: 'WGS-84'})")
// When
val result = executeWith(indexConfig, "CYPHER MATCH (p:Place) WHERE p.location >= point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeekByRange").containingArgumentRegex(":Place\\(location\\) >= point.*".r))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
}
test("indexed points close together in WGS84 - range query within") {
// Given
graph.createIndex("Place", "location")
graph.execute("CREATE (p:Place) SET p.location = point({y: 55.7, x: 11.78, crs: 'cartesian'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 55.7, longitude: 11.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 50.7, longitude: 12.78, crs: 'WGS-84'})")
graph.execute("CREATE (p:Place) SET p.location = point({latitude: 56.7, longitude: 10.78, crs: 'WGS-84'})")
// When
val result = executeWith(indexConfig, "CYPHER MATCH (p:Place) WHERE p.location >= point({latitude: 55.7, longitude: 11.78, crs: 'WGS-84'}) AND p.location < point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point")
// Then
val plan = result.executionPlanDescription()
plan should includeSomewhere
.aPlan("Projection").containingArgumentRegex("\\{point : .*\\}".r)
.onTopOf(aPlan("NodeIndexSeekByRange").containingArgumentRegex(":Place\\(location\\) >= point.* AND :Place\\(location\\) < point.*".r))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 11.78, 55.7))))
}
test("indexed points in 3D cartesian space - range queries") {
// Given
createIndex()
val originPoint = Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 0, 0, 0)
val maxPoint = Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 100000, 100000, 100000)
val minPoint = Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, -100000, -100000, -100000)
val origin = createIndexedNode(originPoint)
val upRightTop = createIndexedNode(maxPoint)
val downLeftBottom = createIndexedNode(minPoint)
val downrightTop = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, -100000, 100000, 100000))
val downLeftTop = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, -100000, -100000, 100000))
val upLeftTop = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 100000, -100000, 100000))
val upRightBottom = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 100000, 100000, -100000))
val downRightBottom = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, -100000, 100000, -100000))
val upLeftBottom = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 100000, -100000, -100000))
// 2D points should never be returned
createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, -100000, -100000))
createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 100000, 100000))
assertRangeScanFor(">", originPoint, upRightTop)
assertRangeScanFor(">=", originPoint, origin, upRightTop)
assertRangeScanFor("<", originPoint, downLeftBottom)
assertRangeScanFor("<=", originPoint, origin, downLeftBottom)
assertRangeScanFor(">=", minPoint, "<=", maxPoint, origin, upRightTop, downLeftBottom, downLeftTop, downRightBottom, downrightTop, upLeftBottom, upLeftTop, upRightBottom)
assertRangeScanFor(">", minPoint, "<=", maxPoint, origin, upRightTop)
assertRangeScanFor(">=", minPoint, "<", maxPoint, origin, downLeftBottom)
assertRangeScanFor(">", minPoint, "<", maxPoint, origin)
}
test("indexed points 3D WGS84 space - range queries") {
// Given
createIndex()
val maxPoint = Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.6, 13.1, 100)
val midPoint = Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.5, 13.0, 50)
val minPoint = Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.4, 12.9, 0)
val n0 = createIndexedNode(midPoint)
val n1 = createIndexedNode(maxPoint)
val n2 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.4, 13.1, 100))
val n3 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.4, 12.9, 100))
val n4 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.6, 12.9, 0))
val n5 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.6, 13.1, 0))
val n6 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.4, 13.1, 0))
val n8 = createIndexedNode(minPoint)
val n7 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.6, 12.9, 0))
// 2D points should never be returned
createIndexedNode(Values.pointValue(CoordinateReferenceSystem.WGS84, 56.6, 13.1))
createIndexedNode(Values.pointValue(CoordinateReferenceSystem.WGS84, 56.4, 12.9))
assertRangeScanFor(">", midPoint, n1)
assertRangeScanFor(">=", midPoint, n0, n1)
assertRangeScanFor("<", midPoint, n8)
assertRangeScanFor("<=", midPoint, n0, n8)
assertRangeScanFor(">=", minPoint, "<=", maxPoint, n0, n1, n2, n3, n4, n5, n6, n7, n8)
assertRangeScanFor(">", minPoint, "<=", maxPoint, n0, n1)
assertRangeScanFor(">=", minPoint, "<", maxPoint, n0, n8)
assertRangeScanFor(">", minPoint, "<", maxPoint, n0)
}
test("Range query should return points greater on both axes or less on both axes") {
// Given nodes at the search point, above and below it, and on the axes intersecting it
createIndex()
val nodeAbove15 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 1.2345, 5.4321))
val nodeBelow15 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 0.2345, 4.4321))
val nodeAt15 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 1, 5))
val nodeAt25 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 2, 5))
val nodeAt16 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 1, 6))
val nodeAt05 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 0, 5))
val nodeAt14 = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 1, 4))
createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 0.2345, 5.4321))
createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 1.2345, 4.4321))
Map(
">=" -> Set(nodeAbove15, nodeAt15, nodeAt16, nodeAt25),
"<=" -> Set(nodeBelow15, nodeAt15, nodeAt05, nodeAt14),
">" -> Set(nodeAbove15),
"<" -> Set(nodeBelow15)
).toList.foreach {
case (op, expected) =>
// When
val includingBorder = innerExecuteDeprecated(s"MATCH (n:Label) WHERE n.prop $op point({x: 1, y: 5}) RETURN n")
// Then
val expectAxes = op contains "="
withClue(s"Should ${if(expectAxes) "" else "NOT "}find nodes that are on the axes defined by the search point when using operator '$op'") {
includingBorder.toList.map(_ ("n")).toSet should be(expected)
}
}
// When running a spatial range query for points greater than or equal to the search point
val includingBorder = innerExecuteDeprecated("MATCH (n:Label) WHERE n.prop >= point({x: 1, y: 5}) RETURN n")
// Then expect to also find nodes on the intersecting axes
withClue("Should find nodes that are on the axes defined by the search point") {
includingBorder.toList.map(_ ("n")).toSet should be(Set(nodeAbove15, nodeAt15, nodeAt16, nodeAt25))
}
// When running a spatial range query for points only greater than the search point
val excludingBorder = innerExecuteDeprecated("MATCH (n:Label) WHERE n.prop > point({x: 1, y: 5}) RETURN n")
// Then expect to find nodes above the search point and not on the intersecting axes
withClue("Should NOT find nodes that are on the axes defined by the search point") {
excludingBorder.toList.map(_ ("n")).toSet should be(Set(nodeAbove15))
}
}
test("Bounding box query on regular grid should not return points on the edges") {
// Given
createIndex()
val grid = Range(-10, 10).map { x =>
Range(-10, 10).map { y =>
createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, x, y))
}
}
val nodeToFind = createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 1.2345, 5.4321))
createIndexedNode(Values.pointValue(CoordinateReferenceSystem.Cartesian, 5.4321, 1.2345))
val vertices = Seq(grid(11)(15), grid(11)(16), grid(12)(16), grid(12)(15))
// When running a bounding box query we expect to include all or none of the border points
val includingBorder = innerExecuteDeprecated("MATCH (n:Label) WHERE point({x: 1, y: 5}) <= n.prop <= point({x: 2, y: 6}) RETURN n")
withClue("Should find nodes that are on the axes defined by the search point") {
includingBorder.toList.size should be(5)
}
val excludingBorder = innerExecuteDeprecated("MATCH (n:Label) WHERE point({x: 1, y: 5}) < n.prop < point({x: 2, y: 6}) RETURN n")
withClue("Should find nodes that are on NOT the axes defined by the search point") {
excludingBorder.toList.size should be(1)
}
// And when using the range scan assertions we should find the same results
val minPoint = Values.pointValue(CoordinateReferenceSystem.Cartesian, 1, 5)
val maxPoint = Values.pointValue(CoordinateReferenceSystem.Cartesian, 2, 6)
assertRangeScanFor(">=", minPoint, "<=", maxPoint, vertices :+ nodeToFind: _*)
assertRangeScanFor(">", minPoint, "<", maxPoint, nodeToFind)
}
}