You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "NickYoungPeng (via GitHub)" <gi...@apache.org> on 2023/09/06 13:27:33 UTC

[GitHub] [seatunnel] NickYoungPeng commented on a diff in pull request #5424: [Feature][Hive JDBC Source] Support Hive JDBC Source Connector

NickYoungPeng commented on code in PR #5424:
URL: https://github.com/apache/seatunnel/pull/5424#discussion_r1317283427


##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/hive/HiveTypeMapper.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.hive;
+
+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.SeaTunnelDataType;
+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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+public class HiveTypeMapper implements JdbcDialectTypeMapper {
+
+    private static final Logger LOG = LoggerFactory.getLogger(HiveTypeMapper.class);
+
+    // reference https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types
+
+    // Numeric Types
+    private static final String HIVE_TINYINT = "TINYINT";
+    private static final String HIVE_SMALLINT = "SMALLINT";
+    private static final String HIVE_INT = "INT";
+    private static final String HIVE_INTEGER = "INTEGER";
+    private static final String HIVE_BIGINT = "BIGINT";
+    private static final String HIVE_FLOAT = "FLOAT";
+    private static final String HIVE_DOUBLE = "DOUBLE";
+    private static final String HIVE_DOUBLE_PRECISION = "DOUBLE PRECISION";
+    private static final String HIVE_DECIMAL = "DECIMAL";
+    private static final String HIVE_NUMERIC = "NUMERIC";
+    // Date/Time Types
+    private static final String HIVE_TIMESTAMP = "TIMESTAMP";
+    private static final String HIVE_DATE = "DATE";
+    private static final String HIVE_INTERVAL = "INTERVAL";
+    // String Types
+    private static final String HIVE_STRING = "STRING";
+    private static final String HIVE_VARCHAR = "VARCHAR";
+    private static final String HIVE_CHAR = "CHAR";
+    // Misc Types
+    private static final String HIVE_BOOLEAN = "BOOLEAN";
+    private static final String HIVE_BINARY = "BINARY";
+    // Complex Types
+    private static final String HIVE_ARRAY = "ARRAY";
+    private static final String HIVE_MAP = "MAP";
+    // float
+    private static final String HIVE_STRUCT = "STRUCT";
+    private static final String HIVE_UNIONTYPE = "UNIONTYPE";
+
+    @Override
+    public SeaTunnelDataType<?> mapping(ResultSetMetaData metadata, int colIndex)
+            throws SQLException {
+        String columnType = metadata.getColumnTypeName(colIndex).toUpperCase();
+        int precision = metadata.getPrecision(colIndex);
+        switch (columnType) {
+            case HIVE_TINYINT:
+            case HIVE_SMALLINT:
+                return BasicType.SHORT_TYPE;
+            case HIVE_INT:
+            case HIVE_INTEGER:
+                return BasicType.INT_TYPE;
+            case HIVE_BIGINT:
+                return BasicType.LONG_TYPE;
+            case HIVE_FLOAT:
+                return BasicType.FLOAT_TYPE;
+            case HIVE_DOUBLE:
+            case HIVE_DOUBLE_PRECISION:
+                return BasicType.DOUBLE_TYPE;
+            case HIVE_DECIMAL:
+            case HIVE_NUMERIC:
+                if (precision > 0) {
+                    return new DecimalType(precision, metadata.getScale(colIndex));
+                }
+                LOG.warn("decimal did define precision,scale, will be Decimal(38,18)");
+                return new DecimalType(38, 18);

Review Comment:
   I think it should maintain similar data types



-- 
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