19
19
\! cp -r regress/age_load/data regress/instance/data/age_load
20
20
LOAD 'age';
21
21
SET search_path TO ag_catalog;
22
+ -- Create a country using CREATE clause
22
23
SELECT create_graph('agload_test_graph');
23
24
NOTICE: graph "agload_test_graph" has been created
24
25
create_graph
25
26
--------------
26
27
27
28
(1 row)
28
29
29
- SELECT create_vlabel('agload_test_graph','Country');
30
- NOTICE: VLabel "Country" has been created
31
- create_vlabel
32
- ---------------
33
-
30
+ SELECT * FROM cypher('agload_test_graph', $$CREATE (n:Country {__id__:1}) RETURN n$$) as (n agtype);
31
+ n
32
+ ----------------------------------------------------------------------------------
33
+ {"id": 844424930131969, "label": "Country", "properties": {"__id__": 1}}::vertex
34
34
(1 row)
35
35
36
+ --
37
+ -- Load countries with id
38
+ --
36
39
SELECT load_labels_from_file('agload_test_graph', 'Country',
37
- 'age_load/countries.csv');
40
+ 'age_load/countries.csv', true );
38
41
load_labels_from_file
39
42
-----------------------
40
43
41
44
(1 row)
42
45
43
- SELECT create_vlabel('agload_test_graph','City');
44
- NOTICE: VLabel "City" has been created
45
- create_vlabel
46
- ---------------
47
-
46
+ -- A temporary table should have been created with 54 ids; 1 from CREATE and 53 from file
47
+ SELECT COUNT(*)=54 FROM "_agload_test_graph_ag_vertex_ids";
48
+ ?column?
49
+ ----------
50
+ t
51
+ (1 row)
52
+
53
+ -- Sequence should be equal to max entry id i.e. 248
54
+ SELECT currval('agload_test_graph."Country_id_seq"')=248;
55
+ ?column?
56
+ ----------
57
+ t
48
58
(1 row)
49
59
60
+ -- Should error out on loading the same file again due to duplicate id
61
+ SELECT load_labels_from_file('agload_test_graph', 'Country',
62
+ 'age_load/countries.csv', true);
63
+ ERROR: Cannot insert duplicate vertex id: 844424930131970
64
+ HINT: Entry id 2 is already used
65
+ --
66
+ -- Load cities with id
67
+ --
68
+ -- Should create City label automatically and load cities
50
69
SELECT load_labels_from_file('agload_test_graph', 'City',
51
- 'age_load/cities.csv');
70
+ 'age_load/cities.csv', true);
71
+ NOTICE: VLabel "City" has been created
52
72
load_labels_from_file
53
73
-----------------------
54
74
55
75
(1 row)
56
76
77
+ -- Temporary table should have 54+72485 rows now
78
+ SELECT COUNT(*)=54+72485 FROM "_agload_test_graph_ag_vertex_ids";
79
+ ?column?
80
+ ----------
81
+ t
82
+ (1 row)
83
+
84
+ -- Sequence should be equal to max entry id i.e. 146941
85
+ SELECT currval('agload_test_graph."City_id_seq"')=146941;
86
+ ?column?
87
+ ----------
88
+ t
89
+ (1 row)
90
+
91
+ -- Should error out on loading the same file again due to duplicate id
92
+ SELECT load_labels_from_file('agload_test_graph', 'City',
93
+ 'age_load/cities.csv', true);
94
+ ERROR: Cannot insert duplicate vertex id: 1125899906842777
95
+ HINT: Entry id 153 is already used
96
+ --
97
+ -- Load edges -- Connects cities to countries
98
+ --
99
+ -- Should error out for using vertex label
100
+ SELECT load_edges_from_file('agload_test_graph', 'Country',
101
+ 'age_load/edges.csv');
102
+ ERROR: label "Country" already exists as edge label
57
103
SELECT create_elabel('agload_test_graph','has_city');
58
104
NOTICE: ELabel "has_city" has been created
59
105
create_elabel
@@ -68,6 +114,17 @@ SELECT load_edges_from_file('agload_test_graph', 'has_city',
68
114
69
115
(1 row)
70
116
117
+ -- Sequence should be equal to number of edges loaded i.e. 72485
118
+ SELECT currval('agload_test_graph."has_city_id_seq"')=72485;
119
+ ?column?
120
+ ----------
121
+ t
122
+ (1 row)
123
+
124
+ -- Should error out for using edge label
125
+ SELECT load_labels_from_file('agload_test_graph', 'has_city',
126
+ 'age_load/cities.csv');
127
+ ERROR: label "has_city" already exists as vertex label
71
128
SELECT table_catalog, table_schema, lower(table_name) as table_name, table_type
72
129
FROM information_schema.tables
73
130
WHERE table_schema = 'agload_test_graph' ORDER BY table_name ASC;
@@ -83,7 +140,7 @@ WHERE table_schema = 'agload_test_graph' ORDER BY table_name ASC;
83
140
SELECT COUNT(*) FROM agload_test_graph."Country";
84
141
count
85
142
-------
86
- 53
143
+ 54
87
144
(1 row)
88
145
89
146
SELECT COUNT(*) FROM agload_test_graph."City";
@@ -101,7 +158,7 @@ SELECT COUNT(*) FROM agload_test_graph."has_city";
101
158
SELECT COUNT(*) FROM cypher('agload_test_graph', $$MATCH(n) RETURN n$$) as (n agtype);
102
159
count
103
160
-------
104
- 72538
161
+ 72539
105
162
(1 row)
106
163
107
164
SELECT COUNT(*) FROM cypher('agload_test_graph', $$MATCH (a)-[e]->(b) RETURN e$$) as (n agtype);
@@ -110,6 +167,17 @@ SELECT COUNT(*) FROM cypher('agload_test_graph', $$MATCH (a)-[e]->(b) RETURN e$$
110
167
72485
111
168
(1 row)
112
169
170
+ --
171
+ -- Load countries and cities without id
172
+ --
173
+ -- Should load countries in Country label without error since it should use sequence now
174
+ SELECT load_labels_from_file('agload_test_graph', 'Country',
175
+ 'age_load/countries.csv', false);
176
+ load_labels_from_file
177
+ -----------------------
178
+
179
+ (1 row)
180
+
113
181
SELECT create_vlabel('agload_test_graph','Country2');
114
182
NOTICE: VLabel "Country2" has been created
115
183
create_vlabel
@@ -153,6 +221,7 @@ SELECT COUNT(*) FROM agload_test_graph."City2";
153
221
SELECT id FROM agload_test_graph."Country" LIMIT 10;
154
222
id
155
223
-----------------
224
+ 844424930131969
156
225
844424930131970
157
226
844424930131971
158
227
844424930131974
@@ -162,7 +231,6 @@ SELECT id FROM agload_test_graph."Country" LIMIT 10;
162
231
844424930131996
163
232
844424930132002
164
233
844424930132023
165
- 844424930132025
166
234
(10 rows)
167
235
168
236
SELECT id FROM agload_test_graph."Country2" LIMIT 10;
@@ -180,42 +248,57 @@ SELECT id FROM agload_test_graph."Country2" LIMIT 10;
180
248
1688849860263946
181
249
(10 rows)
182
250
251
+ -- Should return 2 rows for Country with same properties, but different ids
183
252
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country {iso2 : 'BE'})
184
253
RETURN id(n), n.name, n.iso2 $$) as ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);
185
254
id(n) | n.name | n.iso2
186
255
-----------------+-----------+--------
187
256
844424930131990 | "Belgium" | "BE"
188
- (1 row)
257
+ 844424930132223 | "Belgium" | "BE"
258
+ (2 rows)
189
259
260
+ -- Should return 1 row
190
261
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country2 {iso2 : 'BE'})
191
262
RETURN id(n), n.name, n.iso2 $$) as ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);
192
263
id(n) | n.name | n.iso2
193
264
------------------+-----------+--------
194
265
1688849860263942 | "Belgium" | "BE"
195
266
(1 row)
196
267
268
+ -- Should return 2 rows for Country with same properties, but different ids
197
269
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country {iso2 : 'AT'})
198
270
RETURN id(n), n.name, n.iso2 $$) as ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);
199
271
id(n) | n.name | n.iso2
200
272
-----------------+-----------+--------
201
273
844424930131983 | "Austria" | "AT"
202
- (1 row)
274
+ 844424930132221 | "Austria" | "AT"
275
+ (2 rows)
203
276
277
+ -- Should return 1 row
204
278
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country2 {iso2 : 'AT'})
205
279
RETURN id(n), n.name, n.iso2 $$) as ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);
206
280
id(n) | n.name | n.iso2
207
281
------------------+-----------+--------
208
282
1688849860263940 | "Austria" | "AT"
209
283
(1 row)
210
284
285
+ -- Should return 2 rows for Country with same properties, but different ids
211
286
SELECT * FROM cypher('agload_test_graph', $$
212
287
MATCH (u:Country {region : "Europe"})
213
288
WHERE u.name =~ 'Cro.*'
214
- RETURN u.name, u.region
215
- $$) AS (result_1 agtype, result_2 agtype);
216
- result_1 | result_2
217
- -----------+----------
218
- "Croatia" | "Europe"
289
+ RETURN id(u), u.name, u.region
290
+ $$) AS ("id(u)" agtype, result_1 agtype, result_2 agtype);
291
+ id(u) | result_1 | result_2
292
+ -----------------+-----------+----------
293
+ 844424930132023 | "Croatia" | "Europe"
294
+ 844424930132226 | "Croatia" | "Europe"
295
+ (2 rows)
296
+
297
+ -- There shouldn't be any duplicates
298
+ SELECT * FROM cypher('agload_test_graph', $$return graph_stats('agload_test_graph')$$) as (a agtype);
299
+ a
300
+ ------------------------------------------------------------------------------------------
301
+ {"graph": "agload_test_graph", "num_loaded_edges": 72485, "num_loaded_vertices": 145130}
219
302
(1 row)
220
303
221
304
SELECT drop_graph('agload_test_graph', true);
@@ -236,22 +319,11 @@ NOTICE: graph "agload_test_graph" has been dropped
236
319
--
237
320
-- Test property type conversion
238
321
--
239
- SELECT create_graph('agload_conversion');
240
- NOTICE: graph "agload_conversion" has been created
241
- create_graph
242
- --------------
243
-
244
- (1 row)
245
-
246
322
-- vertex: load as agtype
247
- SELECT create_vlabel('agload_conversion','Person1');
248
- NOTICE: VLabel "Person1" has been created
249
- create_vlabel
250
- ---------------
251
-
252
- (1 row)
253
-
323
+ -- Should create graph and label automatically
254
324
SELECT load_labels_from_file('agload_conversion', 'Person1', 'age_load/conversion_vertices.csv', true, true);
325
+ NOTICE: graph "agload_conversion" has been created
326
+ NOTICE: VLabel "Person1" has been created
255
327
load_labels_from_file
256
328
-----------------------
257
329
0 commit comments