This is an automated email from the ASF dual-hosted git repository. okislal pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/madlib.git
commit 5e05f25e5ab93ff56121336c976523e248876e0a Author: Orhan Kislal <[email protected]> AuthorDate: Tue Mar 10 19:43:43 2020 -0400 Graph: Update tests to use pg_temp JIRA: MADLIB-1411 This commit updates graph dev check tests to use pg_temp instead of public schema. It also updates the rename_table function since altering a tables schema is not allowed if the table is in a temporary schema. Closes #486 --- src/ports/postgres/modules/graph/test/apsp.sql_in | 6 ++--- src/ports/postgres/modules/graph/test/bfs.sql_in | 4 +-- src/ports/postgres/modules/graph/test/hits.sql_in | 4 +-- .../postgres/modules/graph/test/measures.sql_in | 31 +++++++++------------- .../postgres/modules/graph/test/pagerank.sql_in | 4 +-- src/ports/postgres/modules/graph/test/sssp.sql_in | 6 ++--- src/ports/postgres/modules/graph/test/wcc.sql_in | 4 +-- .../postgres/modules/utilities/validate_args.py_in | 18 ++++++++++--- 8 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/ports/postgres/modules/graph/test/apsp.sql_in b/src/ports/postgres/modules/graph/test/apsp.sql_in index bf46260..4f399cc 100644 --- a/src/ports/postgres/modules/graph/test/apsp.sql_in +++ b/src/ports/postgres/modules/graph/test/apsp.sql_in @@ -116,9 +116,9 @@ ALTER TABLE vertex RENAME COLUMN "DEST" TO id; CREATE TABLE v2 AS SELECT id::bigint FROM vertex; CREATE TABLE e2 AS SELECT src::bigint, "DEST"::bigint, weight FROM "EDGE"; -DROP TABLE IF EXISTS public.out2, public.out2_summary, public.out2_path; -SELECT graph_apsp('v2',NULL,'e2','dest="DEST"','public.out2'); -SELECT graph_apsp_get_path('public.out2',0,7,'public.out2_path'); +DROP TABLE IF EXISTS pg_temp.out2, pg_temp.out2_summary, pg_temp.out2_path; +SELECT graph_apsp('v2',NULL,'e2','dest="DEST"','pg_temp.out2'); +SELECT graph_apsp_get_path('pg_temp.out2',0,7,'pg_temp.out2_path'); -- Test for infinite paths DROP TABLE IF EXISTS out, out_summary, out_path; diff --git a/src/ports/postgres/modules/graph/test/bfs.sql_in b/src/ports/postgres/modules/graph/test/bfs.sql_in index f36eeb6..7d04a86 100644 --- a/src/ports/postgres/modules/graph/test/bfs.sql_in +++ b/src/ports/postgres/modules/graph/test/bfs.sql_in @@ -294,8 +294,8 @@ ALTER TABLE vertex RENAME COLUMN dest TO id; CREATE TABLE v2 AS SELECT id::bigint FROM vertex; CREATE TABLE e2 AS SELECT "SRC"::bigint, dest::bigint, weight FROM "EDGE"; -DROP TABLE IF EXISTS public.out2, public.out2_summary; -SELECT graph_bfs('v2',NULL,'e2','src="SRC"',3,'public.out2'); +DROP TABLE IF EXISTS pg_temp.out2, pg_temp.out2_summary; +SELECT graph_bfs('v2',NULL,'e2','src="SRC"',3,'pg_temp.out2'); -- Test for infinite paths DROP TABLE IF EXISTS out, out_summary, out_path; diff --git a/src/ports/postgres/modules/graph/test/hits.sql_in b/src/ports/postgres/modules/graph/test/hits.sql_in index 3be0688..5e474c6 100644 --- a/src/ports/postgres/modules/graph/test/hits.sql_in +++ b/src/ports/postgres/modules/graph/test/hits.sql_in @@ -176,5 +176,5 @@ ALTER TABLE vertex RENAME COLUMN dest TO id; CREATE TABLE v2 AS SELECT id::bigint FROM vertex; CREATE TABLE e2 AS SELECT src::bigint, dest::bigint FROM edge; -DROP TABLE IF EXISTS public.out2, public.out2_summary; -SELECT hits('v2',NULL,'e2',NULL,'public.out2'); +DROP TABLE IF EXISTS pg_temp.out2, pg_temp.out2_summary; +SELECT hits('v2',NULL,'e2',NULL,'pg_temp.out2'); diff --git a/src/ports/postgres/modules/graph/test/measures.sql_in b/src/ports/postgres/modules/graph/test/measures.sql_in index a98faff..d3d0081 100644 --- a/src/ports/postgres/modules/graph/test/measures.sql_in +++ b/src/ports/postgres/modules/graph/test/measures.sql_in @@ -64,51 +64,46 @@ SELECT graph_apsp('vertex', -- Vertex table 'out_apsp'); -- Output table of shortest paths -- Compute the closeness measure for all nodes: -DROP TABLE IF EXISTS public.__madlib__out_closeness; -SELECT graph_closeness('out_apsp', 'public.__madlib__out_closeness'); -SELECT * FROM public.__madlib__out_closeness; +SELECT graph_closeness('out_apsp', 'pg_temp.__madlib__out_closeness'); +SELECT * FROM pg_temp.__madlib__out_closeness; SELECT assert(relative_error(inverse_sum_dist, 0.04347) < 1e-2 and relative_error(inverse_avg_dist, 0.3043) < 1e-2 and relative_error(sum_inverse_dist, 3.6833) < 1e-2 and k_degree = 7, 'Incorrect value for closeness') -FROM public.__madlib__out_closeness +FROM pg_temp.__madlib__out_closeness WHERE src_id = 0; -- Compute the diameter measure for graph -DROP TABLE IF EXISTS public.__madlib__out_diameter; -SELECT graph_diameter('out_apsp', 'public.__madlib__out_diameter'); -SELECT * FROM public.__madlib__out_diameter; -SELECT assert(diameter=14, 'Invalid value for diameter') FROM public.__madlib__out_diameter; +SELECT graph_diameter('out_apsp', 'pg_temp.__madlib__out_diameter'); +SELECT * FROM pg_temp.__madlib__out_diameter; +SELECT assert(diameter=14, 'Invalid value for diameter') FROM pg_temp.__madlib__out_diameter; -- Compute the average path length measure for graph -DROP TABLE IF EXISTS public.__madlib__out_avg_path_length; -SELECT graph_avg_path_length('out_apsp', 'public.__madlib__out_avg_path_length'); -SELECT * FROM public.__madlib__out_avg_path_length; +SELECT graph_avg_path_length('out_apsp', 'pg_temp.__madlib__out_avg_path_length'); +SELECT * FROM pg_temp.__madlib__out_avg_path_length; SELECT assert(relative_error(avg_path_length, 2.97) < 1e-2, - 'Invalid value for avg_path_length') FROM public.__madlib__out_avg_path_length; + 'Invalid value for avg_path_length') FROM pg_temp.__madlib__out_avg_path_length; -- Compute the in and out degrees -DROP TABLE IF EXISTS public.__madlib__out_degrees; SELECT graph_vertex_degrees('vertex', -- Vertex table 'id', -- Vertix id column (NULL means use default naming) '"EDGE"', -- "EDGE" table 'src=src_id, dest="DEST_ID", weight=edge_weight', -- "EDGE" arguments (NULL means use default naming) - 'public.__madlib__out_degrees'); -SELECT * FROM public.__madlib__out_degrees; + 'pg_temp.__madlib__out_degrees'); +SELECT * FROM pg_temp.__madlib__out_degrees; SELECT assert(indegree = 2 and outdegree = 3, 'Invalid value for degrees') -FROM public.__madlib__out_degrees +FROM pg_temp.__madlib__out_degrees WHERE id = 0; SELECT assert(COUNT(*)=1, 'Invalid value for node with only one incoming edge.') -FROM public.__madlib__out_degrees +FROM pg_temp.__madlib__out_degrees WHERE id = 7; DELETE FROM "EDGE" WHERE "DEST_ID"=7; INSERT INTO "EDGE" VALUES (7,6,1); -DROP TABLE IF EXISTS public.out_degrees; SELECT graph_vertex_degrees('vertex', -- Vertex table 'id', -- Vertix id column (NULL means use default naming) '"EDGE"', -- "EDGE" table diff --git a/src/ports/postgres/modules/graph/test/pagerank.sql_in b/src/ports/postgres/modules/graph/test/pagerank.sql_in index 7c886e1..c560d4a 100644 --- a/src/ports/postgres/modules/graph/test/pagerank.sql_in +++ b/src/ports/postgres/modules/graph/test/pagerank.sql_in @@ -212,5 +212,5 @@ ALTER TABLE vertex RENAME COLUMN dest TO id; CREATE TABLE v2 AS SELECT id::bigint FROM vertex; CREATE TABLE e2 AS SELECT src::bigint, dest::bigint FROM "EDGE"; -DROP TABLE IF EXISTS public.out2, public.out2_summary; -SELECT pagerank('v2',NULL,'e2',NULL,'public.out2'); +DROP TABLE IF EXISTS pg_temp.out2, pg_temp.out2_summary; +SELECT pagerank('v2',NULL,'e2',NULL,'pg_temp.out2'); diff --git a/src/ports/postgres/modules/graph/test/sssp.sql_in b/src/ports/postgres/modules/graph/test/sssp.sql_in index 6a2f881..af0eb48 100644 --- a/src/ports/postgres/modules/graph/test/sssp.sql_in +++ b/src/ports/postgres/modules/graph/test/sssp.sql_in @@ -161,9 +161,9 @@ ALTER TABLE vertex RENAME COLUMN dest TO id; CREATE TABLE v2 AS SELECT id::bigint FROM vertex; CREATE TABLE e2 AS SELECT src::bigint, dest::bigint, weight FROM "EDGE"; -DROP TABLE IF EXISTS public.out2, public.out2_summary, public.out2_path; -SELECT graph_sssp('v2',NULL,'e2',NULL,0,'public.out2'); -SELECT graph_sssp_get_path('public.out2',5,'public.out2_path'); +DROP TABLE IF EXISTS pg_temp.out2, pg_temp.out2_summary, pg_temp.out2_path; +SELECT graph_sssp('v2',NULL,'e2',NULL,0,'pg_temp.out2'); +SELECT graph_sssp_get_path('pg_temp.out2',5,'pg_temp.out2_path'); -- Test for infinite paths DROP TABLE IF EXISTS out, out_summary, out_path; diff --git a/src/ports/postgres/modules/graph/test/wcc.sql_in b/src/ports/postgres/modules/graph/test/wcc.sql_in index 2cdbf6d..7e495cf 100644 --- a/src/ports/postgres/modules/graph/test/wcc.sql_in +++ b/src/ports/postgres/modules/graph/test/wcc.sql_in @@ -179,5 +179,5 @@ ALTER TABLE vertex RENAME COLUMN dest TO id; CREATE TABLE v2 AS SELECT id::bigint FROM vertex; CREATE TABLE e2 AS SELECT src_node::bigint, dest_node::bigint FROM "EDGE"; -DROP TABLE IF EXISTS public.out2, public.out2_summary; -SELECT weakly_connected_components('v2',NULL,'e2','src=src_node,dest=dest_node','public.out2'); +DROP TABLE IF EXISTS pg_temp.out2, pg_temp.out2_summary; +SELECT weakly_connected_components('v2',NULL,'e2','src=src_node,dest=dest_node','pg_temp.out2'); diff --git a/src/ports/postgres/modules/utilities/validate_args.py_in b/src/ports/postgres/modules/utilities/validate_args.py_in index ea4d133..ac6bd4a 100644 --- a/src/ports/postgres/modules/utilities/validate_args.py_in +++ b/src/ports/postgres/modules/utilities/validate_args.py_in @@ -209,10 +209,20 @@ def rename_table(schema_madlib, orig_name, new_name): # set schema only if a change in schema is required before_schema_string = "{0}.{1}".format(orig_table_schema, new_table_name) - plpy.execute("""ALTER TABLE {new_table} - SET SCHEMA {schema_name}""". - format(new_table=before_schema_string, - schema_name=new_table_schema)) + + if 'pg_temp' in new_table_schema: + # We cannot alter table schemas from/to temp schemas + # If it looks like a temp schema, we stay safe and just use + # create/drop + plpy.execute("""CREATE TABLE {new_name} AS + SELECT * FROM {new_table_name}""". + format(**locals())) + drop_tables([new_table_name]) + else: + plpy.execute("""ALTER TABLE {new_table} + SET SCHEMA {schema_name}""". + format(new_table=before_schema_string, + schema_name=new_table_schema)) return new_name else: return orig_table_schema + "." + new_table_name
