You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "Hisoka-X (via GitHub)" <gi...@apache.org> on 2023/05/23 01:20:12 UTC

[GitHub] [seatunnel] Hisoka-X commented on a diff in pull request #4803: [Feature][Connector-V2] jdbc connector supports KingbaseES database

Hisoka-X commented on code in PR #4803:
URL: https://github.com/apache/seatunnel/pull/4803#discussion_r1201383552


##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/kingbasees/KingbaseESTypeMapper.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.kingbasees;
+
+import org.apache.seatunnel.api.table.type.ArrayType;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.common.exception.CommonErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.jdbc.exception.JdbcConnectorException;
+import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectTypeMapper;
+
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+public class KingbaseESTypeMapper implements JdbcDialectTypeMapper {
+
+    private static final String KB_SMALLSERIAL = "SMALLSERIAL";
+    private static final String KB_SERIAL = "SERIAL";
+    private static final String KB_BIGSERIAL = "BIGSERIAL";
+    private static final String KB_BYTEA = "BYTEA";
+    private static final String KB_BYTEA_ARRAY = "_BYTEA";
+    private static final String KB_SMALLINT = "INT2";
+    private static final String KB_SMALLINT_ARRAY = "_INT2";
+    private static final String KB_INTEGER = "INT4";
+    private static final String KB_INTEGER_ARRAY = "_INT4";
+    private static final String KB_BIGINT = "INT8";
+    private static final String KB_BIGINT_ARRAY = "_INT8";
+    private static final String KB_REAL = "FLOAT4";
+    private static final String KB_REAL_ARRAY = "_FLOAT4";
+    private static final String KB_DOUBLE_PRECISION = "FLOAT8";
+    private static final String KB_DOUBLE_PRECISION_ARRAY = "_FLOAT8";
+    private static final String KB_NUMERIC = "NUMERIC";
+    private static final String KB_NUMERIC_ARRAY = "_NUMERIC";
+    private static final String KB_BOOLEAN = "BOOL";
+    private static final String KB_BOOLEAN_ARRAY = "_BOOL";
+    private static final String KB_TIMESTAMP = "TIMESTAMP";
+    private static final String KB_TIMESTAMP_ARRAY = "_TIMESTAMP";
+    private static final String KB_TIMESTAMPTZ = "TIMESTAMPTZ";
+    private static final String KB_TIMESTAMPTZ_ARRAY = "_TIMESTAMPTZ";
+    private static final String KB_DATE = "DATE";
+    private static final String KB_DATE_ARRAY = "_DATE";
+    private static final String KB_TIME = "TIME";
+    private static final String KB_TIME_ARRAY = "_TIME";
+    private static final String KB_TEXT = "TEXT";
+    private static final String KB_TEXT_ARRAY = "_TEXT";
+    private static final String KB_CHAR = "BPCHAR";
+    private static final String KB_CHAR_ARRAY = "_BPCHAR";
+    private static final String KB_CHARACTER = "CHARACTER";
+    private static final String KB_CHARACTER_ARRAY = "_CHARACTER";
+    private static final String KB_CHARACTER_VARYING = "VARCHAR";
+    private static final String KB_CHARACTER_VARYING_ARRAY = "_VARCHAR";
+    private static final String KB_JSON = "JSON";
+    private static final String KB_JSONB = "JSONB";
+
+    @SuppressWarnings("checkstyle:MagicNumber")
+    @Override
+    public SeaTunnelDataType<?> mapping(ResultSetMetaData metadata, int colIndex)
+            throws SQLException {
+
+        String kbType = metadata.getColumnTypeName(colIndex).toUpperCase();
+
+        int precision = metadata.getPrecision(colIndex);
+
+        switch (kbType) {
+            case KB_BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case KB_BOOLEAN_ARRAY:
+                return ArrayType.BOOLEAN_ARRAY_TYPE;
+            case KB_BYTEA:
+                return PrimitiveByteArrayType.INSTANCE;
+            case KB_BYTEA_ARRAY:
+                return ArrayType.BYTE_ARRAY_TYPE;
+            case KB_SMALLINT:

Review Comment:
   SMALLINT should map to short



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org