diff --git a/Makefile b/Makefile index 1a176af8e..82405f3b6 100644 --- a/Makefile +++ b/Makefile @@ -110,6 +110,7 @@ REGRESS = scan \ name_validation \ jsonb_operators \ list_comprehension \ + age_meta \ drop srcdir=`pwd` diff --git a/regress/expected/age_meta.out b/regress/expected/age_meta.out new file mode 100644 index 000000000..415eff6b7 --- /dev/null +++ b/regress/expected/age_meta.out @@ -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) + diff --git a/regress/sql/age_meta.sql b/regress/sql/age_meta.sql new file mode 100644 index 000000000..855afcabb --- /dev/null +++ b/regress/sql/age_meta.sql @@ -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); diff --git a/sql/age_meta.sql b/sql/age_meta.sql new file mode 100644 index 000000000..fe8ba0bcb --- /dev/null +++ b/sql/age_meta.sql @@ -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; diff --git a/sql/sql_files b/sql/sql_files index b10f1bcc6..75211ec27 100644 --- a/sql/sql_files +++ b/sql/sql_files @@ -14,3 +14,4 @@ age_string age_trig age_aggregate agtype_typecast +age_meta