Skip to content

Commit bf457f1

Browse files
Inital version of AGE Meta
1 parent 438f551 commit bf457f1

File tree

5 files changed

+266
-0
lines changed

5 files changed

+266
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ REGRESS = scan \
110110
name_validation \
111111
jsonb_operators \
112112
list_comprehension \
113+
age_meta \
113114
drop
114115

115116
srcdir=`pwd`

regress/expected/age_meta.out

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
LOAD 'age';
21+
SET search_path TO ag_catalog;
22+
SELECT create_graph('meta_test_graph');
23+
NOTICE: graph "meta_test_graph" has been created
24+
create_graph
25+
--------------
26+
27+
(1 row)
28+
29+
SELECT list_graphs();
30+
list_graphs
31+
-----------------
32+
meta_test_graph
33+
(1 row)
34+
35+
SELECT list_vertex_labels('meta_test_graph');
36+
list_vertex_labels
37+
--------------------
38+
_ag_label_vertex
39+
(1 row)
40+
41+
SELECT count_vertex_labels('meta_test_graph');
42+
count_vertex_labels
43+
---------------------
44+
1
45+
(1 row)
46+
47+
SELECT create_vlabel('meta_test_graph','vertex_a');
48+
NOTICE: VLabel "vertex_a" has been created
49+
create_vlabel
50+
---------------
51+
52+
(1 row)
53+
54+
SELECT list_vertex_labels('meta_test_graph');
55+
list_vertex_labels
56+
--------------------
57+
_ag_label_vertex
58+
vertex_a
59+
(2 rows)
60+
61+
SELECT count_vertex_labels('meta_test_graph');
62+
count_vertex_labels
63+
---------------------
64+
2
65+
(1 row)
66+
67+
SELECT list_edge_labels('meta_test_graph');
68+
list_edge_labels
69+
------------------
70+
_ag_label_edge
71+
(1 row)
72+
73+
SELECT count_edge_labels('meta_test_graph');
74+
count_edge_labels
75+
-------------------
76+
1
77+
(1 row)
78+
79+
SELECT create_elabel('meta_test_graph','edge_a');
80+
NOTICE: ELabel "edge_a" has been created
81+
create_elabel
82+
---------------
83+
84+
(1 row)
85+
86+
SELECT list_edge_labels('meta_test_graph');
87+
list_edge_labels
88+
------------------
89+
_ag_label_edge
90+
edge_a
91+
(2 rows)
92+
93+
SELECT count_edge_labels('meta_test_graph');
94+
count_edge_labels
95+
-------------------
96+
2
97+
(1 row)
98+
99+
SELECT drop_graph('meta_test_graph', true);
100+
NOTICE: drop cascades to 4 other objects
101+
DETAIL: drop cascades to table meta_test_graph._ag_label_vertex
102+
drop cascades to table meta_test_graph._ag_label_edge
103+
drop cascades to table meta_test_graph.vertex_a
104+
drop cascades to table meta_test_graph.edge_a
105+
NOTICE: graph "meta_test_graph" has been dropped
106+
drop_graph
107+
------------
108+
109+
(1 row)
110+

regress/sql/age_meta.sql

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
LOAD 'age';
21+
SET search_path TO ag_catalog;
22+
23+
SELECT create_graph('meta_test_graph');
24+
25+
SELECT list_graphs();
26+
27+
SELECT list_vertex_labels('meta_test_graph');
28+
SELECT count_vertex_labels('meta_test_graph');
29+
SELECT create_vlabel('meta_test_graph','vertex_a');
30+
SELECT list_vertex_labels('meta_test_graph');
31+
SELECT count_vertex_labels('meta_test_graph');
32+
33+
SELECT list_edge_labels('meta_test_graph');
34+
SELECT count_edge_labels('meta_test_graph');
35+
SELECT create_elabel('meta_test_graph','edge_a');
36+
SELECT list_edge_labels('meta_test_graph');
37+
SELECT count_edge_labels('meta_test_graph');
38+
39+
SELECT drop_graph('meta_test_graph', true);

sql/age_meta.sql

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
DROP FUNCTION IF EXISTS ag_catalog.list_graphs;
21+
22+
CREATE OR REPLACE FUNCTION ag_catalog.list_graphs()
23+
RETURNS TABLE (graph_name name)
24+
LANGUAGE plpgsql
25+
IMMUTABLE
26+
RETURNS NULL ON NULL INPUT
27+
AS $$
28+
BEGIN
29+
RETURN QUERY EXECUTE 'SELECT name FROM ag_catalog.ag_graph';
30+
END $$;
31+
32+
DROP FUNCTION IF EXISTS ag_catalog.list_vertex_labels;
33+
34+
CREATE OR REPLACE FUNCTION ag_catalog.list_vertex_labels(graph_name name)
35+
RETURNS TABLE (label_name name)
36+
LANGUAGE plpgsql
37+
IMMUTABLE
38+
RETURNS NULL ON NULL INPUT
39+
AS $$
40+
DECLARE
41+
stmt TEXT;
42+
BEGIN
43+
stmt = FORMAT('SELECT ag_catalog.ag_label.name FROM ag_catalog.ag_label ' ||
44+
'INNER JOIN ag_catalog.ag_graph ' ||
45+
'ON ag_catalog.ag_label.graph = ag_catalog.ag_graph.graphid ' ||
46+
'WHERE kind = ''v'' AND ag_catalog.ag_graph.name = %L', graph_name);
47+
RETURN QUERY EXECUTE stmt;
48+
49+
END $$;
50+
51+
DROP FUNCTION IF EXISTS ag_catalog.count_vertex_labels;
52+
53+
CREATE OR REPLACE FUNCTION ag_catalog.count_vertex_labels(graph_name name)
54+
RETURNS TABLE (total_vertex_labels bigint)
55+
LANGUAGE plpgsql
56+
IMMUTABLE
57+
RETURNS NULL ON NULL INPUT
58+
AS $$
59+
DECLARE
60+
stmt TEXT;
61+
BEGIN
62+
stmt = FORMAT('SELECT COUNT(ag_catalog.ag_label.name) AS total_vertex_labels ' ||
63+
'FROM ag_catalog.ag_label INNER JOIN ag_catalog.ag_graph ' ||
64+
'ON ag_catalog.ag_label.graph = ag_catalog.ag_graph.graphid ' ||
65+
'WHERE kind = ''v'' AND ag_catalog.ag_graph.name = %L', graph_name);
66+
RETURN QUERY EXECUTE stmt;
67+
68+
END $$;
69+
70+
71+
DROP FUNCTION IF EXISTS ag_catalog.list_edge_labels;
72+
73+
CREATE OR REPLACE FUNCTION ag_catalog.list_edge_labels(graph_name name)
74+
RETURNS TABLE (label_name name)
75+
LANGUAGE plpgsql
76+
IMMUTABLE
77+
RETURNS NULL ON NULL INPUT
78+
AS $$
79+
DECLARE
80+
stmt TEXT;
81+
BEGIN
82+
83+
stmt = FORMAT('SELECT ag_catalog.ag_label.name FROM ag_catalog.ag_label ' ||
84+
'INNER JOIN ag_catalog.ag_graph ' ||
85+
'ON ag_catalog.ag_label.graph = ag_catalog.ag_graph.graphid ' ||
86+
'WHERE kind = ''e'' AND ag_catalog.ag_graph.name = %L', graph_name);
87+
RETURN QUERY EXECUTE stmt;
88+
89+
END $$;
90+
91+
DROP FUNCTION IF EXISTS ag_catalog.count_edge_labels;
92+
93+
CREATE OR REPLACE FUNCTION ag_catalog.count_edge_labels(graph_name name)
94+
RETURNS TABLE (total_edges_labels bigint)
95+
LANGUAGE plpgsql
96+
IMMUTABLE
97+
RETURNS NULL ON NULL INPUT
98+
AS $$
99+
DECLARE
100+
stmt TEXT;
101+
BEGIN
102+
103+
stmt = FORMAT('SELECT COUNT(ag_catalog.ag_label.name) AS total_edges_labels ' ||
104+
'FROM ag_catalog.ag_label INNER JOIN ag_catalog.ag_graph ' ||
105+
'ON ag_catalog.ag_label.graph = ag_catalog.ag_graph.graphid ' ||
106+
'WHERE kind = ''e'' AND ag_catalog.ag_graph.name = %L', graph_name);
107+
RETURN QUERY EXECUTE stmt;
108+
109+
END $$;
110+
111+
CREATE FUNCTION mul(numeric, numeric) RETURNS numeric
112+
AS 'select $1*$2;'
113+
LANGUAGE SQL
114+
IMMUTABLE
115+
RETURNS NULL ON NULL INPUT;

sql/sql_files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ age_string
1414
age_trig
1515
age_aggregate
1616
agtype_typecast
17+
age_meta

0 commit comments

Comments
 (0)