tupleTemplate = null;
/**
*
* @param protoClassName full classpath to the generated Protocol Buffer to be loaded.
*/
public ProtobufPigLoader(String protoClassName) {
typeRef = PigUtil.getProtobufTypeRef(protoClassName);
}
@Override
public RequiredFieldResponse pushProjection(RequiredFieldList requiredFieldList)
throws FrontendException {
return pushProjectionHelper(requiredFieldList);
}
/**
* Return every non-null line as a single-element tuple to Pig.
*
* A small fraction of bad records in input are tolerated.
* See {@link LzoRecordReader} for more information on error handling.
*/
@Override
public Tuple getNext() throws IOException {
if (tupleTemplate == null) {
tupleTemplate = new ProjectedProtobufTupleFactory(typeRef, requiredFieldList);
}
M value = getNextBinaryValue(typeRef);
return value != null ?
tupleTemplate.newTuple(value) : null;
}
@Override
public ResourceSchema getSchema(String filename, Job job) throws IOException {
return new ResourceSchema(protoToPig.toSchema(Protobufs.getMessageDescriptor(typeRef.getRawClass())));
}
@Override
public InputFormat> getInputFormat() throws IOException {
if (typeRef == null) {
LOG.error("Protobuf class must be specified before an InputFormat can be created. Do not use the no-argument constructor.");
throw new IllegalArgumentException("Protobuf class must be specified before an InputFormat can be created. Do not use the no-argument constructor.");
}
return new MultiInputFormat(typeRef);
}
}