Operator refOp = expr.getImplicitReferencedOperator();
Operator attachedOp = expr.getAttachedLogicalOperator();
LogicalPlan lp = (LogicalPlan) attachedOp.getPlan();
List<Operator> succs = lp.getSuccessors( refOp );
LOStore store = null;
FuncSpec interStorageFuncSpec = new FuncSpec(InterStorage.class.getName());
if( succs != null ) {
for( Operator succ : succs ) {
if( succ instanceof LOStore
&& ((LOStore)succ).isTmpStore()
&& interStorageFuncSpec.equals(
((LOStore)succ).getOutputSpec().getFuncSpec() ) ) {
store = (LOStore)succ;
break;
}
}
}
if( store == null ) {
FileSpec fileSpec;
try {
fileSpec = new FileSpec( FileLocalizer.getTemporaryPath( pigContext ).toString(), interStorageFuncSpec ); // TODO: need to hookup the pigcontext.
} catch (IOException e) {
throw new PlanValidationException( expr, "Failed to process scalar" + e);
}
StoreFuncInterface stoFunc = (StoreFuncInterface)PigContext.instantiateFuncFromSpec(interStorageFuncSpec);
String sig = LogicalPlanBuilder.newOperatorKey(scope);
stoFunc.setStoreFuncUDFContextSignature(sig);
store = new LOStore(lp, fileSpec, stoFunc, sig);
store.setTmpStore(true);
lp.add( store );
lp.connect( refOp, store );
}
expr.setImplicitReferencedOperator(store);
filenameConst.setValue( store.getOutputSpec().getFileName() );
if( lp.getSoftLinkSuccessors( store ) == null ||
!lp.getSoftLinkSuccessors( store ).contains( attachedOp ) ) {
lp.createSoftLink( store, attachedOp );
}