/* * 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; -- -- create_graph(), drop_label(), and drop_graph() tests -- SELECT create_graph('g'); NOTICE: graph "g" has been created create_graph -------------- (1 row) SELECT * FROM ag_graph WHERE name = 'g'; name | namespace ------+----------- g | g (1 row) -- create a label to test drop_label() SELECT * FROM cypher('g', $$CREATE (:l)$$) AS r(a agtype); a --- (0 rows) -- test drop_label() SELECT drop_label('g', 'l'); NOTICE: label "g"."l" has been dropped drop_label ------------ (1 row) -- create a label to test drop_graph() SELECT * FROM cypher('g', $$CREATE (:v)$$) AS r(a agtype); a --- (0 rows) -- DROP SCHEMA ... CASCADE should fail DROP SCHEMA g CASCADE; NOTICE: drop cascades to 4 other objects DETAIL: drop cascades to sequence g._label_id_seq drop cascades to table g._ag_label_vertex drop cascades to table g._ag_label_edge drop cascades to table g.v ERROR: table "v" is for label "v" -- DROP TABLE ... should fail DROP TABLE g.v; ERROR: table "v" is for label "v" -- should fail (cascade = false) SELECT drop_graph('g'); ERROR: cannot drop schema g because other objects depend on it DETAIL: table g._ag_label_vertex depends on schema g table g._ag_label_edge depends on schema g table g.v depends on schema g HINT: Use DROP ... CASCADE to drop the dependent objects too. SELECT drop_graph('g', true); NOTICE: drop cascades to 3 other objects DETAIL: drop cascades to table g._ag_label_vertex drop cascades to table g._ag_label_edge drop cascades to table g.v NOTICE: graph "g" has been dropped drop_graph ------------ (1 row) SELECT count(*) FROM ag_graph WHERE name = 'g'; count ------- 0 (1 row) SELECT count(*) FROM pg_namespace WHERE nspname = 'g'; count ------- 0 (1 row) -- invalid cases SELECT create_graph(NULL); ERROR: graph name must not be NULL SELECT drop_graph(NULL); ERROR: graph name must not be NULL -- -- alter_graph() RENAME function tests -- -- create 2 graphs for test. SELECT create_graph('GraphA'); NOTICE: graph "GraphA" has been created create_graph -------------- (1 row) SELECT create_graph('GraphB'); NOTICE: graph "GraphB" has been created create_graph -------------- (1 row) -- Show GraphA's construction to verify case is preserved. SELECT * FROM ag_graph WHERE name = 'GraphA'; name | namespace --------+----------- GraphA | "GraphA" (1 row) SELECT nspname FROM pg_namespace WHERE nspname = 'GraphA'; nspname --------- GraphA (1 row) -- Rename GraphA to GraphX. SELECT alter_graph('GraphA', 'RENAME', 'GraphX'); NOTICE: graph "GraphA" renamed to "GraphX" alter_graph ------------- (1 row) -- Show GraphX's construction to verify case is preserved. SELECT * FROM ag_graph WHERE name = 'GraphX'; name | namespace --------+----------- GraphX | "GraphX" (1 row) SELECT nspname FROM pg_namespace WHERE nspname = 'GraphX'; nspname --------- GraphX (1 row) -- Verify there isn't a graph GraphA anymore. SELECT * FROM ag_graph WHERE name = 'GraphA'; name | namespace ------+----------- (0 rows) SELECT * FROM pg_namespace WHERE nspname = 'GraphA'; nspname | nspowner | nspacl ---------+----------+-------- (0 rows) -- Sanity check that graphx does not exist - should return 0. SELECT count(*) FROM ag_graph where name = 'graphx'; count ------- 0 (1 row) -- Verify case sensitivity (graphx does not exist, but GraphX does) - should fail. SELECT alter_graph('graphx', 'RENAME', 'GRAPHX'); ERROR: graph "graphx" does not exist -- Checks for collisions (GraphB already exists) - should fail. SELECT alter_graph('GraphX', 'RENAME', 'GraphB'); ERROR: schema "GraphB" already exists -- Remove graphs. SELECT drop_graph('GraphX', true); NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to table "GraphX"._ag_label_vertex drop cascades to table "GraphX"._ag_label_edge NOTICE: graph "GraphX" has been dropped drop_graph ------------ (1 row) SELECT drop_graph('GraphB', true); NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to table "GraphB"._ag_label_vertex drop cascades to table "GraphB"._ag_label_edge NOTICE: graph "GraphB" has been dropped drop_graph ------------ (1 row) -- Verify that renaming a graph that does not exist fails. SELECT alter_graph('GraphB', 'RENAME', 'GraphA'); ERROR: graph "GraphB" does not exist -- Verify NULL input checks. SELECT alter_graph(NULL, 'RENAME', 'GraphA'); ERROR: graph_name must not be NULL SELECT alter_graph('GraphB', NULL, 'GraphA'); ERROR: operation must not be NULL SELECT alter_graph('GraphB', 'RENAME', NULL); ERROR: new_value must not be NULL -- Verify invalid input check for operation parameter. SELECT alter_graph('GraphB', 'DUMMY', 'GraphA'); ERROR: invalid operation "DUMMY" HINT: valid operations: RENAME -- -- label id test -- SELECT create_graph('g'); NOTICE: graph "g" has been created create_graph -------------- (1 row) -- label id starts from 1 SELECT * FROM cypher('g', $$CREATE (:v1)$$) AS r(a agtype); a --- (0 rows) SELECT name, id, kind, relation FROM ag_label; name | id | kind | relation ------------------+----+------+-------------------- _ag_label_vertex | 1 | v | g._ag_label_vertex _ag_label_edge | 2 | e | g._ag_label_edge v1 | 3 | v | g.v1 (3 rows) -- skip label id 2 to test the logic that gets an unused label id after cycle SELECT nextval('g._label_id_seq'); nextval --------- 4 (1 row) -- label id is now 3 SELECT * FROM cypher('g', $$CREATE (:v3)$$) as r(a agtype); a --- (0 rows) SELECT name, id, kind, relation FROM ag_label; name | id | kind | relation ------------------+----+------+-------------------- _ag_label_vertex | 1 | v | g._ag_label_vertex _ag_label_edge | 2 | e | g._ag_label_edge v1 | 3 | v | g.v1 v3 | 5 | v | g.v3 (4 rows) -- to use 65535 as the next label id, set label id to 65534 SELECT setval('g._label_id_seq', 65534); setval -------- 65534 (1 row) -- label id is now 65535 SELECT * FROM cypher('g', $$CREATE (:v65535)$$) as r(a agtype); a --- (0 rows) SELECT name, id, kind, relation FROM ag_label; name | id | kind | relation ------------------+-------+------+-------------------- _ag_label_vertex | 1 | v | g._ag_label_vertex _ag_label_edge | 2 | e | g._ag_label_edge v1 | 3 | v | g.v1 v3 | 5 | v | g.v3 v65535 | 65535 | v | g.v65535 (5 rows) -- after cycle, label id is now 2 SELECT * FROM cypher('g', $$CREATE (:v2)$$) as r(a agtype); a --- (0 rows) SELECT name, id, kind, relation FROM ag_label; name | id | kind | relation ------------------+-------+------+-------------------- _ag_label_vertex | 1 | v | g._ag_label_vertex _ag_label_edge | 2 | e | g._ag_label_edge v1 | 3 | v | g.v1 v3 | 5 | v | g.v3 v65535 | 65535 | v | g.v65535 v2 | 4 | v | g.v2 (6 rows) SELECT drop_graph('g', true); NOTICE: drop cascades to 6 other objects DETAIL: drop cascades to table g._ag_label_vertex drop cascades to table g._ag_label_edge drop cascades to table g.v1 drop cascades to table g.v3 drop cascades to table g.v65535 drop cascades to table g.v2 NOTICE: graph "g" has been dropped drop_graph ------------ (1 row) -- create labels SELECT create_graph('g'); NOTICE: graph "g" has been created create_graph -------------- (1 row) SELECT create_vlabel('g', 'n'); NOTICE: VLabel "n" has been created create_vlabel --------------- (1 row) SELECT create_elabel('g', 'r'); NOTICE: ELabel "r" has been created create_elabel --------------- (1 row) -- check if labels have been created or not SELECT name, id, kind, relation FROM ag_label; name | id | kind | relation ------------------+----+------+-------------------- _ag_label_vertex | 1 | v | g._ag_label_vertex _ag_label_edge | 2 | e | g._ag_label_edge n | 3 | v | g.n r | 4 | e | g.r (4 rows) -- try to create duplicate labels SELECT create_vlabel('g', 'n'); ERROR: label "n" already exists SELECT create_elabel('g', 'r'); ERROR: label "r" already exists -- remove the labels that have been created SELECT drop_label('g', 'n', false); NOTICE: label "g"."n" has been dropped drop_label ------------ (1 row) SELECT drop_label('g', 'r', false); NOTICE: label "g"."r" has been dropped drop_label ------------ (1 row) -- check if labels have been deleted or not SELECT name, id, kind, relation FROM ag_label; name | id | kind | relation ------------------+----+------+-------------------- _ag_label_vertex | 1 | v | g._ag_label_vertex _ag_label_edge | 2 | e | g._ag_label_edge (2 rows) -- try to remove labels that is not there SELECT drop_label('g', 'n'); ERROR: label "n" does not exist SELECT drop_label('g', 'r'); ERROR: label "r" does not exist -- Trying to call the functions with label null SELECT create_vlabel('g', NULL); ERROR: label name must not be NULL SELECT create_elabel('g', NULL); ERROR: label name must not be NULL -- Trying to call the functions with graph null SELECT create_vlabel(NULL, 'n'); ERROR: graph name must not be NULL SELECT create_elabel(NULL, 'r'); ERROR: graph name must not be NULL -- Trying to call the functions with both null SELECT create_vlabel(NULL, NULL); ERROR: graph name must not be NULL SELECT create_elabel(NULL, NULL); ERROR: graph name must not be NULL -- dropping the graph SELECT drop_graph('g', true); NOTICE: drop cascades to 2 other objects DETAIL: drop cascades to table g._ag_label_vertex drop cascades to table g._ag_label_edge NOTICE: graph "g" has been dropped drop_graph ------------ (1 row)