Skip to content

Commit

Permalink
Inital version of AGE Meta
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadshoaib committed Jan 10, 2024
1 parent f10bef3 commit a8a0ebc
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ REGRESS = scan \
graph_generation \
name_validation \
jsonb_operators \
age_meta \
drop

srcdir=`pwd`
Expand Down
110 changes: 110 additions & 0 deletions regress/expected/age_meta.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

LOAD 'age';
SET search_path TO ag_catalog;
SELECT create_graph('meta_test_graph');
NOTICE: graph "meta_test_graph" has been created
create_graph
--------------

(1 row)

SELECT list_graphs();
list_graphs
-----------------
meta_test_graph
(1 row)

SELECT list_vertex_labels('meta_test_graph');
list_vertex_labels
--------------------
_ag_label_vertex
(1 row)

SELECT count_vertex_labels('meta_test_graph');
count_vertex_labels
---------------------
1
(1 row)

SELECT create_vlabel('meta_test_graph','vertex_a');
NOTICE: VLabel "vertex_a" has been created
create_vlabel
---------------

(1 row)

SELECT list_vertex_labels('meta_test_graph');
list_vertex_labels
--------------------
_ag_label_vertex
vertex_a
(2 rows)

SELECT count_vertex_labels('meta_test_graph');
count_vertex_labels
---------------------
2
(1 row)

SELECT list_edge_labels('meta_test_graph');
list_edge_labels
------------------
_ag_label_edge
(1 row)

SELECT count_edge_labels('meta_test_graph');
count_edge_labels
-------------------
1
(1 row)

SELECT create_elabel('meta_test_graph','edge_a');
NOTICE: ELabel "edge_a" has been created
create_elabel
---------------

(1 row)

SELECT list_edge_labels('meta_test_graph');
list_edge_labels
------------------
_ag_label_edge
edge_a
(2 rows)

SELECT count_edge_labels('meta_test_graph');
count_edge_labels
-------------------
2
(1 row)

SELECT drop_graph('meta_test_graph', true);
NOTICE: drop cascades to 4 other objects
DETAIL: drop cascades to table meta_test_graph._ag_label_vertex
drop cascades to table meta_test_graph._ag_label_edge
drop cascades to table meta_test_graph.vertex_a
drop cascades to table meta_test_graph.edge_a
NOTICE: graph "meta_test_graph" has been dropped
drop_graph
------------

(1 row)

39 changes: 39 additions & 0 deletions regress/sql/age_meta.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

LOAD 'age';
SET search_path TO ag_catalog;

SELECT create_graph('meta_test_graph');

SELECT list_graphs();

SELECT list_vertex_labels('meta_test_graph');
SELECT count_vertex_labels('meta_test_graph');
SELECT create_vlabel('meta_test_graph','vertex_a');
SELECT list_vertex_labels('meta_test_graph');
SELECT count_vertex_labels('meta_test_graph');

SELECT list_edge_labels('meta_test_graph');
SELECT count_edge_labels('meta_test_graph');
SELECT create_elabel('meta_test_graph','edge_a');
SELECT list_edge_labels('meta_test_graph');
SELECT count_edge_labels('meta_test_graph');

SELECT drop_graph('meta_test_graph', true);
115 changes: 115 additions & 0 deletions sql/age_meta.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

DROP FUNCTION IF EXISTS ag_catalog.list_graphs;

CREATE OR REPLACE FUNCTION ag_catalog.list_graphs()
RETURNS TABLE (graph_name name)
LANGUAGE plpgsql
IMMUTABLE
RETURNS NULL ON NULL INPUT
AS $$
BEGIN
RETURN QUERY EXECUTE 'SELECT name FROM ag_catalog.ag_graph';
END $$;

DROP FUNCTION IF EXISTS ag_catalog.list_vertex_labels;

CREATE OR REPLACE FUNCTION ag_catalog.list_vertex_labels(graph_name name)
RETURNS TABLE (label_name name)
LANGUAGE plpgsql
IMMUTABLE
RETURNS NULL ON NULL INPUT
AS $$
DECLARE
stmt TEXT;
BEGIN
stmt = FORMAT('SELECT ag_catalog.ag_label.name FROM ag_catalog.ag_label ' ||
'INNER JOIN ag_catalog.ag_graph ' ||
'ON ag_catalog.ag_label.graph = ag_catalog.ag_graph.graphid ' ||
'WHERE kind = ''v'' AND ag_catalog.ag_graph.name = %L', graph_name);
RETURN QUERY EXECUTE stmt;

END $$;

DROP FUNCTION IF EXISTS ag_catalog.count_vertex_labels;

CREATE OR REPLACE FUNCTION ag_catalog.count_vertex_labels(graph_name name)
RETURNS TABLE (total_vertex_labels bigint)
LANGUAGE plpgsql
IMMUTABLE
RETURNS NULL ON NULL INPUT
AS $$
DECLARE
stmt TEXT;
BEGIN
stmt = FORMAT('SELECT COUNT(ag_catalog.ag_label.name) AS total_vertex_labels ' ||
'FROM ag_catalog.ag_label INNER JOIN ag_catalog.ag_graph ' ||
'ON ag_catalog.ag_label.graph = ag_catalog.ag_graph.graphid ' ||
'WHERE kind = ''v'' AND ag_catalog.ag_graph.name = %L', graph_name);
RETURN QUERY EXECUTE stmt;

END $$;


DROP FUNCTION IF EXISTS ag_catalog.list_edge_labels;

CREATE OR REPLACE FUNCTION ag_catalog.list_edge_labels(graph_name name)
RETURNS TABLE (label_name name)
LANGUAGE plpgsql
IMMUTABLE
RETURNS NULL ON NULL INPUT
AS $$
DECLARE
stmt TEXT;
BEGIN

stmt = FORMAT('SELECT ag_catalog.ag_label.name FROM ag_catalog.ag_label ' ||
'INNER JOIN ag_catalog.ag_graph ' ||
'ON ag_catalog.ag_label.graph = ag_catalog.ag_graph.graphid ' ||
'WHERE kind = ''e'' AND ag_catalog.ag_graph.name = %L', graph_name);
RETURN QUERY EXECUTE stmt;

END $$;

DROP FUNCTION IF EXISTS ag_catalog.count_edge_labels;

CREATE OR REPLACE FUNCTION ag_catalog.count_edge_labels(graph_name name)
RETURNS TABLE (total_edges_labels bigint)
LANGUAGE plpgsql
IMMUTABLE
RETURNS NULL ON NULL INPUT
AS $$
DECLARE
stmt TEXT;
BEGIN

stmt = FORMAT('SELECT COUNT(ag_catalog.ag_label.name) AS total_edges_labels ' ||
'FROM ag_catalog.ag_label INNER JOIN ag_catalog.ag_graph ' ||
'ON ag_catalog.ag_label.graph = ag_catalog.ag_graph.graphid ' ||
'WHERE kind = ''e'' AND ag_catalog.ag_graph.name = %L', graph_name);
RETURN QUERY EXECUTE stmt;

END $$;

CREATE FUNCTION mul(numeric, numeric) RETURNS numeric
AS 'select $1*$2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
1 change: 1 addition & 0 deletions sql/sql_files
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ age_string
age_trig
age_aggregate
agtype_typecast
age_meta

0 comments on commit a8a0ebc

Please sign in to comment.