Skip to content

Commit 1686c61

Browse files
authored
Add the command graph_stats and improve VLE messaging for load (#1750) (#1755)
Added the command graph_stats. This command will force a reload of the specified graph. This is done to generate current statistics and dump any warning messages about the graph generated during a the load. Cleaned up some messaging from the VLE load process for duplicate vertices and edges. Added regression tests.
1 parent ed1dc3a commit 1686c61

5 files changed

Lines changed: 348 additions & 26 deletions

File tree

age--1.5.0--y.y.y.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,11 @@ RETURNS NULL ON NULL INPUT
117117
PARALLEL SAFE
118118
AS 'MODULE_PATHNAME';
119119

120+
-- this is a new function for graph statistics
121+
CREATE FUNCTION ag_catalog.age_graph_stats(agtype)
122+
RETURNS agtype
123+
LANGUAGE c
124+
STABLE
125+
PARALLEL SAFE
126+
AS 'MODULE_PATHNAME';
127+

regress/expected/age_global_graph.out

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,164 @@ SELECT * FROM cypher('ag_graph_2', $$ MATCH (a) RETURN vertex_stats(a) $$) AS (r
216216
{"id": 1125899906842625, "label": "Person", "in_degree": 0, "out_degree": 0, "self_loops": 0}
217217
(2 rows)
218218

219+
--
220+
-- graph_stats command
221+
--
222+
-- what's in the current graphs?
223+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (result agtype);
224+
result
225+
--------------------------------------------------------------------------
226+
{"graph": "ag_graph_1", "num_loaded_edges": 0, "num_loaded_vertices": 3}
227+
(1 row)
228+
229+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_2') $$) AS (result agtype);
230+
result
231+
--------------------------------------------------------------------------
232+
{"graph": "ag_graph_2", "num_loaded_edges": 0, "num_loaded_vertices": 2}
233+
(1 row)
234+
235+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_3') $$) AS (result agtype);
236+
result
237+
--------------------------------------------------------------------------
238+
{"graph": "ag_graph_3", "num_loaded_edges": 0, "num_loaded_vertices": 1}
239+
(1 row)
240+
241+
-- add some edges
242+
SELECT * FROM cypher('ag_graph_1', $$ CREATE ()-[:knows]->() $$) AS (results agtype);
243+
results
244+
---------
245+
(0 rows)
246+
247+
SELECT * FROM cypher('ag_graph_1', $$ CREATE ()-[:knows]->() $$) AS (results agtype);
248+
results
249+
---------
250+
(0 rows)
251+
252+
SELECT * FROM cypher('ag_graph_1', $$ CREATE ()-[:knows]->() $$) AS (results agtype);
253+
results
254+
---------
255+
(0 rows)
256+
257+
SELECT * FROM cypher('ag_graph_1', $$ CREATE ()-[:knows]->() $$) AS (results agtype);
258+
results
259+
---------
260+
(0 rows)
261+
262+
-- what is there now?
263+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (result agtype);
264+
result
265+
---------------------------------------------------------------------------
266+
{"graph": "ag_graph_1", "num_loaded_edges": 4, "num_loaded_vertices": 11}
267+
(1 row)
268+
269+
-- add some more
270+
SELECT * FROM cypher('ag_graph_1', $$ MATCH (u)-[]->(v) SET u.id = id(u)
271+
SET v.id = id(v)
272+
SET u.name = 'u'
273+
SET v.name = 'v'
274+
RETURN u,v $$) AS (u agtype, v agtype);
275+
u | v
276+
--------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------
277+
{"id": 281474976710659, "label": "", "properties": {"id": 281474976710659, "name": "u"}}::vertex | {"id": 281474976710660, "label": "", "properties": {"id": 281474976710660, "name": "v"}}::vertex
278+
{"id": 281474976710661, "label": "", "properties": {"id": 281474976710661, "name": "u"}}::vertex | {"id": 281474976710662, "label": "", "properties": {"id": 281474976710662, "name": "v"}}::vertex
279+
{"id": 281474976710663, "label": "", "properties": {"id": 281474976710663, "name": "u"}}::vertex | {"id": 281474976710664, "label": "", "properties": {"id": 281474976710664, "name": "v"}}::vertex
280+
{"id": 281474976710665, "label": "", "properties": {"id": 281474976710665, "name": "u"}}::vertex | {"id": 281474976710666, "label": "", "properties": {"id": 281474976710666, "name": "v"}}::vertex
281+
(4 rows)
282+
283+
SELECT * FROM cypher('ag_graph_1', $$ MATCH (u)-[]->(v) MERGE (v)-[:stalks]->(u) $$) AS (result agtype);
284+
result
285+
--------
286+
(0 rows)
287+
288+
SELECT * FROM cypher('ag_graph_1', $$ MATCH (u)-[e]->(v) RETURN u, e, v $$) AS (u agtype, e agtype, v agtype);
289+
u | e | v
290+
--------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------
291+
{"id": 281474976710660, "label": "", "properties": {"id": 281474976710660, "name": "v"}}::vertex | {"id": 1407374883553281, "label": "stalks", "end_id": 281474976710659, "start_id": 281474976710660, "properties": {}}::edge | {"id": 281474976710659, "label": "", "properties": {"id": 281474976710659, "name": "u"}}::vertex
292+
{"id": 281474976710659, "label": "", "properties": {"id": 281474976710659, "name": "u"}}::vertex | {"id": 1125899906842625, "label": "knows", "end_id": 281474976710660, "start_id": 281474976710659, "properties": {}}::edge | {"id": 281474976710660, "label": "", "properties": {"id": 281474976710660, "name": "v"}}::vertex
293+
{"id": 281474976710662, "label": "", "properties": {"id": 281474976710662, "name": "v"}}::vertex | {"id": 1407374883553282, "label": "stalks", "end_id": 281474976710661, "start_id": 281474976710662, "properties": {}}::edge | {"id": 281474976710661, "label": "", "properties": {"id": 281474976710661, "name": "u"}}::vertex
294+
{"id": 281474976710661, "label": "", "properties": {"id": 281474976710661, "name": "u"}}::vertex | {"id": 1125899906842626, "label": "knows", "end_id": 281474976710662, "start_id": 281474976710661, "properties": {}}::edge | {"id": 281474976710662, "label": "", "properties": {"id": 281474976710662, "name": "v"}}::vertex
295+
{"id": 281474976710664, "label": "", "properties": {"id": 281474976710664, "name": "v"}}::vertex | {"id": 1407374883553283, "label": "stalks", "end_id": 281474976710663, "start_id": 281474976710664, "properties": {}}::edge | {"id": 281474976710663, "label": "", "properties": {"id": 281474976710663, "name": "u"}}::vertex
296+
{"id": 281474976710663, "label": "", "properties": {"id": 281474976710663, "name": "u"}}::vertex | {"id": 1125899906842627, "label": "knows", "end_id": 281474976710664, "start_id": 281474976710663, "properties": {}}::edge | {"id": 281474976710664, "label": "", "properties": {"id": 281474976710664, "name": "v"}}::vertex
297+
{"id": 281474976710666, "label": "", "properties": {"id": 281474976710666, "name": "v"}}::vertex | {"id": 1407374883553284, "label": "stalks", "end_id": 281474976710665, "start_id": 281474976710666, "properties": {}}::edge | {"id": 281474976710665, "label": "", "properties": {"id": 281474976710665, "name": "u"}}::vertex
298+
{"id": 281474976710665, "label": "", "properties": {"id": 281474976710665, "name": "u"}}::vertex | {"id": 1125899906842628, "label": "knows", "end_id": 281474976710666, "start_id": 281474976710665, "properties": {}}::edge | {"id": 281474976710666, "label": "", "properties": {"id": 281474976710666, "name": "v"}}::vertex
299+
(8 rows)
300+
301+
-- what is there now?
302+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (result agtype);
303+
result
304+
---------------------------------------------------------------------------
305+
{"graph": "ag_graph_1", "num_loaded_edges": 8, "num_loaded_vertices": 11}
306+
(1 row)
307+
308+
-- remove some vertices
309+
SELECT * FROM ag_graph_1._ag_label_vertex;
310+
id | properties
311+
-----------------+--------------------------------------
312+
281474976710657 | {}
313+
281474976710658 | {}
314+
281474976710659 | {"id": 281474976710659, "name": "u"}
315+
281474976710660 | {"id": 281474976710660, "name": "v"}
316+
281474976710661 | {"id": 281474976710661, "name": "u"}
317+
281474976710662 | {"id": 281474976710662, "name": "v"}
318+
281474976710663 | {"id": 281474976710663, "name": "u"}
319+
281474976710664 | {"id": 281474976710664, "name": "v"}
320+
281474976710665 | {"id": 281474976710665, "name": "u"}
321+
281474976710666 | {"id": 281474976710666, "name": "v"}
322+
844424930131969 | {}
323+
(11 rows)
324+
325+
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710661';
326+
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710662';
327+
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710664';
328+
SELECT * FROM ag_graph_1._ag_label_vertex;
329+
id | properties
330+
-----------------+--------------------------------------
331+
281474976710657 | {}
332+
281474976710658 | {}
333+
281474976710659 | {"id": 281474976710659, "name": "u"}
334+
281474976710660 | {"id": 281474976710660, "name": "v"}
335+
281474976710663 | {"id": 281474976710663, "name": "u"}
336+
281474976710665 | {"id": 281474976710665, "name": "u"}
337+
281474976710666 | {"id": 281474976710666, "name": "v"}
338+
844424930131969 | {}
339+
(8 rows)
340+
341+
SELECT * FROM ag_graph_1._ag_label_edge;
342+
id | start_id | end_id | properties
343+
------------------+-----------------+-----------------+------------
344+
1125899906842625 | 281474976710659 | 281474976710660 | {}
345+
1125899906842626 | 281474976710661 | 281474976710662 | {}
346+
1125899906842627 | 281474976710663 | 281474976710664 | {}
347+
1125899906842628 | 281474976710665 | 281474976710666 | {}
348+
1407374883553281 | 281474976710660 | 281474976710659 | {}
349+
1407374883553282 | 281474976710662 | 281474976710661 | {}
350+
1407374883553283 | 281474976710664 | 281474976710663 | {}
351+
1407374883553284 | 281474976710666 | 281474976710665 | {}
352+
(8 rows)
353+
354+
-- there should be warning messages
355+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (result agtype);
356+
WARNING: edge: [id: 1125899906842626, start: 281474976710661, end: 281474976710662, label: knows] start and end vertices not found
357+
WARNING: ignored malformed or dangling edge
358+
WARNING: edge: [id: 1125899906842627, start: 281474976710663, end: 281474976710664, label: knows] end vertex not found
359+
WARNING: ignored malformed or dangling edge
360+
WARNING: edge: [id: 1407374883553282, start: 281474976710662, end: 281474976710661, label: stalks] start and end vertices not found
361+
WARNING: ignored malformed or dangling edge
362+
WARNING: edge: [id: 1407374883553283, start: 281474976710664, end: 281474976710663, label: stalks] start vertex not found
363+
WARNING: ignored malformed or dangling edge
364+
result
365+
--------------------------------------------------------------------------
366+
{"graph": "ag_graph_1", "num_loaded_edges": 8, "num_loaded_vertices": 8}
367+
(1 row)
368+
219369
--drop graphs
220370
SELECT * FROM drop_graph('ag_graph_1', true);
221-
NOTICE: drop cascades to 3 other objects
371+
NOTICE: drop cascades to 5 other objects
222372
DETAIL: drop cascades to table ag_graph_1._ag_label_vertex
223373
drop cascades to table ag_graph_1._ag_label_edge
224374
drop cascades to table ag_graph_1.vertex1
375+
drop cascades to table ag_graph_1.knows
376+
drop cascades to table ag_graph_1.stalks
225377
NOTICE: graph "ag_graph_1" has been dropped
226378
drop_graph
227379
------------

regress/sql/age_global_graph.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,40 @@ SELECT * FROM cypher('ag_graph_1', $$ MATCH (n) RETURN vertex_stats(n) $$) AS (r
9090
--should return 1 vertice and 1 label
9191
SELECT * FROM cypher('ag_graph_2', $$ MATCH (a) RETURN vertex_stats(a) $$) AS (result agtype);
9292

93+
--
94+
-- graph_stats command
95+
--
96+
-- what's in the current graphs?
97+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (result agtype);
98+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_2') $$) AS (result agtype);
99+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_3') $$) AS (result agtype);
100+
-- add some edges
101+
SELECT * FROM cypher('ag_graph_1', $$ CREATE ()-[:knows]->() $$) AS (results agtype);
102+
SELECT * FROM cypher('ag_graph_1', $$ CREATE ()-[:knows]->() $$) AS (results agtype);
103+
SELECT * FROM cypher('ag_graph_1', $$ CREATE ()-[:knows]->() $$) AS (results agtype);
104+
SELECT * FROM cypher('ag_graph_1', $$ CREATE ()-[:knows]->() $$) AS (results agtype);
105+
-- what is there now?
106+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (result agtype);
107+
-- add some more
108+
SELECT * FROM cypher('ag_graph_1', $$ MATCH (u)-[]->(v) SET u.id = id(u)
109+
SET v.id = id(v)
110+
SET u.name = 'u'
111+
SET v.name = 'v'
112+
RETURN u,v $$) AS (u agtype, v agtype);
113+
SELECT * FROM cypher('ag_graph_1', $$ MATCH (u)-[]->(v) MERGE (v)-[:stalks]->(u) $$) AS (result agtype);
114+
SELECT * FROM cypher('ag_graph_1', $$ MATCH (u)-[e]->(v) RETURN u, e, v $$) AS (u agtype, e agtype, v agtype);
115+
-- what is there now?
116+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (result agtype);
117+
-- remove some vertices
118+
SELECT * FROM ag_graph_1._ag_label_vertex;
119+
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710661';
120+
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710662';
121+
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710664';
122+
SELECT * FROM ag_graph_1._ag_label_vertex;
123+
SELECT * FROM ag_graph_1._ag_label_edge;
124+
-- there should be warning messages
125+
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (result agtype);
126+
93127
--drop graphs
94128

95129
SELECT * FROM drop_graph('ag_graph_1', true);

sql/agtype_typecast.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ CREATE FUNCTION ag_catalog.age_vertex_stats(agtype, agtype)
196196
PARALLEL SAFE
197197
AS 'MODULE_PATHNAME';
198198

199+
CREATE FUNCTION ag_catalog.age_graph_stats(agtype)
200+
RETURNS agtype
201+
LANGUAGE c
202+
STABLE
203+
PARALLEL SAFE
204+
AS 'MODULE_PATHNAME';
205+
199206
CREATE FUNCTION ag_catalog.age_delete_global_graphs(agtype)
200207
RETURNS boolean
201208
LANGUAGE c

0 commit comments

Comments
 (0)