Last active
April 19, 2016 16:10
-
-
Save marcocitus/27b5819895ab6c9c23738f24ae718574 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Test compatibility with Citus extension | |
-- | |
-- Function to perform a COPY, but hide error messages | |
CREATE OR REPLACE FUNCTION silent_copy() | |
RETURNS void LANGUAGE plpgsql AS $function$ | |
BEGIN | |
COPY contestant FROM '@abs_srcdir@/data/contestants.1.csv' WITH CSV; | |
EXCEPTION WHEN OTHERS THEN | |
RAISE EXCEPTION 'COPY error'; | |
END; | |
$function$; | |
-- Create fake Citus metadata tables | |
CREATE TABLE pg_dist_partition ( | |
logicalrelid Oid NOT NULL, | |
partmethod "char" NOT NULL, | |
partkey text NOT NULL | |
); | |
CREATE UNIQUE INDEX pg_dist_partition_logical_relid_index | |
ON pg_dist_partition using btree(logicalrelid); | |
ALTER TABLE pg_dist_partition SET SCHEMA pg_catalog; | |
CREATE TABLE pg_dist_shard( | |
logicalrelid oid NOT NULL, | |
shardid int8 NOT NULL, | |
shardstorage "char" NOT NULL, | |
shardalias text, | |
shardminvalue text, | |
shardmaxvalue text | |
); | |
CREATE UNIQUE INDEX pg_dist_shard_shardid_index | |
ON pg_dist_shard using btree(shardid); | |
CREATE INDEX pg_dist_shard_logical_relid_index | |
ON pg_dist_shard using btree(logicalrelid); | |
ALTER TABLE pg_dist_shard SET SCHEMA pg_catalog; | |
-- Insert a fake record for citus into pg_extension | |
INSERT INTO pg_extension | |
SELECT 'citus', | |
extowner, | |
extnamespace, | |
extrelocatable, | |
extversion | |
FROM pg_extension | |
WHERE extname = 'cstore_fdw'; | |
-- COPY should go through, since there is no distributed table | |
SELECT silent_copy(); | |
-- Create a mock distributed table entry | |
INSERT INTO pg_dist_partition | |
VALUES ('contestant'::regclass, | |
'hash', | |
'{VAR :varno 1 :varattno 2 :vartype 1082 :vartypmod -1 :varcollid 0 '|| | |
':varlevelsup 0 :varnoold 1 :varoattno 2 :location -1}'); | |
-- COPY should now error out | |
SELECT silent_copy(); | |
DELETE FROM pg_extension WHERE extname = 'citus'; | |
DROP TABLE pg_dist_partition, pg_dist_shard; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment