-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
SpatialFunctionsAcceptanceTest.scala
729 lines (604 loc) · 36.6 KB
/
SpatialFunctionsAcceptanceTest.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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
/*
* Copyright (c) 2002-2018 "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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.internal.cypher.acceptance
import java.util.concurrent.TimeUnit
import org.neo4j.cypher.ExecutionEngineFunSuite
import org.neo4j.graphdb.Label
import org.neo4j.graphdb.spatial.Point
import org.neo4j.internal.cypher.acceptance.CypherComparisonSupport.Versions.V3_1
import org.neo4j.internal.cypher.acceptance.CypherComparisonSupport._
import org.neo4j.values.storable.{CoordinateReferenceSystem, Values}
class SpatialFunctionsAcceptanceTest extends ExecutionEngineFunSuite with CypherComparisonSupport {
val expectedToSucceed = Configs.Interpreted + Configs.Morsel - Configs.Version2_3
val expectedToFail = TestConfiguration(Versions(Versions.Default, V3_1), Planners.all, Runtimes.Default)
test("point function should work with literal map") {
val result = executeWith(expectedToSucceed, "RETURN point({latitude: 12.78, longitude: 56.7}) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 56.7, 12.78))))
}
test("point function should work with literal map and cartesian coordinates") {
val result = executeWith(expectedToSucceed, "RETURN point({x: 2.3, y: 4.5, crs: 'cartesian'}) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.Cartesian, 2.3, 4.5))))
}
test("point function should work with literal map and geographic coordinates") {
val result = executeWith(expectedToSucceed, "RETURN point({longitude: 2.3, latitude: 4.5, crs: 'WGS-84'}) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 2.3, 4.5))))
}
test("point function should not work with literal map and incorrect cartesian CRS") {
failWithError(expectedToFail, "RETURN point({x: 2.3, y: 4.5, crs: 'cart'}) as point", List("'cart' is not a supported coordinate reference system for points"))
}
test("point function should not work with literal map and incorrect geographic CRS") {
failWithError(expectedToFail, "RETURN point({x: 2.3, y: 4.5, crs: 'WGS84'}) as point", List("'WGS84' is not a supported coordinate reference system for points"))
}
test("point function should work with integer arguments") {
val result = executeWith(expectedToSucceed, "RETURN point({x: 2, y: 4}) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.Cartesian, 2, 4))))
}
test("should fail properly if missing cartesian coordinates") {
failWithError(expectedToFail, "RETURN point({params}) as point", List("A point must contain either 'x' and 'y' or 'latitude' and 'longitude'"),
params = "params" -> Map("y" -> 1.0, "crs" -> "cartesian"))
}
test("should fail properly if missing geographic longitude") {
failWithError(expectedToFail, "RETURN point({params}) as point", List("A point must contain either 'x' and 'y' or 'latitude' and 'longitude'"),
params = "params" -> Map("latitude" -> 1.0, "crs" -> "WGS-84"))
}
test("should fail properly if missing geographic latitude") {
failWithError(expectedToFail, "RETURN point({params}) as point", List("A point must contain either 'x' and 'y' or 'latitude' and 'longitude'"),
params = "params" -> Map("longitude" -> 1.0, "crs" -> "WGS-84"))
}
test("should fail properly if unknown coordinate system") {
failWithError(expectedToFail, "RETURN point({params}) as point", List("'WGS-1337' is not a supported coordinate reference system for points"),
params = "params" -> Map("x" -> 1, "y" -> 2, "crs" -> "WGS-1337"))
}
test("should default to Cartesian if missing cartesian CRS") {
val result = executeWith(expectedToSucceed, "RETURN point({x: 2.3, y: 4.5}) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.Cartesian, 2.3, 4.5))))
}
test("should default to WGS84 if missing geographic CRS") {
val result = executeWith(expectedToSucceed, "RETURN point({longitude: 2.3, latitude: 4.5}) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 2.3, 4.5))))
}
test("should allow Geographic CRS with x/y coordinates") {
val result = executeWith(expectedToSucceed, "RETURN point({x: 2.3, y: 4.5, crs: 'WGS-84'}) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 2.3, 4.5))))
}
test("should not allow Cartesian CRS with latitude/longitude coordinates") {
failWithError(expectedToFail, "RETURN point({longitude: 2.3, latitude: 4.5, crs: 'cartesian'}) as point",
List("'cartesian' is not a supported coordinate reference system for geographic points"))
}
test("point function should work with previous map") {
val result = executeWith(expectedToSucceed, "WITH {latitude: 12.78, longitude: 56.7} as data RETURN point(data) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 56.7, 12.78))))
}
test("distance function should work on co-located points") {
val result = executeWith(expectedToSucceed, "WITH point({latitude: 12.78, longitude: 56.7}) as point RETURN distance(point,point) as dist",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point", "dist"),
expectPlansToFail = Configs.AllRulePlanners))
result.toList should equal(List(Map("dist" -> 0.0)))
}
test("distance function should work on nearby cartesian points") {
val result = executeWith(expectedToSucceed,
"""
|WITH point({x: 2.3, y: 4.5, crs: 'cartesian'}) as p1, point({x: 1.1, y: 5.4, crs: 'cartesian'}) as p2
|RETURN distance(p1,p2) as dist
""".stripMargin,
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "p1", "p2", "dist"),
expectPlansToFail = Configs.AllRulePlanners))
result.columnAs("dist").next().asInstanceOf[Double] should equal(1.5)
}
test("distance function should work on nearby points") {
val result = executeWith(expectedToSucceed,
"""
|WITH point({longitude: 12.78, latitude: 56.7}) as p1, point({latitude: 56.71, longitude: 12.79}) as p2
|RETURN distance(p1,p2) as dist
""".stripMargin,
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "p1", "p2", "dist"),
expectPlansToFail = Configs.AllRulePlanners))
Math.round(result.columnAs("dist").next().asInstanceOf[Double]) should equal(1270)
}
test("distance function should work on distant points") {
val result = executeWith(expectedToSucceed,
"""
|WITH point({latitude: 56.7, longitude: 12.78}) as p1, point({longitude: -51.9, latitude: -16.7}) as p2
|RETURN distance(p1,p2) as dist
""".stripMargin,
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "p1", "p2", "dist"),
expectPlansToFail = Configs.AllRulePlanners))
Math.round(result.columnAs("dist").next().asInstanceOf[Double]) should equal(10116214)
}
// Fails with TestFailException or java.lang.IllegalArgumentException depending on TestConfiguration
test("distance function should fail if provided with points from different CRS") {
try {
failWithError(expectedToFail,
"""WITH point({x: 2.3, y: 4.5, crs: 'cartesian'}) as p1, point({longitude: 1.1, latitude: 5.4, crs: 'WGS-84'}) as p2
|RETURN distance(p1,p2) as dist""".stripMargin, List("Invalid points passed to distance(p1, p2)"))
} catch {
case e: Throwable => assert(e.getMessage.contains("Invalid points passed to distance(p1, p2)"))
}
}
test("distance function should measure distance from Copenhagen train station to Neo4j in Malmö") {
val result = executeWith(expectedToSucceed,
"""
|WITH point({latitude: 55.672874, longitude: 12.564590}) as p1, point({latitude: 55.611784, longitude: 12.994341}) as p2
|RETURN distance(p1,p2) as dist
""".stripMargin,
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "p1", "p2","dist"),
expectPlansToFail = Configs.AllRulePlanners))
Math.round(result.columnAs("dist").next().asInstanceOf[Double]) should equal(27842)
}
test("distance function should work with two null inputs") {
val result = executeWith(expectedToSucceed, "RETURN distance(null, null) as dist")
result.toList should equal(List(Map("dist" -> null)))
}
test("distance function should return null with lhs null input") {
val result = executeWith(expectedToSucceed,
"""
|WITH point({latitude: 55.672874, longitude: 12.564590}) as p1
|RETURN distance(null, p1) as dist
""".stripMargin)
result.toList should equal(List(Map("dist" -> null)))
}
test("distance function should return null with rhs null input") {
val result = executeWith(expectedToSucceed,
"""
|WITH point({latitude: 55.672874, longitude: 12.564590}) as p1
|RETURN distance(p1, null) as dist
""".stripMargin)
result.toList should equal(List(Map("dist" -> null)))
}
test("distance function should return null if a point is null") {
var result = executeWith(expectedToSucceed,
"RETURN distance(point({latitude:3,longitude:7}),point({latitude:null, longitude:3})) as dist;")
result.toList should equal(List(Map("dist" -> null)))
result = executeWith(expectedToSucceed,
"RETURN distance(point({latitude:3,longitude:null}),point({latitude:7, longitude:3})) as dist;")
result.toList should equal(List(Map("dist" -> null)))
result = executeWith(expectedToSucceed,
"RETURN distance(point({x:3,y:7}),point({x:null, y:3})) as dist;")
result.toList should equal(List(Map("dist" -> null)))
result = executeWith(expectedToSucceed,
"RETURN distance(point({x:3,y:null}),point({x:7, y:3})) as dist;")
result.toList should equal(List(Map("dist" -> null)))
}
test("distance function should fail on wrong type") {
val config = Configs.AbsolutelyAll + TestConfiguration(Versions.Default, Planners.Default, Runtimes.Default) - Configs.Version2_3
failWithError(config, "RETURN distance(1, 2) as dist", List("Type mismatch: expected Point or Geometry but was Integer"))
}
test("point function should work with node properties") {
// Given
createLabeledNode(Map("latitude" -> 12.78, "longitude" -> 56.7), "Place")
// When
val result = executeWith(expectedToSucceed - Configs.Morsel, "MATCH (p:Place) RETURN point({latitude: p.latitude, longitude: p.longitude}) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
// Then
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 56.7, 12.78))))
}
test("point function should work with relationship properties") {
// Given
val r = relate(createNode(), createNode(), "PASS_THROUGH", Map("latitude" -> 12.78, "longitude" -> 56.7))
// When
val result = executeWith(expectedToSucceed, "MATCH ()-[r:PASS_THROUGH]->() RETURN point({latitude: r.latitude, longitude: r.longitude}) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
// Then
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 56.7, 12.78))))
}
test("point function should work with node as map") {
// Given
createLabeledNode(Map("latitude" -> 12.78, "longitude" -> 56.7), "Place")
// When
val result = executeWith(expectedToSucceed - Configs.Morsel, "MATCH (p:Place) RETURN point(p) as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
// Then
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 56.7, 12.78))))
}
test("point function should work with null input") {
val result = executeWith(expectedToSucceed, "RETURN point(null) as p")
result.toList should equal(List(Map("p" -> null)))
}
test("point function should return null if the map that backs it up contains a null") {
var result = executeWith(expectedToSucceed, "RETURN point({latitude:null, longitude:3}) as pt;")
result.toList should equal(List(Map("pt" -> null)))
result = executeWith(expectedToSucceed, "RETURN point({latitude:3, longitude:null}) as pt;")
result.toList should equal(List(Map("pt" -> null)))
result = executeWith(expectedToSucceed, "RETURN point({x:null, y:3}) as pt;")
result.toList should equal(List(Map("pt" -> null)))
result = executeWith(expectedToSucceed, "RETURN point({x:3, y:null}) as pt;")
result.toList should equal(List(Map("pt" -> null)))
}
test("point function should fail on wrong type") {
val config = Configs.AbsolutelyAll + TestConfiguration(Versions.Default, Planners.Default, Runtimes.Default) - Configs.Version2_3
failWithError(config, "RETURN point(1) as dist", List("Type mismatch: expected Map, Node or Relationship but was Integer"))
}
test("point should be assignable to node property") {
// Given
createLabeledNode("Place")
// When
val config = expectedToSucceed - Configs.Cost3_1 - Configs.AllRulePlanners - Configs.Morsel
val result = executeWith(config, "MATCH (p:Place) SET p.location = point({latitude: 56.7, longitude: 12.78}) RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
// Then
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
}
test("point should be readable from node property") {
// Given
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 result = executeWith(Configs.All, "MATCH (p:Place) RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
// 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 node property") {
// Given
graph.inTx {
graph.schema().indexFor(Label.label("Place")).on("location").create()
}
graph.inTx {
graph.schema().awaitIndexesOnline(5, TimeUnit.SECONDS)
}
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 result = executeWith(expectedToSucceed - Configs.AllRulePlanners,
"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 useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeek", ":Place(location)")
}, expectPlansToFail = Configs.AbsolutelyAll - Configs.Version3_4 - Configs.Version3_3))
// 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("with multiple indexed points only exact match should be returned") {
// Given
graph.inTx {
graph.schema().indexFor(Label.label("Place")).on("location").create()
}
graph.inTx {
graph.schema().awaitIndexesOnline(5, TimeUnit.SECONDS)
}
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_3, Versions.V3_4, 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({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point",
planComparisonStrategy = ComparePlansWithAssertion({ plan =>
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeek", ":Place(location)")
}, expectPlansToFail = Configs.AbsolutelyAll - configuration))
// Then
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7))))
}
// TODO add 3D here too
test("inequality on cartesian points") {
// case same point
shouldCompareLike("point({x: 0, y: 0})", "point({x: 0, y: 0})", aBiggerB = false, aSmallerB = false)
// case top right quadrant
shouldCompareLike("point({x: 1, y: 1})", "point({x: 0, y: 0})", aBiggerB = true, aSmallerB = false)
// case bottom left quadrant
shouldCompareLike("point({x: -1, y: -1})", "point({x: 0, y: 0})", aBiggerB = false, aSmallerB = true)
// case top left quadrant
shouldCompareLike("point({x: -1, y: 1})", "point({x: 0, y: 0})", aBiggerB = null, aSmallerB = null)
// case bottom right quadrant
shouldCompareLike("point({x: 1, y: -1})", "point({x: 0, y: 0})", aBiggerB = null, aSmallerB = null)
// case staight top
shouldCompareLike("point({x: 0, y: 1})", "point({x: 0, y: 0})", aBiggerB = true, aSmallerB = false)
// case staight right
shouldCompareLike("point({x: 1, y: 0})", "point({x: 0, y: 0})", aBiggerB = true, aSmallerB = false)
// case staight bottom
shouldCompareLike("point({x: 0, y: -1})", "point({x: 0, y: 0})", aBiggerB = false, aSmallerB = true)
// case staight left
shouldCompareLike("point({x: -1, y: 0})", "point({x: 0, y: 0})", aBiggerB = false, aSmallerB = true)
}
// TODO what about the poles!?
test("inequality on geographic points") {
// case same point
shouldCompareLike("point({longitude: 0, latitude: 0})", "point({longitude: 0, latitude: 0})", aBiggerB = false, aSmallerB = false)
// case top right quadrant
shouldCompareLike("point({longitude: 1, latitude: 1})", "point({longitude: 0, latitude: 0})", aBiggerB = true, aSmallerB = false)
// case bottom left quadrant
shouldCompareLike("point({longitude: -1, latitude: -1})", "point({longitude: 0, latitude: 0})", aBiggerB = false, aSmallerB = true)
// case top left quadrant
shouldCompareLike("point({longitude: -1, latitude: 1})", "point({longitude: 0, latitude: 0})", aBiggerB = null, aSmallerB = null)
// case bottom right quadrant
shouldCompareLike("point({longitude: 1, latitude: -1})", "point({longitude: 0, latitude: 0})", aBiggerB = null, aSmallerB = null)
// case staight top
shouldCompareLike("point({longitude: 0, latitude: 1})", "point({longitude: 0, latitude: 0})", aBiggerB = true, aSmallerB = false)
// case staight right
shouldCompareLike("point({longitude: 1, latitude: 0})", "point({longitude: 0, latitude: 0})", aBiggerB = true, aSmallerB = false)
// case staight bottom
shouldCompareLike("point({longitude: 0, latitude: -1})", "point({longitude: 0, latitude: 0})", aBiggerB = false, aSmallerB = true)
// case staight left
shouldCompareLike("point({longitude: -1, latitude: 0})", "point({longitude: 0, latitude: 0})", aBiggerB = false, aSmallerB = true)
}
test("inequality on mixed points") {
shouldCompareLike("point({longitude: 0, latitude: 0})", "point({x: 0, y: 0})", aBiggerB = null, aSmallerB = null)
}
private def shouldCompareLike(a: String, b: String, aBiggerB: Any, aSmallerB: Any) = {
val query =
s"""WITH $a as a, $b as b
|RETURN a > b, a < b
""".stripMargin
val pointConfig = Configs.Interpreted - Configs.BackwardsCompatibility - Configs.AllRulePlanners
val result = executeWith(pointConfig, query).toList
result should equal(List(Map("a > b" -> aBiggerB, "a < b" -> aSmallerB)))
}
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 = innerExecuteDeprecated("CYPHER runtime=slotted MATCH (p:Place) WHERE p.location > point({x: 0, y: 0}) RETURN p.location as point", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeekByRange", ":Place(location) > point")
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 = innerExecuteDeprecated("CYPHER runtime=slotted MATCH (p:Place) WHERE p.location < point({x: 0, y: 0}) RETURN p.location as point", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeekByRange", ":Place(location) < point")
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 = innerExecuteDeprecated("CYPHER runtime=slotted MATCH (p:Place) WHERE p.location > point({x: 0, y: 0}) AND p.location < point({x: 200000, y: 200000}) RETURN p.location as point", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeekByRange", ":Place(location) > point", ":Place(location) < point")
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 = innerExecuteDeprecated("CYPHER runtime=slotted MATCH (p:Place) WHERE p.location > point({latitude: 56.0, longitude: 12.0, crs: 'WGS-84'}) RETURN p.location as point", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeekByRange", ":Place(location) > point")
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 = innerExecuteDeprecated("CYPHER runtime=slotted MATCH (p:Place) WHERE p.location = point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("NodeIndexSeek", ":Place(location)")
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") {
// 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 = innerExecuteDeprecated("CYPHER runtime=slotted MATCH (p:Place) WHERE p.location > point({latitude: 56.0, longitude: 12.0, crs: 'WGS-84'}) RETURN p.location as point", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeekByRange", ":Place(location) > point")
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 = innerExecuteDeprecated("CYPHER runtime=slotted MATCH (p:Place) WHERE p.location >= point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeekByRange", ":Place(location) >= point")
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 = innerExecuteDeprecated("CYPHER runtime=slotted MATCH (p:Place) WHERE p.location > point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeekByRange", ":Place(location) > point")
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 = innerExecuteDeprecated("CYPHER runtime=slotted MATCH (p:Place) WHERE p.location >= point({latitude: 56.7, longitude: 12.78, crs: 'WGS-84'}) RETURN p.location as point", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeekByRange", ":Place(location) >= point")
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 = innerExecuteDeprecated("CYPHER runtime=slotted 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", Map.empty)
// Then
val plan = result.executionPlanDescription()
plan should useOperatorWithText("Projection", "point")
plan should useOperatorWithText("NodeIndexSeekByRange", ":Place(location) >= point", ":Place(location) < point")
result.toList should equal(List(Map("point" -> Values.pointValue(CoordinateReferenceSystem.WGS84, 11.78, 55.7))))
}
test("array of points should be assignable to node property") {
// Given
createLabeledNode("Place")
// When
val config = expectedToSucceed - Configs.Cost3_1 - Configs.AllRulePlanners - Configs.Morsel
val query =
"""
|UNWIND [1,2,3] as num
|WITH point({x: num, y: num}) as p
|WITH collect(p) as points
|MATCH (place:Place) SET place.location = points
|RETURN points
""".stripMargin
val result = executeWith(config, query,
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
// Then
result.toList should equal(List(Map("points" -> List(
Values.pointValue(CoordinateReferenceSystem.Cartesian, 1.0, 1.0),
Values.pointValue(CoordinateReferenceSystem.Cartesian, 2.0, 2.0),
Values.pointValue(CoordinateReferenceSystem.Cartesian, 3.0, 3.0)
))))
}
test("array of cartesian points should be readable from node property") {
// Given
createLabeledNode("Place")
graph.execute(
"""
|UNWIND [1,2,3] as num
|WITH point({x: num, y: num}) as p
|WITH collect(p) as points
|MATCH (place:Place) SET place.location = points
|RETURN place.location as points
""".stripMargin)
// When
val result = executeWith(Configs.All, "MATCH (p:Place) RETURN p.location as points",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
// Then
val points = result.columnAs("points").toList.head.asInstanceOf[Array[_]]
points should equal(Array(
Values.pointValue(CoordinateReferenceSystem.Cartesian, 1.0, 1.0),
Values.pointValue(CoordinateReferenceSystem.Cartesian, 2.0, 2.0),
Values.pointValue(CoordinateReferenceSystem.Cartesian, 3.0, 3.0)
))
}
test("array of wgs84 points should be readable from node property") {
// Given
createLabeledNode("Place")
graph.execute(
"""
|UNWIND [1,2,3] as num
|WITH point({latitude: num, longitude: num}) as p
|WITH collect(p) as points
|MATCH (place:Place) SET place.location = points
|RETURN place.location as points
""".stripMargin)
// When
val result = executeWith(Configs.All, "MATCH (p:Place) RETURN p.location as points",
planComparisonStrategy = ComparePlansWithAssertion(_ should useOperatorWithText("Projection", "point"),
expectPlansToFail = Configs.AllRulePlanners))
// Then
val points = result.columnAs("points").toList.head.asInstanceOf[Array[_]]
points should equal(Array(
Values.pointValue(CoordinateReferenceSystem.WGS84, 1.0, 1.0),
Values.pointValue(CoordinateReferenceSystem.WGS84, 2.0, 2.0),
Values.pointValue(CoordinateReferenceSystem.WGS84, 3.0, 3.0)
))
}
test("array of mixed points should not be assignable to node property") {
// Given
createLabeledNode("Place")
// When
val config = expectedToSucceed - Configs.Cost3_1 - Configs.AllRulePlanners - Configs.Morsel
val query =
"""
|WITH [point({x: 1, y: 2}), point({latitude: 1, longitude: 2})] as points
|MATCH (place:Place) SET place.location = points
|RETURN points
""".stripMargin
// Then
failWithError(config + Configs.Procs, query, Seq("Collections containing point values with different CRS can not be stored in properties."))
}
}