tid = projectionMap[i];
// if the column is byte[0], it presents a NULL value.
if (column.get(tid).getLength() == 0) {
tuple.put(tid, DatumFactory.createNullDatum());
} else {
DataType dataType = targets[i].getDataType();
switch (dataType.getType()) {
case BOOLEAN:
tuple.put(tid,
DatumFactory.createBool(column.get(tid).getBytesCopy()[0]));
break;
case BIT:
tuple.put(tid,
DatumFactory.createBit(column.get(tid).getBytesCopy()[0]));
break;
case CHAR:
byte[] buf = column.get(tid).getBytesCopy();
tuple.put(tid,
DatumFactory.createChar(buf));
break;
case INT2:
tuple.put(tid,
DatumFactory.createInt2(Bytes.toShort(
column.get(tid).getBytesCopy())));
break;
case INT4:
tuple.put(tid,
DatumFactory.createInt4(Bytes.toInt(
column.get(tid).getBytesCopy())));
break;
case INT8:
tuple.put(tid,
DatumFactory.createInt8(Bytes.toLong(
column.get(tid).getBytesCopy())));
break;
case FLOAT4:
tuple.put(tid,
DatumFactory.createFloat4(Bytes.toFloat(
column.get(tid).getBytesCopy())));
break;
case FLOAT8:
tuple.put(tid,
DatumFactory.createFloat8(Bytes.toDouble(
column.get(tid).getBytesCopy())));
break;
case TEXT:
tuple.put(tid,
DatumFactory.createText(
column.get(tid).getBytesCopy()));
break;
case PROTOBUF: {
ProtobufDatumFactory factory = ProtobufDatumFactory.get(dataType.getCode());
Message.Builder builder = factory.newBuilder();
builder.mergeFrom(column.get(tid).getBytesCopy());
tuple.put(tid, factory.createDatum(builder));
break;
}