if (parentLoad) {
EvalSpec spec = e.getSpec();
if (spec instanceof StreamSpec && !load.isSplittable()) {
// Try and optimize if the load and stream input specs match
// and input files are to be processed as-is
StreamSpec streamSpec = (StreamSpec)spec;
StreamingCommand command = streamSpec.getCommand();
HandleSpec streamInputSpec = command.getInputSpec();
FileSpec loadFileSpec = load.getInputFileSpec();
// Instantiate both to compare them for equality
StoreFunc streamStorer =
(StoreFunc)PigContext.instantiateFuncFromSpec(
streamInputSpec.getSpec());
LoadFunc inputLoader = (LoadFunc)PigContext.instantiateFuncFromSpec(
loadFileSpec.getFuncSpec());
// 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);
// 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
load.setInputFileSpec(new FileSpec(loadFileSpec.getFileName(), BinaryStorage.class.getName()));
streamSpec.setOptimizedSpec(Handle.INPUT,
BinaryStorage.class.getName());
optimize = true;
}
}
} else {
if (e.getSpec() instanceof StreamSpec) {
StreamSpec streamSpec = (StreamSpec)e.getSpec();
streamSpec.revertOptimizedCommand(Handle.INPUT);
}
}
parentLoad = false;
}