Skip to content

Commit

Permalink
Merge c22fc0f into 63ba619
Browse files Browse the repository at this point in the history
  • Loading branch information
onderkalaci committed Jul 9, 2015
2 parents 63ba619 + c22fc0f commit 83d05de
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ SCRIPTS = bin/copy_to_distributed_table

REGRESS = init connection distribution_metadata extend_ddl_commands \
generate_ddl_commands create_shards prune_shard_list repair_shards \
modifications queries utilities citus_metadata_sync create_insert_proxy
modifications queries utilities citus_metadata_sync create_insert_proxy \
data_types

# The launcher regression flag lets us specify a special wrapper to handle
# testing rather than psql directly. Our wrapper swaps in a known worker list.
Expand Down
9 changes: 6 additions & 3 deletions create_shards.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,16 @@ IntegerToText(int32 value)
/*
* SupportFunctionForColumn locates a support function given a column, an access method,
* and and id of a support function. This function returns InvalidOid if there is no
* support function associated with the data type of the column, but if the data type of
* the column has no default operator class whatsoever, this function errors out.
* support function for the operator class family of the column, but if the data type
* of the column has no default operator class whatsoever, this function errors out.
*/
Oid
SupportFunctionForColumn(Var *partitionColumn, Oid accessMethodId,
int16 supportFunctionNumber)
{
Oid operatorFamilyId = InvalidOid;
Oid supportFunctionOid = InvalidOid;
Oid operatorClassInputType = InvalidOid;
Oid columnOid = partitionColumn->vartype;
Oid operatorClassId = GetDefaultOpClass(columnOid, accessMethodId);

Expand All @@ -613,7 +614,9 @@ SupportFunctionForColumn(Var *partitionColumn, Oid accessMethodId,
}

operatorFamilyId = get_opclass_family(operatorClassId);
supportFunctionOid = get_opfamily_proc(operatorFamilyId, columnOid, columnOid,
operatorClassInputType = get_opclass_input_type(operatorClassId);
supportFunctionOid = get_opfamily_proc(operatorFamilyId, operatorClassInputType,
operatorClassInputType,
supportFunctionNumber);

return supportFunctionOid;
Expand Down
160 changes: 160 additions & 0 deletions expected/data_types.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
-- ===================================================================
-- test composite type, varchar and enum types
-- create, distribute, INSERT, SELECT and UPDATE
-- ===================================================================
-- create a custom type...
CREATE TYPE test_composite_type AS (
i integer,
i2 integer
);
-- ... as well as a function to use as its comparator...
CREATE FUNCTION equal_test_composite_type_function(test_composite_type, test_composite_type) RETURNS boolean
AS 'select $1.i = $2.i AND $1.i2 = $2.i2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
-- ... use that function to create a custom equality operator...
CREATE OPERATOR = (
LEFTARG = test_composite_type,
RIGHTARG = test_composite_type,
PROCEDURE = equal_test_composite_type_function,
HASHES
);
-- ... and create a custom operator family for hash indexes...
CREATE OPERATOR FAMILY cats_op_fam USING hash;
-- ... create a test HASH function. Though it is a poor hash function,
-- it is acceptable for our tests
CREATE FUNCTION test_composite_type_hash(test_composite_type) RETURNS int
AS 'SELECT hashtext( ($1.i + $1.i2)::text);'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
-- We need to define two different operator classes for the composite types
-- One uses BTREE the other uses HASH
CREATE OPERATOR CLASS cats_op_fam_clas3
DEFAULT FOR TYPE test_composite_type USING BTREE AS
OPERATOR 3 = (test_composite_type, test_composite_type);
CREATE OPERATOR CLASS cats_op_fam_class
DEFAULT FOR TYPE test_composite_type USING HASH AS
OPERATOR 1 = (test_composite_type, test_composite_type),
FUNCTION 1 test_composite_type_hash(test_composite_type);
-- create and distribute a table on composite type column
CREATE TABLE composite_type_partitioned_table
(
id integer,
col test_composite_type
);
SELECT master_create_distributed_table('composite_type_partitioned_table', 'col');
master_create_distributed_table
---------------------------------

(1 row)

-- squelch noisy warnings when creating shards
\set VERBOSITY terse
SELECT master_create_worker_shards('composite_type_partitioned_table', 4, 1);
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
master_create_worker_shards
-----------------------------

(1 row)

\set VERBOSITY default
-- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table
INSERT INTO composite_type_partitioned_table VALUES (1, '(1, 2)'::test_composite_type);
INSERT INTO composite_type_partitioned_table VALUES (2, '(3, 4)'::test_composite_type);
INSERT INTO composite_type_partitioned_table VALUES (3, '(5, 6)'::test_composite_type);
INSERT INTO composite_type_partitioned_table VALUES (4, '(7, 8)'::test_composite_type);
INSERT INTO composite_type_partitioned_table VALUES (5, '(9, 10)'::test_composite_type);
SELECT * FROM composite_type_partitioned_table WHERE col = '(7, 8)'::test_composite_type;
id | col
----+-------
4 | (7,8)
(1 row)

UPDATE composite_type_partitioned_table SET id = 6 WHERE col = '(7, 8)'::test_composite_type;
SELECT * FROM composite_type_partitioned_table WHERE col = '(7, 8)'::test_composite_type;
id | col
----+-------
6 | (7,8)
(1 row)

-- create and distribute a table on enum type column
CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed');
CREATE TABLE bugs (
id integer,
status bug_status
);
SELECT master_create_distributed_table('bugs', 'status');
master_create_distributed_table
---------------------------------

(1 row)

-- squelch noisy warnings when creating shards
\set VERBOSITY terse
SELECT master_create_worker_shards('bugs', 4, 1);
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
WARNING: Connection failed to adeadhost:5432
WARNING: could not create shard on "adeadhost:5432"
master_create_worker_shards
-----------------------------

(1 row)

\set VERBOSITY default
-- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table
INSERT INTO bugs VALUES (1, 'new');
INSERT INTO bugs VALUES (2, 'open');
INSERT INTO bugs VALUES (3, 'closed');
INSERT INTO bugs VALUES (4, 'closed');
INSERT INTO bugs VALUES (5, 'open');
SELECT * FROM bugs WHERE status = 'closed'::bug_status;
id | status
----+--------
3 | closed
4 | closed
(2 rows)

UPDATE bugs SET status = 'closed'::bug_status WHERE id = 2;
ERROR: modifying the partition value of rows is not allowed
SELECT * FROM bugs WHERE status = 'open'::bug_status;
id | status
----+--------
2 | open
5 | open
(2 rows)

-- create and distribute a table on varchar column
CREATE TABLE varchar_partitioned_table
(
id int,
name varchar
);
SELECT master_create_distributed_table('varchar_partitioned_table', 'c1');
ERROR: column "c1" of relation "varchar_partitioned_table" does not exist
SELECT master_create_worker_shards('varchar_partitioned_table', 4, 1);
ERROR: no partition column is defined for relation "varchar_partitioned_table"
-- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table
INSERT INTO varchar_partitioned_table VALUES (1, 'Jason');
INSERT INTO varchar_partitioned_table VALUES (2, 'Ozgun');
INSERT INTO varchar_partitioned_table VALUES (3, 'Onder');
INSERT INTO varchar_partitioned_table VALUES (4, 'Sumedh');
INSERT INTO varchar_partitioned_table VALUES (5, 'Marco');
SELECT * FROM varchar_partitioned_table WHERE name = 'Onder';
id | name
----+-------
3 | Onder
(1 row)

UPDATE varchar_partitioned_table SET name = 'Samay' WHERE id = 5;
SELECT * FROM varchar_partitioned_table WHERE name = 'Samay';
id | name
----+-------
5 | Samay
(1 row)

7 changes: 5 additions & 2 deletions prune_shard_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,15 @@ LookupOperatorByType(Oid typeId, Oid accessMethodId, int16 strategyNumber)
Oid
GetOperatorByType(Oid typeId, Oid accessMethodId, int16 strategyNumber)
{
/* Get default operator class from pg_opclass */
/* get default operator class from pg_opclass */
Oid operatorClassId = GetDefaultOpClass(typeId, accessMethodId);

Oid operatorFamily = get_opclass_family(operatorClassId);
Oid operatorClassInputType = get_opclass_input_type(operatorClassId);

Oid operatorId = get_opfamily_member(operatorFamily, typeId, typeId, strategyNumber);
/* lookup for the operator with the desired input type in the family */
Oid operatorId = get_opfamily_member(operatorFamily, operatorClassInputType,
operatorClassInputType, strategyNumber);

return operatorId;
}
Expand Down
127 changes: 127 additions & 0 deletions sql/data_types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
-- ===================================================================
-- test composite type, varchar and enum types
-- create, distribute, INSERT, SELECT and UPDATE
-- ===================================================================

-- create a custom type...
CREATE TYPE test_composite_type AS (
i integer,
i2 integer
);

-- ... as well as a function to use as its comparator...
CREATE FUNCTION equal_test_composite_type_function(test_composite_type, test_composite_type) RETURNS boolean
AS 'select $1.i = $2.i AND $1.i2 = $2.i2;'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;

-- ... use that function to create a custom equality operator...
CREATE OPERATOR = (
LEFTARG = test_composite_type,
RIGHTARG = test_composite_type,
PROCEDURE = equal_test_composite_type_function,
HASHES
);

-- ... and create a custom operator family for hash indexes...
CREATE OPERATOR FAMILY cats_op_fam USING hash;

-- ... create a test HASH function. Though it is a poor hash function,
-- it is acceptable for our tests
CREATE FUNCTION test_composite_type_hash(test_composite_type) RETURNS int
AS 'SELECT hashtext( ($1.i + $1.i2)::text);'
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;


-- We need to define two different operator classes for the composite types
-- One uses BTREE the other uses HASH
CREATE OPERATOR CLASS cats_op_fam_clas3
DEFAULT FOR TYPE test_composite_type USING BTREE AS
OPERATOR 3 = (test_composite_type, test_composite_type);

CREATE OPERATOR CLASS cats_op_fam_class
DEFAULT FOR TYPE test_composite_type USING HASH AS
OPERATOR 1 = (test_composite_type, test_composite_type),
FUNCTION 1 test_composite_type_hash(test_composite_type);

-- create and distribute a table on composite type column
CREATE TABLE composite_type_partitioned_table
(
id integer,
col test_composite_type
);

SELECT master_create_distributed_table('composite_type_partitioned_table', 'col');

-- squelch noisy warnings when creating shards
\set VERBOSITY terse
SELECT master_create_worker_shards('composite_type_partitioned_table', 4, 1);
\set VERBOSITY default

-- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table
INSERT INTO composite_type_partitioned_table VALUES (1, '(1, 2)'::test_composite_type);
INSERT INTO composite_type_partitioned_table VALUES (2, '(3, 4)'::test_composite_type);
INSERT INTO composite_type_partitioned_table VALUES (3, '(5, 6)'::test_composite_type);
INSERT INTO composite_type_partitioned_table VALUES (4, '(7, 8)'::test_composite_type);
INSERT INTO composite_type_partitioned_table VALUES (5, '(9, 10)'::test_composite_type);

SELECT * FROM composite_type_partitioned_table WHERE col = '(7, 8)'::test_composite_type;

UPDATE composite_type_partitioned_table SET id = 6 WHERE col = '(7, 8)'::test_composite_type;

SELECT * FROM composite_type_partitioned_table WHERE col = '(7, 8)'::test_composite_type;


-- create and distribute a table on enum type column
CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed');

CREATE TABLE bugs (
id integer,
status bug_status
);

SELECT master_create_distributed_table('bugs', 'status');

-- squelch noisy warnings when creating shards
\set VERBOSITY terse
SELECT master_create_worker_shards('bugs', 4, 1);
\set VERBOSITY default

-- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table
INSERT INTO bugs VALUES (1, 'new');
INSERT INTO bugs VALUES (2, 'open');
INSERT INTO bugs VALUES (3, 'closed');
INSERT INTO bugs VALUES (4, 'closed');
INSERT INTO bugs VALUES (5, 'open');

SELECT * FROM bugs WHERE status = 'closed'::bug_status;

UPDATE bugs SET status = 'closed'::bug_status WHERE id = 2;

SELECT * FROM bugs WHERE status = 'open'::bug_status;

-- create and distribute a table on varchar column
CREATE TABLE varchar_partitioned_table
(
id int,
name varchar
);

SELECT master_create_distributed_table('varchar_partitioned_table', 'c1');
SELECT master_create_worker_shards('varchar_partitioned_table', 4, 1);

-- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table
INSERT INTO varchar_partitioned_table VALUES (1, 'Jason');
INSERT INTO varchar_partitioned_table VALUES (2, 'Ozgun');
INSERT INTO varchar_partitioned_table VALUES (3, 'Onder');
INSERT INTO varchar_partitioned_table VALUES (4, 'Sumedh');
INSERT INTO varchar_partitioned_table VALUES (5, 'Marco');

SELECT * FROM varchar_partitioned_table WHERE name = 'Onder';

UPDATE varchar_partitioned_table SET name = 'Samay' WHERE id = 5;

SELECT * FROM varchar_partitioned_table WHERE name = 'Samay';

0 comments on commit 83d05de

Please sign in to comment.