Skip to content

Commit d82b387

Browse files
committed
Support PostgreSQL regclass CDC type
1 parent 0044826 commit d82b387

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

flink-doris-connector/flink-doris-connector-base/src/main/java/org/apache/doris/flink/tools/cdc/postgres/PostgresType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class PostgresType {
5555
private static final String VARBIT = "varbit";
5656
private static final String UUID = "uuid";
5757
private static final String BYTEA = "bytea";
58+
private static final String REGCLASS = "regclass";
5859
private static final String JSON = "json";
5960
private static final String JSONB = "jsonb";
6061
private static final String _INT2 = "_int2";
@@ -127,6 +128,7 @@ public static String toDorisType(String postgresType, Integer precision, Integer
127128
case VARBIT:
128129
case UUID:
129130
case BYTEA:
131+
case REGCLASS:
130132
return DorisType.STRING;
131133
case JSON:
132134
case JSONB:

flink-doris-connector/flink-doris-connector-base/src/test/java/org/apache/doris/flink/sink/schema/SQLParserSchemaManagerTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ public void testParserAlterDDLsAdd() {
8080
}
8181
}
8282

83+
@Test
84+
public void testParserPostgresAlterDDLsAddRegclass() {
85+
String ddl = "ALTER TABLE access_control_device ADD COLUMN relation_id regclass";
86+
List<String> actualDDLs =
87+
schemaManager.parseAlterDDLs(SourceConnector.POSTGRES, ddl, dorisTable);
88+
89+
Assert.assertEquals(1, actualDDLs.size());
90+
Assert.assertEquals(
91+
"ALTER TABLE `doris`.`tab` ADD COLUMN `relation_id` STRING", actualDDLs.get(0));
92+
}
93+
8394
@Test
8495
public void testParserAlterDDLsChange() {
8596
List<String> expectDDLs = new ArrayList<>();

flink-doris-connector/flink-doris-connector-base/src/test/java/org/apache/doris/flink/sink/writer/serializer/jsondebezium/TestJsonDebeziumSchemaChangeImplV2.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ public void testBuildPostgres2DorisTypeName() throws IOException {
386386
JsonNode columns = objectMapper.readTree(columnInfo);
387387
String dorisTypeName = schemaChange.buildDorisTypeName(columns);
388388
Assert.assertEquals(dorisTypeName, "VARCHAR(384)");
389+
390+
columnInfo =
391+
"{\"name\":\"RELATION_ID\",\"jdbcType\":1111,\"nativeType\":null,\"typeName\":\"regclass\",\"typeExpression\":\"regclass\",\"charsetName\":null,\"position\":3,\"optional\":true,\"autoIncremented\":false,\"generated\":false,\"comment\":null}";
392+
columns = objectMapper.readTree(columnInfo);
393+
dorisTypeName = schemaChange.buildDorisTypeName(columns);
394+
Assert.assertEquals(dorisTypeName, "STRING");
389395
}
390396

391397
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.flink.tools.cdc.postgres;
19+
20+
import org.apache.doris.flink.catalog.doris.DorisType;
21+
import org.junit.Test;
22+
23+
import static org.junit.Assert.assertEquals;
24+
25+
public class PostgresTypeTest {
26+
@Test
27+
public void regclassTypeTest() {
28+
assertEquals(DorisType.STRING, PostgresType.toDorisType("regclass", null, null));
29+
assertEquals(DorisType.STRING, PostgresType.toDorisType("REGCLASS", null, null));
30+
}
31+
}

0 commit comments

Comments
 (0)