use of org.apache.gora.mapreduce.GoraRecordWriter in project gora by apache.
the class GoraStorage method putNext.
@SuppressWarnings("unchecked")
@Override
public void putNext(Tuple pigTuple) throws IOException {
PersistentBase persistentObj = this.dataStore.newPersistent();
if (LOG.isTraceEnabled())
LOG.trace("key: {}", pigTuple.get(pigFieldKeyIndex));
for (String fieldName : this.loadQueryFields) {
if (LOG.isTraceEnabled()) {
LOG.trace(" Put fieldname: {}", fieldName);
LOG.trace(" resourcefield schema: {}", this.writeResourceFieldSchemaMap.get(fieldName).getResourceFieldSchema());
LOG.trace(" value: {} - {}", this.writeResourceFieldSchemaMap.get(fieldName).getIndex(), pigTuple.get(this.writeResourceFieldSchemaMap.get(fieldName).getIndex()));
}
ResourceFieldSchemaWithIndex writeResourceFieldSchemaWithIndex = this.writeResourceFieldSchemaMap.get(fieldName);
if (writeResourceFieldSchemaWithIndex == null) {
if (LOG.isTraceEnabled())
LOG.trace("Field {} defined in constructor not found in the tuple to persist, skipping field", fieldName);
continue;
}
Field persistentField = persistentSchema.getField(fieldName);
if (persistentField == null) {
throw new IOException("Field " + fieldName + " does not exist in the Gora's Avro schema.");
}
ResourceFieldSchema pigFieldSchema = writeResourceFieldSchemaWithIndex.getResourceFieldSchema();
if (pigFieldSchema == null) {
throw new IOException("The field " + fieldName + " does not have a Pig schema when writing.");
}
// TODO Move this put to PersistentUtils
// TODO Here is used the resourceFieldSchema and the index. Think about optimize if possible
// TODO Find a better name to this.writeField, like 'tupleToPersistent'
int persistentFieldIndex = persistentObj.getSchema().getField(fieldName).pos();
persistentObj.put(persistentFieldIndex, this.writeField(persistentField.schema(), pigFieldSchema, pigTuple.get(writeResourceFieldSchemaWithIndex.getIndex())));
persistentObj.setDirty(persistentFieldIndex);
}
try {
((GoraRecordWriter<Object, PersistentBase>) this.writer).write(pigTuple.get(pigFieldKeyIndex), (PersistentBase) persistentObj);
} catch (InterruptedException e) {
throw new IOException("Error writing the tuple.", e);
}
}
Aggregations