in hologres-connector-datax-writer/src/main/java/com/alibaba/datax/plugin/writer/hologresjdbcwriter/BaseWriter.java [384:527]
protected void fillColumn(Put data, TableSchema schema, int index, Column column) throws SQLException {
org.postgresql.model.Column holoColumn = schema.getColumn(index);
java.util.Date utilDate;
switch (holoColumn.getType()) {
case Types.CHAR:
case Types.NCHAR:
case Types.CLOB:
case Types.NCLOB:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.NVARCHAR:
case Types.LONGNVARCHAR:
String value = column.asString();
if (emptyAsNull && value != null && value.length() == 0) {
data.setObject(index, null);
} else {
data.setObject(index, value);
}
break;
case Types.SMALLINT:
if (column.getByteSize() > 0) {
data.setObject(index, column.asBigInteger().shortValue());
} else if (emptyAsNull) {
data.setObject(index, null);
}
break;
case Types.INTEGER:
if (column.getByteSize() > 0) {
data.setObject(index, column.asBigInteger().intValue());
} else if (emptyAsNull) {
data.setObject(index, null);
}
break;
case Types.BIGINT:
if (column.getByteSize() > 0) {
data.setObject(index, column.asBigInteger().longValue());
} else if (emptyAsNull) {
data.setObject(index, null);
}
break;
case Types.NUMERIC:
case Types.DECIMAL:
if (column.getByteSize() > 0) {
data.setObject(index, column.asBigDecimal());
} else if (emptyAsNull) {
data.setObject(index, null);
}
break;
case Types.FLOAT:
case Types.REAL:
if (column.getByteSize() > 0) {
data.setObject(index, column.asBigDecimal().floatValue());
} else if (emptyAsNull) {
data.setObject(index, null);
}
break;
case Types.DOUBLE:
if (column.getByteSize() > 0) {
data.setObject(index, column.asDouble());
} else if (emptyAsNull) {
data.setObject(index, null);
}
break;
case Types.TIME:
if (column.getByteSize() > 0) {
if (column instanceof LongColumn || column instanceof DateColumn) {
data.setObject(index, new Time(column.asLong()));
} else {
data.setObject(index, column.asString());
}
} else if (emptyAsNull) {
data.setObject(index, null);
}
break;
case Types.DATE:
if (column.getByteSize() > 0) {
if (column instanceof LongColumn || column instanceof DateColumn) {
data.setObject(index, column.asLong());
} else {
data.setObject(index, column.asString());
}
} else if (emptyAsNull) {
data.setObject(index, null);
}
break;
case Types.TIMESTAMP:
if (column.getByteSize() > 0) {
if (column instanceof LongColumn || column instanceof DateColumn) {
data.setObject(index, new Timestamp(column.asLong()));
} else {
data.setObject(index, column.asString());
}
} else if (emptyAsNull) {
data.setObject(index, null);
}
break;
case Types.BINARY:
case Types.VARBINARY:
case Types.BLOB:
case Types.LONGVARBINARY:
String byteValue = column.asString();
if (null != byteValue) {
data.setObject(index, column
.asBytes());
}
break;
case Types.BOOLEAN:
case Types.BIT:
if (column.getByteSize() == 0) {
break;
}
try {
Boolean boolValue = column.asBoolean();
data.setObject(index, boolValue);
} catch (Exception e) {
data.setObject(index, !"0".equals(column.asString()));
}
break;
case Types.ARRAY:
String arrayString = column.asString();
Object arrayObject = null;
if (null == arrayString || (emptyAsNull && "".equals(arrayString))) {
data.setObject(index, null);
break;
} else if (arrayDelimiter != null && arrayDelimiter.length() > 0) {
arrayObject = arrayString.split(this.arrayDelimiter);
} else {
arrayObject = JSONArray.parseArray(arrayString);
}
data.setObject(index, arrayObject);
break;
default:
throw DataXException
.asDataXException(
DBUtilErrorCode.UNSUPPORTED_TYPE,
String.format(
"您的配置文件中的列配置信息有误. 因为DataX 不支持数据库写入这种字段类型. 字段名:[%s], 字段类型:[%d], 字段Java类型:[%s]. 请修改表中该字段的类型或者不同步该字段.",
holoColumn.getName(),
holoColumn.getType(),
holoColumn.getTypeName()));
}
}