}
@Override
public void addTuple(Tuple tuple) throws IOException {
Column col;
Datum datum;
int colNum = schema.getColumnNum();
if (tuple instanceof LazyTuple) {
LazyTuple lTuple = (LazyTuple)tuple;
for (int i = 0; i < colNum; i++) {
TajoDataTypes.DataType dataType = schema.getColumn(i).getDataType();
switch (dataType.getType()) {
case TEXT: {
datum = tuple.get(i);
if (datum instanceof NullDatum) {
outputStream.write(nullChars);
} else {
outputStream.write(datum.asTextBytes());
}
break;
}
case CHAR: {
datum = tuple.get(i);
if (datum instanceof NullDatum) {
outputStream.write(nullChars);
} else {
byte[] pad = new byte[dataType.getLength() - datum.size()];
outputStream.write(datum.asTextBytes());
outputStream.write(pad);
}
break;
}
case BOOLEAN: {
datum = tuple.get(i);
if (datum instanceof NullDatum) {
//null datum is zero length byte array
} else {
outputStream.write(datum.asBool() ? trueBytes : falseBytes); //Compatibility with Apache Hive
}
break;
}
case NULL:
break;
case PROTOBUF:
datum = tuple.get(i);
ProtobufDatum protobufDatum = (ProtobufDatum) datum;
protobufJsonFormat.print(protobufDatum.get(), outputStream);
break;
default:
outputStream.write(lTuple.getTextBytes(i)); //better usage for insertion to table of lazy tuple
break;
}
if(colNum - 1 > i){
outputStream.write((byte) delimiter);
}
if (enabledStats) {
datum = tuple.get(i);
stats.analyzeField(i, datum);
}
}
} else {
for (int i = 0; i < schema.getColumnNum(); i++) {
datum = tuple.get(i);
if (enabledStats) {
stats.analyzeField(i, datum);
}
if (datum instanceof NullDatum) {
outputStream.write(nullChars);
} else {
col = schema.getColumn(i);
switch (col.getDataType().getType()) {
case BOOLEAN:
outputStream.write(tuple.getBoolean(i).asBool() ? trueBytes : falseBytes); //Compatibility with Apache Hive
break;
case BIT:
outputStream.write(tuple.getByte(i).asTextBytes());
break;
case BLOB:
outputStream.write(Base64.encodeBase64(tuple.getBytes(i).asByteArray(), false));
break;
case CHAR:
CharDatum charDatum = tuple.getChar(i);
byte[] pad = new byte[col.getDataType().getLength() - datum.size()];
outputStream.write(charDatum.asTextBytes());
outputStream.write(pad);
break;
case TEXT:
outputStream.write(tuple.getText(i).asTextBytes());