Java SQL Type toHCatType(int sqlType)

Here you can find the source of toHCatType(int sqlType)

Description

Resolve a database-specific type to HCat data type.

License

Apache License

Parameter

Parameter Description
sqlType sql type

Return

hcat type

Declaration

public static String toHCatType(int sqlType) 

Method Source Code

//package com.java2s;
/**//www  .  j  a va 2 s . c om
 * 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.
 */

import java.sql.Types;

public class Main {
    /**
     * Resolve a database-specific type to HCat data type. Largely follows Sqoop's
     * hive translation.
     * @param sqlType
     *          sql type
     * @return hcat type
     */
    public static String toHCatType(int sqlType) {
        switch (sqlType) {

        // Ideally TINYINT and SMALLINT should be mapped to their
        // HCat equivalents tinyint and smallint respectively
        // But the Sqoop Java type conversion has them mapped to Integer
        // Even though the referenced Java doc clearly recommends otherwise.
        // Changing this now can cause many of the sequence file usages to
        // break as value class implementations will change. So, we
        // just use the same behavior here.
        case Types.SMALLINT:
        case Types.TINYINT:
        case Types.INTEGER:
            return "int";

        case Types.VARCHAR:
            return "varchar";
        case Types.CHAR:
            return "char";
        case Types.LONGVARCHAR:
        case Types.NVARCHAR:
        case Types.NCHAR:
        case Types.LONGNVARCHAR:
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
        case Types.CLOB:
            return "string";

        case Types.FLOAT:
        case Types.REAL:
            return "float";

        case Types.NUMERIC:
        case Types.DECIMAL:
            return "decimal";

        case Types.DOUBLE:
            return "double";

        case Types.BIT:
        case Types.BOOLEAN:
            return "boolean";

        case Types.BIGINT:
            return "bigint";

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.BLOB:
        case Types.LONGVARBINARY:
            return "binary";

        default:
            throw new IllegalArgumentException(
                    "Cannot convert SQL type to HCatalog type " + sqlType);
        }
    }
}

Related

  1. sqlTypeToHiveType(Integer type)
  2. sqlTypeToSetterGetter(int sqlType)
  3. sqlTypeToSqlTypeName(final int type)
  4. toClass(final int type)
  5. toClass(int sqlType, boolean isUnsigned)
  6. toJavaType(int sqlType, String type)
  7. toOdaDataType(Class odiTypeClass)
  8. toSqlType(Class clazz)
  9. toSqlType(String clickshouseType)