in hologres-connector-hive-base/src/main/java/com/alibaba/hologres/hive/HoloSerDe.java [145:263]
private void validateColumns(
TableSchema schema, String[] hiveColumnNames, TypeInfo[] hiveColumnTypes) {
for (int i = 0; i < hiveColumnCount; i++) {
String columnName = hiveColumnNames[i];
Column holoColumn;
try {
holoColumn = schema.getColumn(schema.getColumnIndex(columnName));
} catch (NullPointerException e) {
throw new IllegalArgumentException(
String.format("Column %s does not exist in hologres!", columnName));
}
boolean matched = false;
if (holoColumn.getType() == Types.ARRAY) {
String arrayElementTypeName =
((ListTypeInfo) hiveColumnTypes[i]).getListElementTypeInfo().getTypeName();
switch (holoColumn.getTypeName()) {
case "_int4":
matched = ("int".equals(arrayElementTypeName));
break;
case "_int8":
matched = ("bigint".equals(arrayElementTypeName));
break;
case "_float4":
matched = ("float".equals(arrayElementTypeName));
break;
case "_float8":
matched = ("double".equals(arrayElementTypeName));
break;
case "_bool":
matched = ("boolean".equals(arrayElementTypeName));
break;
case "_varchar":
case "_text":
matched = ("string".equals(arrayElementTypeName));
break;
default:
throw new IllegalArgumentException(
String.format(
"Does not support array element type %s , column name %s!",
arrayElementTypeName, hiveColumnNames[i]));
}
} else {
PrimitiveCategory columnType =
((PrimitiveTypeInfo) hiveColumnTypes[i]).getPrimitiveCategory();
switch (holoColumn.getType()) {
case Types.TINYINT:
matched = (columnType == PrimitiveCategory.BYTE);
break;
case Types.SMALLINT:
matched = (columnType == PrimitiveCategory.SHORT);
break;
case Types.INTEGER:
matched = (columnType == PrimitiveCategory.INT);
break;
case Types.BIGINT:
matched = (columnType == PrimitiveCategory.LONG);
break;
case Types.REAL:
case Types.FLOAT:
matched = (columnType == PrimitiveCategory.FLOAT);
break;
case Types.DOUBLE:
matched = (columnType == PrimitiveCategory.DOUBLE);
break;
case Types.NUMERIC:
case Types.DECIMAL:
matched = (columnType == PrimitiveCategory.DECIMAL);
break;
case Types.BOOLEAN:
case Types.BIT:
matched = (columnType == PrimitiveCategory.BOOLEAN);
break;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
matched = (columnType == PrimitiveCategory.STRING);
break;
case Types.DATE:
matched = (columnType == PrimitiveCategory.DATE);
break;
case Types.TIMESTAMP:
matched = (columnType == PrimitiveCategory.TIMESTAMP);
break;
case Types.BINARY:
case Types.VARBINARY:
matched = (columnType == PrimitiveCategory.BINARY);
break;
case Types.OTHER:
switch (holoColumn.getTypeName()) {
case "json":
case "jsonb":
matched = (columnType == PrimitiveCategory.STRING);
break;
case "roaringbitmap":
matched = (columnType == PrimitiveCategory.BINARY);
break;
default:
throw new IllegalArgumentException(
String.format(
"Does not support column %s with data type %s and hologres type %s for now!",
columnName, columnType, holoColumn.getTypeName()));
}
break;
default:
throw new IllegalArgumentException(
String.format(
"Does not support column %s with data type %s and hologres type %s for now!",
columnName, columnType, holoColumn.getTypeName()));
}
}
if (!matched) {
throw new IllegalArgumentException(
String.format(
"Column %s with data type %s does not match the hologres data type!",
columnName, hiveColumnTypes[i].getTypeName()));
}
}
}