|
| 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; |
0 commit comments