public static IFrameWriter assemblePipeline(AlgebricksPipeline subplan, IFrameWriter writer,
IHyracksTaskContext ctx) throws HyracksDataException {
boolean enforce = ctx.getJobFlags().contains(JobFlag.ENFORCE_CONTRACT);
IFrameWriter start = writer;
IPushRuntimeFactory[] runtimeFactories = subplan.getRuntimeFactories();
RecordDescriptor[] recordDescriptors = subplan.getRecordDescriptors();
for (int i = runtimeFactories.length - 1; i >= 0; i--) {
IPushRuntime newRuntime = runtimeFactories[i].createPushRuntime(ctx)[0];
newRuntime = enforce ? EnforcePushRuntime.enforce(newRuntime) : newRuntime;
start = enforce ? EnforceFrameWriter.enforce(start) : start;
newRuntime.setOutputFrameWriter(0, start, recordDescriptors[i]);
if (i > 0) {
newRuntime.setInputRecordDescriptor(0, recordDescriptors[i - 1]);
} else {
newRuntime.setInputRecordDescriptor(0, recordDescriptors[0]);
}
start = newRuntime;
}
return start;
}
}