@@ -708,60 +708,101 @@ public void add_two_nodes_to_the_spatial_layer() throws Exception {
708
708
assertEquals (false , res .hasNext ());
709
709
}
710
710
);
711
+ Result removeResult = db .execute ("CALL spatial.removeNode('geom',$node) YIELD node RETURN node" , map ("node" , node1 ));
712
+ Assert .assertEquals (node1 ,removeResult .next ().get ("node" ));
713
+ removeResult .close ();
714
+ testResult (db , "CALL spatial.withinDistance('geom',{lon:15.0,lat:60.0},100)" , res -> {
715
+ assertEquals (true , res .hasNext ());
716
+ assertEquals (node2 , res .next ().get ("node" ));
717
+ assertEquals (false , res .hasNext ());
718
+ }
719
+ );
711
720
}
712
721
713
722
@ Test
714
723
public void add_many_nodes_to_the_simple_point_layer_using_addNodes () throws Exception {
715
724
// Playing with this number in both tests leads to rough benchmarking of the addNode/addNodes comparison
716
725
int count = 1000 ;
717
- execute ("CALL spatial.addLayer('poi ','SimplePoint','')" );
726
+ execute ("CALL spatial.addLayer('simple_poi ','SimplePoint','')" );
718
727
String query = "UNWIND range(1,{count}) as i\n " +
719
- "CREATE (n:Point {latitude:(56.0+toFloat(i)/100.0),longitude:(12.0+toFloat(i)/100.0)})\n " +
728
+ "CREATE (n:Point {id:i, latitude:(56.0+toFloat(i)/100.0),longitude:(12.0+toFloat(i)/100.0)})\n " +
720
729
"WITH collect(n) as points\n " +
721
- "CALL spatial.addNodes('poi ',points) YIELD count\n " +
730
+ "CALL spatial.addNodes('simple_poi ',points) YIELD count\n " +
722
731
"RETURN count" ;
723
732
testCountQuery ("addNodes" , query , count , "count" , map ("count" , count ));
733
+ testRemoveNodes ("simple_poi" , count );
724
734
}
725
735
726
736
@ Test
727
737
public void add_many_nodes_to_the_simple_point_layer_using_addNode () throws Exception {
728
738
// Playing with this number in both tests leads to rough benchmarking of the addNode/addNodes comparison
729
739
int count = 1000 ;
730
- execute ("CALL spatial.addLayer('poi ','SimplePoint','')" );
740
+ execute ("CALL spatial.addLayer('simple_poi ','SimplePoint','')" );
731
741
String query = "UNWIND range(1,{count}) as i\n " +
732
- "CREATE (n:Point {latitude:(56.0+toFloat(i)/100.0),longitude:(12.0+toFloat(i)/100.0)})\n " +
742
+ "CREATE (n:Point {id:i, latitude:(56.0+toFloat(i)/100.0),longitude:(12.0+toFloat(i)/100.0)})\n " +
733
743
"WITH n\n " +
734
- "CALL spatial.addNode('poi ',n) YIELD node\n " +
744
+ "CALL spatial.addNode('simple_poi ',n) YIELD node\n " +
735
745
"RETURN count(node)" ;
736
746
testCountQuery ("addNode" , query , count , "count(node)" , map ("count" , count ));
747
+ testRemoveNode ("simple_poi" , count );
737
748
}
738
749
739
750
@ Test
740
751
public void add_many_nodes_to_the_native_point_layer_using_addNodes () throws Exception {
741
752
// Playing with this number in both tests leads to rough benchmarking of the addNode/addNodes comparison
742
753
int count = 1000 ;
743
- execute ("CALL spatial.addLayer('poi ','NativePoint','')" );
754
+ execute ("CALL spatial.addLayer('native_poi ','NativePoint','')" );
744
755
String query = "UNWIND range(1,{count}) as i\n " +
745
- "WITH Point({latitude:(56.0+toFloat(i)/100.0),longitude:(12.0+toFloat(i)/100.0)}) AS location\n " +
746
- "CREATE (n:Point {location:location})\n " +
756
+ "WITH i, Point({latitude:(56.0+toFloat(i)/100.0),longitude:(12.0+toFloat(i)/100.0)}) AS location\n " +
757
+ "CREATE (n:Point {id: i, location:location})\n " +
747
758
"WITH collect(n) as points\n " +
748
- "CALL spatial.addNodes('poi ',points) YIELD count\n " +
759
+ "CALL spatial.addNodes('native_poi ',points) YIELD count\n " +
749
760
"RETURN count" ;
750
761
testCountQuery ("addNodes" , query , count , "count" , map ("count" , count ));
762
+ testRemoveNodes ("native_poi" , count );
751
763
}
752
764
753
765
@ Test
754
766
public void add_many_nodes_to_the_native_point_layer_using_addNode () throws Exception {
755
767
// Playing with this number in both tests leads to rough benchmarking of the addNode/addNodes comparison
756
768
int count = 1000 ;
757
- execute ("CALL spatial.addLayer('poi ','NativePoint','')" );
769
+ execute ("CALL spatial.addLayer('native_poi ','NativePoint','')" );
758
770
String query = "UNWIND range(1,{count}) as i\n " +
759
- "WITH Point({latitude:(56.0+toFloat(i)/100.0),longitude:(12.0+toFloat(i)/100.0)}) AS location\n " +
760
- "CREATE (n:Point {location:location})\n " +
771
+ "WITH i, Point({latitude:(56.0+toFloat(i)/100.0),longitude:(12.0+toFloat(i)/100.0)}) AS location\n " +
772
+ "CREATE (n:Point {id: i, location:location})\n " +
761
773
"WITH n\n " +
762
- "CALL spatial.addNode('poi ',n) YIELD node\n " +
774
+ "CALL spatial.addNode('native_poi ',n) YIELD node\n " +
763
775
"RETURN count(node)" ;
764
776
testCountQuery ("addNode" , query , count , "count(node)" , map ("count" , count ));
777
+ testRemoveNode ("native_poi" , count );
778
+ }
779
+
780
+ private void testRemoveNode (String layer , int count ) {
781
+ // Check all nodes are there
782
+ testCountQuery ("withinDistance" , "CALL spatial.withinDistance('" + layer + "',{lon:15.0,lat:60.0},1000) YIELD node RETURN count(node)" , count , "count(node)" , null );
783
+ // Now remove half the points
784
+ String remove = "UNWIND range(1,{count}) as i\n " +
785
+ "MATCH (n:Point {id:i})\n " +
786
+ "WITH n\n " +
787
+ "CALL spatial.removeNode('" + layer + "',n) YIELD node\n " +
788
+ "RETURN count(node)" ;
789
+ testCountQuery ("removeNode" , remove , count / 2 , "count(node)" , map ("count" , count / 2 ));
790
+ // Check that only half remain
791
+ testCountQuery ("withinDistance" , "CALL spatial.withinDistance('" + layer + "',{lon:15.0,lat:60.0},1000) YIELD node RETURN count(node)" , count / 2 , "count(node)" , null );
792
+ }
793
+
794
+ private void testRemoveNodes (String layer , int count ) {
795
+ // Check all nodes are there
796
+ testCountQuery ("withinDistance" , "CALL spatial.withinDistance('" + layer + "',{lon:15.0,lat:60.0},1000) YIELD node RETURN count(node)" , count , "count(node)" , null );
797
+ // Now remove half the points
798
+ String remove = "UNWIND range(1,{count}) as i\n " +
799
+ "MATCH (n:Point {id:i})\n " +
800
+ "WITH collect(n) as points\n " +
801
+ "CALL spatial.removeNodes('" + layer + "',points) YIELD count\n " +
802
+ "RETURN count" ;
803
+ testCountQuery ("removeNodes" , remove , count / 2 , "count" , map ("count" , count / 2 ));
804
+ // Check that only half remain
805
+ testCountQuery ("withinDistance" , "CALL spatial.withinDistance('" + layer + "',{lon:15.0,lat:60.0},1000) YIELD node RETURN count(node)" , count / 2 , "count(node)" , null );
765
806
}
766
807
767
808
@ Test
0 commit comments