in src/main/java/com/aliyun/odps/jdbc/utils/JdbcColumn.java [146:203]
public static int columnPrecision(TypeInfo typeInfo) throws SQLException {
int columnType = odpsTypeToSqlType(typeInfo.getOdpsType());
// according to odpsTypeToSqlType possible options are:
switch (columnType) {
case Types.NULL:
return 0;
case Types.BOOLEAN:
return 1;
case Types.CHAR:
case Types.VARCHAR:
if (typeInfo instanceof VarcharTypeInfo) {
return ((VarcharTypeInfo) typeInfo).getLength();
}
if (typeInfo instanceof CharTypeInfo) {
return ((CharTypeInfo) typeInfo).getLength();
}
return Integer.MAX_VALUE; // hive has no max limit for strings
case Types.BINARY:
return Integer.MAX_VALUE; // hive has no max limit for binary
case Types.TINYINT:
return 3;
case Types.SMALLINT:
return 5;
case Types.INTEGER:
return 10;
case Types.BIGINT:
return 19;
case Types.FLOAT:
return 7;
case Types.DOUBLE:
return 15;
case Types.DATE:
return 10;
case Types.TIMESTAMP:
return 29;
case Types.DECIMAL:
return ((DecimalTypeInfo) typeInfo).getPrecision();
case Types.OTHER:
case Types.JAVA_OBJECT: {
if (typeInfo instanceof SimplePrimitiveTypeInfo) {
SimplePrimitiveTypeInfo spti = (SimplePrimitiveTypeInfo) typeInfo;
if (OdpsType.INTERVAL_YEAR_MONTH.equals(spti.getOdpsType())) {
// -yyyyyyy-mm : should be more than enough
return 11;
} else if (OdpsType.INTERVAL_DAY_TIME.equals(spti.getOdpsType())) {
// -ddddddddd hh:mm:ss.nnnnnnnnn
return 29;
}
}
return Integer.MAX_VALUE;
}
case Types.ARRAY:
case Types.STRUCT:
return Integer.MAX_VALUE;
default:
throw new SQLException("Invalid odps type: " + columnType);
}
}