StreamingCommand command = stream.getStreamingCommand();
HandleSpec streamInputSpec = command.getInputSpec();
FileSpec loadFileSpec = load.getInputFile();
// Instantiate both LoadFunc objects to compare them for
// equality
StoreFunc streamStorer =
(StoreFunc)PigContext.instantiateFuncFromSpec(
streamInputSpec.getSpec());
LoadFunc inputLoader = (LoadFunc)PigContext.instantiateFuncFromSpec(
loadFileSpec.getFuncSpec());
LogFactory.getLog(this.getClass()).info("streamStorer:" + streamStorer + "," +
"inputLoader:" + inputLoader);
// Check if the streaming command's inputSpec also implements
// LoadFunc and if it does, are they of the same _reversible_
// type?
boolean sameType = false;
try {
// Check if the streamStorer is _reversible_ as
// the inputLoader ...
if (streamStorer instanceof LoadFunc) {
// Cast to check if they are of the same type...
streamStorer.getClass().cast(inputLoader);
LogFactory.getLog(this.getClass()).info("streamStorer:" + streamStorer + "," +
"inputLoader:" + inputLoader);
// Now check if they both are reversible...
if (streamStorer instanceof ReversibleLoadStoreFunc &&
inputLoader instanceof ReversibleLoadStoreFunc) {
sameType = true;
}
}
} catch (ClassCastException cce) {
sameType = false;
}
// Check if both LoadFunc objects belong to the same type and
// are equivalent
if (sameType && streamStorer.equals(inputLoader)) {
// Since they both are the same, we can flip them
// for BinaryStorage
mOptimizeLoad = true;
}
}