[enhancement](jdbc catalog ) support postgresql partition table (#23744)

This commit is contained in:
zy-kkk
2023-09-03 10:52:01 +08:00
committed by GitHub
parent a74fe4acfd
commit a664bc5fca
5 changed files with 117 additions and 1 deletions

View File

@ -178,3 +178,55 @@ CREATE TABLE catalog_pg_test.jsonb_test (
type varchar(10),
value jsonb
);
CREATE TABLE catalog_pg_test.person_r (
age int not null,
city varchar not null
)
PARTITION BY RANGE (age);
create table catalog_pg_test.person_r1 partition of catalog_pg_test.person_r for values from (MINVALUE) to (10);
create table catalog_pg_test.person_r2 partition of catalog_pg_test.person_r for values from (11) to (20);
create table catalog_pg_test.person_r3 partition of catalog_pg_test.person_r for values from (21) to (30);
create table catalog_pg_test.person_r4 partition of catalog_pg_test.person_r for values from (31) to (MAXVALUE);
CREATE TABLE catalog_pg_test.tb_test_alarm (
id varchar(64) NOT NULL,
alarm_type varchar(10) NOT NULL,
happen_time timestamptz NOT NULL,
CONSTRAINT tb_test_pk PRIMARY KEY (id)
);
create table catalog_pg_test.tb_test_alarm_2020_12 () inherits (catalog_pg_test.tb_test_alarm);
create table catalog_pg_test.tb_test_alarm_2020_11 () inherits (catalog_pg_test.tb_test_alarm);
create table catalog_pg_test.tb_test_alarm_2020_10 () inherits (catalog_pg_test.tb_test_alarm);
create table catalog_pg_test.tb_test_alarm_2020_09 () inherits (catalog_pg_test.tb_test_alarm);
--
CREATE OR REPLACE FUNCTION alarm_partition_trigger()
RETURNS TRIGGER AS $$
BEGIN
IF NEW.happen_time >= '2020-09-01 00:00:00' and NEW.happen_time <= '2020-09-30 23:59:59'
THEN
INSERT INTO catalog_pg_test.tb_test_alarm_2020_09 VALUES (NEW.*);
ELSIF NEW.happen_time >= '2020-10-01 00:00:00' and NEW.happen_time <= '2020-10-31 23:59:59'
THEN
INSERT INTO catalog_pg_test.tb_test_alarm_2020_10 VALUES (NEW.*);
ELSIF NEW.happen_time >= '2020-11-01 00:00:00' and NEW.happen_time <= '2020-11-30 23:59:59'
THEN
INSERT INTO catalog_pg_test.tb_test_alarm_2020_11 VALUES (NEW.*);
ELSIF NEW.happen_time >= '2020-12-01 00:00:00' and NEW.happen_time <= '2020-12-31 23:59:59'
THEN
INSERT INTO catalog_pg_test.tb_test_alarm_2020_12 VALUES (NEW.*);
END IF;
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
--Trigger
CREATE TRIGGER insert_almart_partition_trigger
BEFORE INSERT ON catalog_pg_test.tb_test_alarm
FOR EACH ROW EXECUTE PROCEDURE alarm_partition_trigger();

View File

@ -2704,3 +2704,17 @@ INSERT INTO catalog_pg_test.jsonb_test (type,value) VALUES
'jsonb2',
NULL
);
insert into catalog_pg_test.person_r(age, city) VALUES (1, 'GZ');
insert into catalog_pg_test.person_r(age, city) VALUES (2, 'SZ');
insert into catalog_pg_test.person_r(age, city) VALUES (21, 'SZ');
insert into catalog_pg_test.person_r(age, city) VALUES (13, 'BJ');
insert into catalog_pg_test.person_r(age, city) VALUES (43, 'SH');
insert into catalog_pg_test.person_r(age, city) VALUES (28, 'HK');
insert into catalog_pg_test.tb_test_alarm
values('1','A','2020-09-02 00:00:00')
,('2','A','2020-10-02 00:00:00')
,('3','A','2020-11-02 00:00:00')
,('4','A','2020-12-02 00:00:00')
;

View File

@ -35,7 +35,7 @@ public class JdbcPostgreSQLClient extends JdbcClient {
@Override
protected String[] getTableTypes() {
return new String[] {"TABLE", "VIEW", "MATERIALIZED VIEW", "FOREIGN TABLE"};
return new String[] {"TABLE", "PARTITIONED TABLE", "VIEW", "MATERIALIZED VIEW", "FOREIGN TABLE"};
}
@Override

View File

@ -2161,6 +2161,46 @@ true abc def 2022-10-11 1.234 1 2 99 2022-10-22T10:59:59 34.123
-- !filter3 --
1 false 12.123456 10.16.10.14/32 10.16.10.14 ff:ff:ff:ff:ff:aa 1010101010 01010 1 {"id":1}
-- !partition_1_0 --
1 GZ
13 BJ
2 SZ
21 SZ
28 HK
43 SH
-- !partition_1_1 --
1 GZ
2 SZ
-- !partition_1_2 --
13 BJ
-- !partition_1_3 --
21 SZ
28 HK
-- !partition_1_4 --
43 SH
-- !partition_2_0 --
1 A 2020-09-02T08:00
2 A 2020-10-02T08:00
3 A 2020-11-02T08:00
4 A 2020-12-02T08:00
-- !partition_2_1 --
1 A 2020-09-02T08:00
-- !partition_2_2 --
2 A 2020-10-02T08:00
-- !partition_2_3 --
3 A 2020-11-02T08:00
-- !partition_2_4 --
4 A 2020-12-02T08:00
-- !test_insert1 --
doris1 18

View File

@ -82,6 +82,16 @@ suite("test_pg_jdbc_catalog", "p0,external,pg,external_docker,external_docker_pg
order_qt_filter1 """ select * from test10 where 1 = 1 order by id; """
order_qt_filter2 """ select * from test10 where id = 1 order by id; """
order_qt_filter3 """ select * from test10 where 1 = 1 and id = 1 order by id; """
order_qt_partition_1_0 "select * from person_r;"
order_qt_partition_1_1 "select * from person_r1;"
order_qt_partition_1_2 "select * from person_r2;"
order_qt_partition_1_3 "select * from person_r3;"
order_qt_partition_1_4 "select * from person_r4;"
order_qt_partition_2_0 "select * from tb_test_alarm;"
order_qt_partition_2_1 "select * from tb_test_alarm_2020_09;"
order_qt_partition_2_2 "select * from tb_test_alarm_2020_10;"
order_qt_partition_2_3 "select * from tb_test_alarm_2020_11;"
order_qt_partition_2_4 "select * from tb_test_alarm_2020_12;"
// test insert
String uuid1 = UUID.randomUUID().toString();