in metacat-connector-redshift/src/main/java/com/netflix/metacat/connector/redshift/RedshiftTypeConverter.java [126:191]
public String fromMetacatType(final Type type) {
switch (type.getTypeSignature().getBase()) {
case ARRAY:
throw new UnsupportedOperationException("Redshift doesn't support array types");
case BIGINT:
return "BIGINT";
case BOOLEAN:
return "BOOLEAN";
case CHAR:
if (!(type instanceof CharType)) {
throw new IllegalArgumentException("Expected CHAR type but was " + type.getClass().getName());
}
final CharType charType = (CharType) type;
return "CHAR(" + charType.getLength() + ")";
case DATE:
return "DATE";
case DECIMAL:
if (!(type instanceof DecimalType)) {
throw new IllegalArgumentException("Expected decimal type but was " + type.getClass().getName());
}
final DecimalType decimalType = (DecimalType) type;
return "DECIMAL(" + decimalType.getPrecision() + ", " + decimalType.getScale() + ")";
case DOUBLE:
case FLOAT:
return "DOUBLE PRECISION";
case INT:
return "INT";
case INTERVAL_DAY_TO_SECOND:
throw new UnsupportedOperationException("Redshift doesn't support interval types");
case INTERVAL_YEAR_TO_MONTH:
throw new UnsupportedOperationException("Redshift doesn't support interval types");
case JSON:
throw new UnsupportedOperationException("Redshift doesn't support JSON types");
case MAP:
throw new UnsupportedOperationException("Redshift doesn't support MAP types");
case ROW:
throw new UnsupportedOperationException("Redshift doesn't support ROW types");
case SMALLINT:
return "SMALLINT";
case STRING:
throw new UnsupportedOperationException("Redshift doesn't support STRING types");
case TIME:
case TIME_WITH_TIME_ZONE:
throw new UnsupportedOperationException("Redshift doesn't support TIME types");
case TIMESTAMP:
return "TIMESTAMP";
case TIMESTAMP_WITH_TIME_ZONE:
return "TIMESTAMPZ";
case TINYINT:
// NOTE: There is no tiny int type in Redshift so using slightly larger SMALLINT
return "SMALLINT";
case UNKNOWN:
throw new IllegalArgumentException("Can't map an unknown type");
case VARBINARY:
throw new UnsupportedOperationException("Redshift doesn't support VARBINARY types");
case VARCHAR:
if (!(type instanceof VarcharType)) {
throw new IllegalArgumentException("Expected varchar type but was " + type.getClass().getName());
}
final VarcharType varcharType = (VarcharType) type;
// NOTE: PostgreSQL lets you store up to 1GB in a varchar field which is about the same as TEXT
return "VARCHAR(" + varcharType.getLength() + ")";
default:
throw new IllegalArgumentException("Unknown type " + type.getTypeSignature().getBase());
}
}