mirror of https://github.com/citusdata/citus.git
Add tests
parent
ac6cc0a738
commit
043d53f9c2
|
@ -168,9 +168,100 @@ DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
|||
6 | 7 | 8 |
|
||||
(3 rows)
|
||||
|
||||
RESET citus.log_remote_commands;
|
||||
-- test everything on https://github.com/citusdata/citus/issues/7684
|
||||
CREATE TABLE test_name_prefix (
|
||||
attribute1 varchar(255),
|
||||
attribute2 varchar(255),
|
||||
attribute3 varchar(255)
|
||||
);
|
||||
INSERT INTO test_name_prefix (attribute1, attribute2, attribute3)
|
||||
VALUES ('Phone', 'John', 'A'),
|
||||
('Phone', 'Eric', 'A'),
|
||||
('Tablet','Eric', 'B');
|
||||
-- vanilla Postgres result
|
||||
-- with DISTINCT ON (T.attribute1, T.attribute2)
|
||||
-- we have 3 distinct groups of 1 row each
|
||||
-- (Phone, John) (Phone, Eric) and (Tablet, Eric)
|
||||
SELECT DISTINCT ON (T.attribute1, T.attribute2)
|
||||
T.attribute1 AS attribute1,
|
||||
T.attribute3 AS attribute2,
|
||||
T.attribute2 AS attribute3
|
||||
FROM test_name_prefix T ORDER BY T.attribute1, T.attribute2;
|
||||
attribute1 | attribute2 | attribute3
|
||||
---------------------------------------------------------------------
|
||||
Phone | A | Eric
|
||||
Phone | A | John
|
||||
Tablet | B | Eric
|
||||
(3 rows)
|
||||
|
||||
-- vanilla Postgres result
|
||||
-- changes when we remove the table-name prefix to attribute2
|
||||
-- in this case it uses the output column name,
|
||||
-- which is actually T.attribute3 (AS attribute2)
|
||||
-- so, with DISTINCT ON (T.attribute1, T.attribute3)
|
||||
-- we have only 2 distinct groups
|
||||
-- (Phone, A) and (Tablet, B)
|
||||
SELECT DISTINCT ON (T.attribute1, attribute2)
|
||||
T.attribute1 AS attribute1,
|
||||
T.attribute3 AS attribute2, -- name match in output column name
|
||||
T.attribute2 AS attribute3
|
||||
FROM test_name_prefix T ORDER BY T.attribute1, attribute2;
|
||||
attribute1 | attribute2 | attribute3
|
||||
---------------------------------------------------------------------
|
||||
Phone | A | John
|
||||
Tablet | B | Eric
|
||||
(2 rows)
|
||||
|
||||
-- now, let's verify the distributed query scenario
|
||||
SELECT create_distributed_table('test_name_prefix', 'attribute1');
|
||||
NOTICE: Copying data from local table...
|
||||
NOTICE: copying the data has completed
|
||||
DETAIL: The local data in the table is no longer visible, but is still on disk.
|
||||
HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$alias.test_name_prefix$$)
|
||||
create_distributed_table
|
||||
---------------------------------------------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SET citus.log_remote_commands TO on;
|
||||
-- make sure we preserve the table-name prefix to attribute2
|
||||
-- when building the shard query
|
||||
-- (before this patch we wouldn't preserve T.attribute2)
|
||||
-- note that we only need to preserve T.attribute2, not T.attribute1
|
||||
-- because there is no confusion there
|
||||
SELECT DISTINCT ON (T.attribute1, T.attribute2)
|
||||
T.attribute1 AS attribute1,
|
||||
T.attribute3 AS attribute2,
|
||||
T.attribute2 AS attribute3
|
||||
FROM test_name_prefix T ORDER BY T.attribute1, T.attribute2;
|
||||
NOTICE: issuing SELECT DISTINCT ON (attribute1, t.attribute2) attribute1, attribute3 AS attribute2, attribute2 AS attribute3 FROM alias.test_name_prefix_90630803 t ORDER BY attribute1, t.attribute2
|
||||
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
||||
attribute1 | attribute2 | attribute3
|
||||
---------------------------------------------------------------------
|
||||
Phone | A | Eric
|
||||
Phone | A | John
|
||||
Tablet | B | Eric
|
||||
(3 rows)
|
||||
|
||||
-- here Citus will replace attribute2 with T.attribute3
|
||||
SELECT DISTINCT ON (T.attribute1, attribute2)
|
||||
T.attribute1 AS attribute1,
|
||||
T.attribute3 AS attribute2,
|
||||
T.attribute2 AS attribute3
|
||||
FROM test_name_prefix T ORDER BY T.attribute1, attribute2;
|
||||
NOTICE: issuing SELECT DISTINCT ON (attribute1, t.attribute3) attribute1, attribute3 AS attribute2, attribute2 AS attribute3 FROM alias.test_name_prefix_90630803 t ORDER BY attribute1, t.attribute3
|
||||
DETAIL: on server postgres@localhost:xxxxx connectionId: xxxxxxx
|
||||
attribute1 | attribute2 | attribute3
|
||||
---------------------------------------------------------------------
|
||||
Phone | A | John
|
||||
Tablet | B | Eric
|
||||
(2 rows)
|
||||
|
||||
RESET citus.log_remote_commands;
|
||||
DROP SCHEMA alias CASCADE;
|
||||
NOTICE: drop cascades to 3 other objects
|
||||
NOTICE: drop cascades to 4 other objects
|
||||
DETAIL: drop cascades to table alias_test
|
||||
drop cascades to table test
|
||||
drop cascades to table test_2
|
||||
drop cascades to table test_name_prefix
|
||||
|
|
|
@ -63,4 +63,65 @@ SELECT *
|
|||
ORDER BY a, d;
|
||||
|
||||
RESET citus.log_remote_commands;
|
||||
|
||||
-- test everything on https://github.com/citusdata/citus/issues/7684
|
||||
CREATE TABLE test_name_prefix (
|
||||
attribute1 varchar(255),
|
||||
attribute2 varchar(255),
|
||||
attribute3 varchar(255)
|
||||
);
|
||||
|
||||
INSERT INTO test_name_prefix (attribute1, attribute2, attribute3)
|
||||
VALUES ('Phone', 'John', 'A'),
|
||||
('Phone', 'Eric', 'A'),
|
||||
('Tablet','Eric', 'B');
|
||||
|
||||
-- vanilla Postgres result
|
||||
-- with DISTINCT ON (T.attribute1, T.attribute2)
|
||||
-- we have 3 distinct groups of 1 row each
|
||||
-- (Phone, John) (Phone, Eric) and (Tablet, Eric)
|
||||
SELECT DISTINCT ON (T.attribute1, T.attribute2)
|
||||
T.attribute1 AS attribute1,
|
||||
T.attribute3 AS attribute2,
|
||||
T.attribute2 AS attribute3
|
||||
FROM test_name_prefix T ORDER BY T.attribute1, T.attribute2;
|
||||
|
||||
-- vanilla Postgres result
|
||||
-- changes when we remove the table-name prefix to attribute2
|
||||
-- in this case it uses the output column name,
|
||||
-- which is actually T.attribute3 (AS attribute2)
|
||||
-- so, with DISTINCT ON (T.attribute1, T.attribute3)
|
||||
-- we have only 2 distinct groups
|
||||
-- (Phone, A) and (Tablet, B)
|
||||
SELECT DISTINCT ON (T.attribute1, attribute2)
|
||||
T.attribute1 AS attribute1,
|
||||
T.attribute3 AS attribute2, -- name match in output column name
|
||||
T.attribute2 AS attribute3
|
||||
FROM test_name_prefix T ORDER BY T.attribute1, attribute2;
|
||||
|
||||
-- now, let's verify the distributed query scenario
|
||||
SELECT create_distributed_table('test_name_prefix', 'attribute1');
|
||||
|
||||
SET citus.log_remote_commands TO on;
|
||||
|
||||
-- make sure we preserve the table-name prefix to attribute2
|
||||
-- when building the shard query
|
||||
-- (before this patch we wouldn't preserve T.attribute2)
|
||||
-- note that we only need to preserve T.attribute2, not T.attribute1
|
||||
-- because there is no confusion there
|
||||
SELECT DISTINCT ON (T.attribute1, T.attribute2)
|
||||
T.attribute1 AS attribute1,
|
||||
T.attribute3 AS attribute2,
|
||||
T.attribute2 AS attribute3
|
||||
FROM test_name_prefix T ORDER BY T.attribute1, T.attribute2;
|
||||
|
||||
-- here Citus will replace attribute2 with T.attribute3
|
||||
SELECT DISTINCT ON (T.attribute1, attribute2)
|
||||
T.attribute1 AS attribute1,
|
||||
T.attribute3 AS attribute2,
|
||||
T.attribute2 AS attribute3
|
||||
FROM test_name_prefix T ORDER BY T.attribute1, attribute2;
|
||||
|
||||
RESET citus.log_remote_commands;
|
||||
|
||||
DROP SCHEMA alias CASCADE;
|
||||
|
|
Loading…
Reference in New Issue