Skip to content

Commit 1c9d594

Browse files
libailinlihongwei
authored and
lihongwei
committed
[Feature-#1924][opengauss] Add opengauss connector
1 parent 5432e78 commit 1c9d594

39 files changed

+3317
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<parent>
25+
<artifactId>chunjun-connectors</artifactId>
26+
<groupId>com.dtstack.chunjun</groupId>
27+
<version>${revision}</version>
28+
</parent>
29+
<modelVersion>4.0.0</modelVersion>
30+
31+
<artifactId>chunjun-connector-opengauss</artifactId>
32+
<name>ChunJun : Connector : openGauss</name>
33+
34+
<properties>
35+
<connector.dir>opengauss</connector.dir>
36+
</properties>
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>com.dtstack.chunjun</groupId>
41+
<artifactId>chunjun-connector-jdbc-base</artifactId>
42+
<version>${project.version}</version>
43+
</dependency>
44+
<!-- 建议从官网(https://opengauss.org/zh/download/)下载此驱动jar包,务必注意里面的正确包名是org.opengauss -->
45+
<!-- mvn install:install-file -DgroupId=org.opengauss -DartifactId=opengauss-jdbc -Dversion=5.0.1 -Dpackaging=jar -Dfile=./opengauss-jdbc-5.0.1.jar -->
46+
<!-- 注意:从maven中央仓库里下载的jar包里的包名可能是org.postgresql,这会导致与PostgreSQL Connector之间的JDBC驱动包名冲突。 -->
47+
<dependency>
48+
<groupId>org.opengauss</groupId>
49+
<artifactId>opengauss-jdbc</artifactId>
50+
<version>5.0.1</version>
51+
</dependency>
52+
</dependencies>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-antrun-plugin</artifactId>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.chunjun.connector.opengauss.converter;
20+
21+
import com.dtstack.chunjun.config.TypeConfig;
22+
import com.dtstack.chunjun.connector.opengauss.converter.logical.BitType;
23+
import com.dtstack.chunjun.connector.opengauss.converter.logical.BoolType;
24+
import com.dtstack.chunjun.connector.opengauss.converter.logical.BpcharType;
25+
import com.dtstack.chunjun.connector.opengauss.converter.logical.ByteaType;
26+
import com.dtstack.chunjun.connector.opengauss.converter.logical.CharType;
27+
import com.dtstack.chunjun.connector.opengauss.converter.logical.DateType;
28+
import com.dtstack.chunjun.connector.opengauss.converter.logical.Float4Type;
29+
import com.dtstack.chunjun.connector.opengauss.converter.logical.Float8Type;
30+
import com.dtstack.chunjun.connector.opengauss.converter.logical.Int2Type;
31+
import com.dtstack.chunjun.connector.opengauss.converter.logical.Int4Type;
32+
import com.dtstack.chunjun.connector.opengauss.converter.logical.Int8Type;
33+
import com.dtstack.chunjun.connector.opengauss.converter.logical.JsonType;
34+
import com.dtstack.chunjun.connector.opengauss.converter.logical.JsonbType;
35+
import com.dtstack.chunjun.connector.opengauss.converter.logical.MoneyType;
36+
import com.dtstack.chunjun.connector.opengauss.converter.logical.NameType;
37+
import com.dtstack.chunjun.connector.opengauss.converter.logical.NumericType;
38+
import com.dtstack.chunjun.connector.opengauss.converter.logical.OidType;
39+
import com.dtstack.chunjun.connector.opengauss.converter.logical.PointType;
40+
import com.dtstack.chunjun.connector.opengauss.converter.logical.TextType;
41+
import com.dtstack.chunjun.connector.opengauss.converter.logical.TimeType;
42+
import com.dtstack.chunjun.connector.opengauss.converter.logical.TimestampType;
43+
import com.dtstack.chunjun.connector.opengauss.converter.logical.TimestampTzType;
44+
import com.dtstack.chunjun.connector.opengauss.converter.logical.TimetzType;
45+
import com.dtstack.chunjun.connector.opengauss.converter.logical.UuidType;
46+
import com.dtstack.chunjun.connector.opengauss.converter.logical.VarbitType;
47+
import com.dtstack.chunjun.connector.opengauss.converter.logical.VarcharType;
48+
import com.dtstack.chunjun.connector.opengauss.converter.logical.XmlType;
49+
import com.dtstack.chunjun.throwable.UnsupportedTypeException;
50+
51+
import org.apache.flink.table.api.DataTypes;
52+
import org.apache.flink.table.types.AtomicDataType;
53+
import org.apache.flink.table.types.DataType;
54+
import org.apache.flink.table.types.logical.LogicalTypeRoot;
55+
56+
public class OpengaussRawTypeMapper {
57+
58+
/**
59+
* https://docs-opengauss.osinfra.cn/zh/docs/5.0.0/docs/BriefTutorial/%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B.html
60+
*
61+
* @param type
62+
*/
63+
public static DataType apply(TypeConfig type) {
64+
switch (type.getType()) {
65+
case "BIT":
66+
return new AtomicDataType(new BitType(true, LogicalTypeRoot.BOOLEAN, false));
67+
case "BOOLEAN":
68+
case "BOOL":
69+
return DataTypes.BOOLEAN();
70+
case "SMALLINT":
71+
case "SMALLSERIAL":
72+
case "INT2":
73+
case "INT":
74+
case "INTEGER":
75+
case "SERIAL":
76+
case "INT4":
77+
return DataTypes.INT();
78+
case "BIGINT":
79+
case "BIGSERIAL":
80+
case "OID":
81+
case "INT8":
82+
return DataTypes.BIGINT();
83+
case "REAL":
84+
case "FLOAT4":
85+
return DataTypes.FLOAT();
86+
case "FLOAT":
87+
case "DOUBLE PRECISION":
88+
case "FLOAT8":
89+
return DataTypes.DOUBLE();
90+
case "MONEY":
91+
return new AtomicDataType(new MoneyType(true, LogicalTypeRoot.DOUBLE, false));
92+
case "DECIMAL":
93+
case "NUMERIC":
94+
return type.toDecimalDataType();
95+
case "CHARACTER VARYING":
96+
case "VARCHAR":
97+
case "CHARACTER":
98+
case "CHAR":
99+
case "TEXT":
100+
case "NAME":
101+
case "BPCHAR":
102+
return DataTypes.STRING();
103+
// Binary Data Types
104+
case "BYTEA":
105+
return DataTypes.BYTES();
106+
case "VARBIT":
107+
return new AtomicDataType(new VarbitType(true, LogicalTypeRoot.VARCHAR, false));
108+
case "XML":
109+
return new AtomicDataType(new XmlType(true, LogicalTypeRoot.VARCHAR, false));
110+
case "UUID":
111+
return new AtomicDataType(new UuidType(true, LogicalTypeRoot.VARCHAR, false));
112+
case "POINT":
113+
return new AtomicDataType(new PointType(true, LogicalTypeRoot.VARCHAR, false));
114+
// Date/Time Types
115+
case "ABSTIME":
116+
case "TIMESTAMP":
117+
case "TIMESTAMPTZ":
118+
return type.toTimestampDataType(6);
119+
case "DATE":
120+
return DataTypes.DATE();
121+
case "TIME":
122+
case "TIMETZ":
123+
// todo check sync
124+
return type.toTimeDataType(6);
125+
case "JSON":
126+
return new AtomicDataType(new JsonType(true, LogicalTypeRoot.VARCHAR, false));
127+
case "JSONB":
128+
return new AtomicDataType(new JsonbType(true, LogicalTypeRoot.VARCHAR, false));
129+
case "_BIT":
130+
return new AtomicDataType(new BitType(true, LogicalTypeRoot.VARCHAR, true));
131+
case "_BOOL":
132+
return new AtomicDataType(new BoolType(true, LogicalTypeRoot.VARCHAR, true));
133+
case "_INT2":
134+
return new AtomicDataType(new Int2Type(true, LogicalTypeRoot.VARCHAR, true));
135+
case "_INT4":
136+
return new AtomicDataType(new Int4Type(true, LogicalTypeRoot.VARCHAR, true));
137+
case "_INT8":
138+
return new AtomicDataType(new Int8Type(true, LogicalTypeRoot.VARCHAR, true));
139+
case "_FLOAT4":
140+
return new AtomicDataType(new Float4Type(true, LogicalTypeRoot.VARCHAR, true));
141+
case "_FLOAT8":
142+
return new AtomicDataType(new Float8Type(true, LogicalTypeRoot.VARCHAR, true));
143+
case "_NUMERIC":
144+
return new AtomicDataType(new NumericType(true, LogicalTypeRoot.VARCHAR, true));
145+
case "_TIME":
146+
return new AtomicDataType(new TimeType(true, LogicalTypeRoot.VARCHAR, true));
147+
case "_TIMETZ":
148+
return new AtomicDataType(new TimetzType(true, LogicalTypeRoot.VARCHAR, true));
149+
case "_TIMESTAMP":
150+
return new AtomicDataType(new TimestampType(true, LogicalTypeRoot.VARCHAR, true));
151+
case "_TIMESTAMPTZ":
152+
return new AtomicDataType(new TimestampTzType(true, LogicalTypeRoot.VARCHAR, true));
153+
case "_DATE":
154+
return new AtomicDataType(new DateType(true, LogicalTypeRoot.VARCHAR, true));
155+
case "_BYTEA":
156+
return new AtomicDataType(new ByteaType(true, LogicalTypeRoot.VARCHAR, true));
157+
case "_VARCHAR":
158+
return new AtomicDataType(new VarcharType(true, LogicalTypeRoot.VARCHAR, true));
159+
case "_OID":
160+
return new AtomicDataType(new OidType(true, LogicalTypeRoot.VARCHAR, true));
161+
case "_BPCHAR":
162+
return new AtomicDataType(new BpcharType(true, LogicalTypeRoot.VARCHAR, true));
163+
case "_TEXT":
164+
return new AtomicDataType(new TextType(true, LogicalTypeRoot.VARCHAR, true));
165+
case "_MONEY":
166+
return new AtomicDataType(new MoneyType(true, LogicalTypeRoot.VARCHAR, true));
167+
// case "_INTERVAL":
168+
case "_CHAR":
169+
return new AtomicDataType(new CharType(true, LogicalTypeRoot.VARCHAR, true));
170+
case "_VARBIT":
171+
return new AtomicDataType(new VarbitType(true, LogicalTypeRoot.VARCHAR, true));
172+
case "_NAME":
173+
return new AtomicDataType(new NameType(true, LogicalTypeRoot.VARCHAR, true));
174+
case "_UUID":
175+
return new AtomicDataType(new UuidType(true, LogicalTypeRoot.VARCHAR, true));
176+
case "_XML":
177+
return new AtomicDataType(new XmlType(true, LogicalTypeRoot.VARCHAR, true));
178+
// case "_POINT":
179+
// case "_JSONB":
180+
// case "_JSON":
181+
// case "_REF_CURSOR":
182+
183+
// 以下类型无法支持
184+
// Enumerated Types
185+
186+
// Geometric Types
187+
// case "LINE":
188+
// case "LSEG":
189+
// case "BOX":
190+
// case "PATH":
191+
// case "POLYGON":
192+
// case "CIRCLE":
193+
194+
// Network Address Types
195+
196+
//
197+
// // JSON Types
198+
// case "JSONB":
199+
// case "JSONPATH":
200+
// return DataTypes.STRING();
201+
202+
default:
203+
throw new UnsupportedTypeException(type);
204+
}
205+
}
206+
}

0 commit comments

Comments
 (0)