public Tuple next() throws IOException {
if (!dataFileReader.hasNext()) {
return null;
}
Tuple tuple = new VTuple(schema.size());
GenericRecord record = dataFileReader.next();
for (int i = 0; i < projectionMap.length; ++i) {
int columnIndex = projectionMap[i];
Object value = record.get(columnIndex);
if (value == null) {
tuple.put(columnIndex, NullDatum.get());
continue;
}
// Get Avro type.
Schema.Field avroField = avroFields.get(columnIndex);
Schema nonNullAvroSchema = getNonNull(avroField.schema());
Schema.Type avroType = nonNullAvroSchema.getType();
// Get Tajo type.
Column column = schema.getColumn(columnIndex);
DataType dataType = column.getDataType();
TajoDataTypes.Type tajoType = dataType.getType();
switch (avroType) {
case NULL:
tuple.put(columnIndex, NullDatum.get());
break;
case BOOLEAN:
tuple.put(columnIndex, DatumFactory.createBool((Boolean)value));
break;
case INT:
tuple.put(columnIndex, convertInt(value, tajoType));
break;
case LONG:
tuple.put(columnIndex, DatumFactory.createInt8((Long)value));
break;
case FLOAT:
tuple.put(columnIndex, DatumFactory.createFloat4((Float)value));
break;
case DOUBLE:
tuple.put(columnIndex, DatumFactory.createFloat8((Double)value));
break;
case BYTES:
tuple.put(columnIndex, convertBytes(value, tajoType, dataType));
break;
case STRING:
tuple.put(columnIndex, convertString(value, tajoType));
break;
case RECORD:
throw new RuntimeException("Avro RECORD not supported.");
case ENUM:
throw new RuntimeException("Avro ENUM not supported.");
case MAP:
throw new RuntimeException("Avro MAP not supported.");
case UNION:
throw new RuntimeException("Avro UNION not supported.");
case FIXED:
tuple.put(columnIndex, new BlobDatum(((GenericFixed)value).bytes()));
break;
default:
throw new RuntimeException("Unknown type.");
}
}