in holo-client/src/main/java/com/alibaba/hologres/client/impl/RecordReader.java [129:229]
private void fillRecord() throws IOException {
cellBuffer.flip();
if (currentRecord == null) {
currentRecord = new Record(schema);
}
Column column = schema.getColumn(currentColumnIndex);
int type = column.getType();
if (cellBuffer.remaining() == 0) {
switch (type) {
case Types.CHAR:
case Types.NCHAR:
case Types.CLOB:
case Types.NCLOB:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.NVARCHAR:
case Types.LONGNVARCHAR:
currentRecord.setObject(currentColumnIndex, "");
break;
default:
currentRecord.setObject(currentColumnIndex, null);
}
} else {
byte[] temp = null;
String text = null;
try {
temp = new byte[cellBuffer.remaining()];
cellBuffer.get(temp);
text = new String(temp, UTF8);
if (text.equals(NULL)) {
currentRecord.setObject(currentColumnIndex, null);
}
else {
switch (type) {
case Types.CHAR:
case Types.NCHAR:
case Types.CLOB:
case Types.NCLOB:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.NVARCHAR:
case Types.LONGNVARCHAR:
case Types.ARRAY:
currentRecord.setObject(currentColumnIndex, text);
break;
case Types.TIME:
case Types.TIME_WITH_TIMEZONE:
currentRecord.setObject(currentColumnIndex, timestampUtils.toTime(null, text));
break;
case Types.DATE:
currentRecord.setObject(currentColumnIndex, timestampUtils.toDate(null, text));
break;
case Types.TIMESTAMP:
case Types.TIMESTAMP_WITH_TIMEZONE:
currentRecord.setObject(currentColumnIndex, timestampUtils.toTimestamp(null, text));
break;
case Types.SMALLINT:
currentRecord.setObject(currentColumnIndex, Short.parseShort(text));
break;
case Types.INTEGER:
currentRecord.setObject(currentColumnIndex, Integer.parseInt(text));
break;
case Types.BIGINT:
currentRecord.setObject(currentColumnIndex, Long.parseLong(text));
break;
case Types.NUMERIC:
case Types.DECIMAL:
currentRecord.setObject(currentColumnIndex, new BigDecimal(text));
break;
case Types.FLOAT:
case Types.REAL:
currentRecord.setObject(currentColumnIndex, Float.parseFloat(text));
break;
case Types.DOUBLE:
currentRecord.setObject(currentColumnIndex, Double.parseDouble(text));
break;
case Types.BINARY:
case Types.VARBINARY:
case Types.BLOB:
case Types.LONGVARBINARY:
case Types.OTHER:
byte[] temp2 = new byte[temp.length];
System.arraycopy(temp, 0, temp2, 0, temp.length);
currentRecord.setObject(currentColumnIndex, temp2);
break;
case Types.BOOLEAN:
case Types.BIT:
currentRecord.setObject(currentColumnIndex, Boolean.parseBoolean(text));
break;
default:
throw new IOException("unsupported type " + type + " type name:" + column.getTypeName());
}
}
} catch (Exception e) {
throw new IOException("fill column " + column.getName() + " fail.index:" + currentRecord + " record:" + currentRecord + ", bytes:" + (temp != null ? Arrays.toString(temp) : "null") + ", text:" + text, e);
}
}
cellBuffer.clear();
++currentColumnIndex;
}