in tajo-storage/src/main/java/org/apache/tajo/storage/TextSerializerDeserializer.java [106:198]
public Datum deserialize(Column col, byte[] bytes, int offset, int length, byte[] nullCharacters) throws IOException {
Datum datum;
switch (col.getDataType().getType()) {
case BOOLEAN:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createBool(bytes[offset] == 't' || bytes[offset] == 'T');
break;
case BIT:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createBit(Byte.parseByte(new String(bytes, offset, length)));
break;
case CHAR:
datum = isNullText(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createChar(new String(bytes, offset, length).trim());
break;
case INT2:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createInt2((short) Bytes.parseInt(bytes, offset, length));
break;
case INT4:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createInt4(Bytes.parseInt(bytes, offset, length));
break;
case INT8:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createInt8(new String(bytes, offset, length));
break;
case FLOAT4:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createFloat4(new String(bytes, offset, length));
break;
case FLOAT8:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createFloat8(Bytes.parseDouble(bytes, offset, length));
break;
case TEXT: {
byte[] chars = new byte[length];
System.arraycopy(bytes, offset, chars, 0, length);
datum = isNullText(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createText(chars);
break;
}
case DATE:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createDate(new String(bytes, offset, length));
break;
case TIME:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createTime(new String(bytes, offset, length));
break;
case TIMESTAMP:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createTimeStamp(new String(bytes, offset, length));
break;
case PROTOBUF: {
if (isNull(bytes, offset, length, nullCharacters)) {
datum = NullDatum.get();
} else {
ProtobufDatumFactory factory = ProtobufDatumFactory.get(col.getDataType());
Message.Builder builder = factory.newBuilder();
try {
byte[] protoBytes = new byte[length];
System.arraycopy(bytes, offset, protoBytes, 0, length);
protobufJsonFormat.merge(protoBytes, builder);
datum = factory.createDatum(builder.build());
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
break;
}
case INET4:
datum = isNull(bytes, offset, length, nullCharacters) ? NullDatum.get()
: DatumFactory.createInet4(new String(bytes, offset, length));
break;
case BLOB: {
if (isNull(bytes, offset, length, nullCharacters)) {
datum = NullDatum.get();
} else {
byte[] blob = new byte[length];
System.arraycopy(bytes, offset, blob, 0, length);
datum = DatumFactory.createBlob(Base64.decodeBase64(blob));
}
break;
}
default:
datum = NullDatum.get();
break;
}
return datum;
}