1SHOW server_version \gset 2SELECT substring(:'server_version', '\d+')::int > 11 AS server_version_above_eleven 3\gset 4\if :server_version_above_eleven 5\else 6\q 7\endif 8 9SET citus.shard_replication_factor to 1; 10SET citus.next_shard_id TO 60000; 11SET citus.next_placement_id TO 60000; 12SET citus.shard_count TO 4; 13 14create schema test_tableam; 15set search_path to test_tableam; 16 17SELECT public.run_command_on_coordinator_and_workers($Q$ 18 CREATE FUNCTION fake_am_handler(internal) 19 RETURNS table_am_handler 20 AS 'citus' 21 LANGUAGE C; 22 CREATE ACCESS METHOD fake_am TYPE TABLE HANDLER fake_am_handler; 23$Q$); 24 25-- 26-- Hash distributed table using a non-default table access method 27-- 28 29create table test_hash_dist(id int, val int) using fake_am; 30insert into test_hash_dist values (1, 1); 31select create_distributed_table('test_hash_dist','id'); 32 33select * from test_hash_dist; 34insert into test_hash_dist values (1, 1); 35 36-- we should error on following, since this AM is append only 37SET client_min_messages TO ERROR; 38delete from test_hash_dist where id=1; 39update test_hash_dist set val=2 where id=2; 40RESET client_min_messages; 41 42-- ddl events should include "USING fake_am" 43SELECT * FROM master_get_table_ddl_events('test_hash_dist'); 44 45-- 46-- Reference table using a non-default table access method 47-- 48 49create table test_ref(a int) using fake_am; 50insert into test_ref values (1); 51select create_reference_table('test_ref'); 52 53select * from test_ref; 54insert into test_ref values (1); 55 56-- we should error on following, since this AM is append only 57SET client_min_messages TO ERROR; 58delete from test_ref; 59update test_ref set a=2; 60RESET client_min_messages; 61 62-- ddl events should include "USING fake_am" 63SELECT * FROM master_get_table_ddl_events('test_ref'); 64 65-- replicate to coordinator 66SET client_min_messages TO WARNING; 67\set VERBOSIY terse 68SELECT 1 FROM master_add_node('localhost', :master_port, groupid => 0); 69RESET client_min_messages; 70delete from test_ref; 71SELECT master_remove_node('localhost', :master_port); 72 73-- 74-- Range partitioned table using a non-default table access method 75-- 76 77CREATE TABLE test_range_dist(id int, val int) using fake_am; 78SELECT create_distributed_table('test_range_dist', 'id', 'range'); 79CALL public.create_range_partitioned_shards('test_range_dist', '{"0","25"}','{"24","49"}'); 80 81select * from test_range_dist; 82insert into test_range_dist values (1, 1); 83COPY test_range_dist FROM PROGRAM 'echo 0, 0 && echo 1, -1 && echo 2, 4 && echo 3, 9' WITH CSV; 84COPY test_range_dist FROM PROGRAM 'echo 25, 16 && echo 26, 1 && echo 27, 4 && echo 7, 9' WITH CSV; 85 86 87-- ddl events should include "USING fake_am" 88SELECT * FROM master_get_table_ddl_events('test_range_dist'); 89 90-- 91-- Test master_copy_shard_placement with a fake_am table 92-- 93 94select a.shardid, a.nodeport 95FROM pg_dist_shard b, pg_dist_shard_placement a 96WHERE a.shardid=b.shardid AND logicalrelid = 'test_range_dist'::regclass::oid 97ORDER BY a.shardid, nodeport; 98 99SELECT master_copy_shard_placement( 100 get_shard_id_for_distribution_column('test_range_dist', '1'), 101 'localhost', :worker_1_port, 102 'localhost', :worker_2_port, 103 do_repair := false, 104 transfer_mode := 'block_writes'); 105 106select a.shardid, a.nodeport 107FROM pg_dist_shard b, pg_dist_shard_placement a 108WHERE a.shardid=b.shardid AND logicalrelid = 'test_range_dist'::regclass::oid 109ORDER BY a.shardid, nodeport; 110 111-- verify that data was copied correctly 112 113\c - - - :worker_1_port 114select * from test_tableam.test_range_dist_60005 ORDER BY id; 115 116\c - - - :worker_2_port 117select * from test_tableam.test_range_dist_60005 ORDER BY id; 118 119\c - - - :master_port 120 121-- 122-- Test that partitioned tables work correctly with a fake_am table 123-- 124 125-- parent using default am, one of children using fake_am 126CREATE TABLE test_partitioned(id int, p int, val int) 127PARTITION BY RANGE (p); 128 129CREATE TABLE test_partitioned_p1 PARTITION OF test_partitioned 130 FOR VALUES FROM (1) TO (10); 131CREATE TABLE test_partitioned_p2 PARTITION OF test_partitioned 132 FOR VALUES FROM (11) TO (20) USING fake_am; 133 134INSERT INTO test_partitioned VALUES (1, 5, -1), (2, 15, -2); 135 136SELECT create_distributed_table('test_partitioned', 'id'); 137 138INSERT INTO test_partitioned VALUES (3, 6, -6), (4, 16, -4); 139 140SELECT count(*) FROM test_partitioned; 141 142DROP TABLE test_partitioned; 143 144-- Specifying access method in parent is not supported. 145-- If the below statement ever succeeds, add more tests for 146-- the case where children inherit access method from parent. 147CREATE TABLE test_partitioned(id int, p int, val int) 148PARTITION BY RANGE (p) USING fake_am; 149 150\set VERBOSITY terse 151drop schema test_tableam cascade; 152