Java SQL Type sqlTypeToHiveType(Integer type)

Here you can find the source of sqlTypeToHiveType(Integer type)

Description

sql Type To Hive Type

License

Apache License

Declaration

public static String sqlTypeToHiveType(Integer type) 

Method Source Code

//package com.java2s;
/*-/*w  w w  . j a  v  a  2  s  .  c  o  m*/
 * #%L
 * thinkbig-schema-discovery-api
 * %%
 * Copyright (C) 2017 ThinkBig Analytics
 * %%
 * Licensed 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.
 * #L%
 */

import java.sql.JDBCType;
import java.sql.Types;

public class Main {
    public static String sqlTypeToHiveType(Integer type) {
        switch (type) {
        case Types.BIGINT:
            return "bigint";
        case Types.NUMERIC:
        case Types.DOUBLE:
        case Types.DECIMAL:
            return "double";
        case Types.INTEGER:
            return "int";
        case Types.FLOAT:
            return "float";
        case Types.TINYINT:
            return "tinyint";
        case Types.DATE:
            return "date";
        case Types.TIMESTAMP:
            return "timestamp";
        case Types.BOOLEAN:
            return "boolean";
        case Types.BINARY:
            return "binary";
        default:
            return "string";
        }
    }

    public static String sqlTypeToHiveType(JDBCType jdbcType) {
        if (jdbcType != null) {
            Integer type = jdbcType.getVendorTypeNumber();
            return sqlTypeToHiveType(type);

        }
        return null;
    }
}

Related

  1. sqlTypeIsNumeric(int sqlType)
  2. sqlTypeName(final int value)
  3. sqlTypeString(int sqlType)
  4. sqlTypeToClass(int sqlType, String className)
  5. sqlTypeToClassType(final Integer sqlType)
  6. sqlTypeToSetterGetter(int sqlType)
  7. sqlTypeToSqlTypeName(final int type)
  8. toClass(final int type)
  9. toClass(int sqlType, boolean isUnsigned)