Java SQL Type toSqlType(String clickshouseType)

Here you can find the source of toSqlType(String clickshouseType)

Description

to Sql Type

License

Apache License

Declaration

public static int toSqlType(String clickshouseType) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.Types;

public class Main {
    public static int toSqlType(String clickshouseType) {
        if (isNullable(clickshouseType)) {
            clickshouseType = unwrapNullable(clickshouseType);
        }/* w w  w . ja  v a  2  s . co  m*/
        if (clickshouseType.startsWith("Int") || clickshouseType.startsWith("UInt")) {
            return clickshouseType.endsWith("64") ? Types.BIGINT : Types.INTEGER;
        }
        if ("String".equals(clickshouseType))
            return Types.VARCHAR;
        if (clickshouseType.startsWith("Float32"))
            return Types.FLOAT;
        if (clickshouseType.startsWith("Float64"))
            return Types.DOUBLE;
        if ("Date".equals(clickshouseType))
            return Types.DATE;
        if ("DateTime".equals(clickshouseType))
            return Types.TIMESTAMP;
        if ("FixedString".equals(clickshouseType))
            return Types.BLOB;
        if (isArray(clickshouseType))
            return Types.ARRAY;

        // don't know what to return actually
        return Types.VARCHAR;
    }

    private static boolean isNullable(String clickshouseType) {
        return clickshouseType.startsWith("Nullable(") && clickshouseType.endsWith(")");
    }

    private static String unwrapNullable(String clickshouseType) {
        return clickshouseType.substring("Nullable(".length(), clickshouseType.length() - 1);
    }

    private static boolean isArray(String clickhouseType) {
        return clickhouseType.startsWith("Array(") && clickhouseType.endsWith(")");
    }
}

Related

  1. toHCatType(int sqlType)
  2. toJavaType(int sqlType, String type)
  3. toOdaDataType(Class odiTypeClass)
  4. toSqlType(Class clazz)
  5. toSqlType(String clickshouseType)
  6. translateType(int sqlType)
  7. typeName(int type)
  8. typeNameToValueType(String typeName)
  9. typeToClass(int type)