public Operator[] process(final Operator[] contracts) { for (final Operator contract : contracts) contract.accept(this); for (int index = 0; index < contracts.length; index++) if (!(contracts[index] instanceof GenericDataSink)) contracts[index] = this.replaceWithDefaultOutput(contracts[index]); return contracts; }
/** * Traverses the test plan and returns all contracts that process the data * of the given contract. * * @param contract * the contract of which preceding contracts should be returned * @return returns all contracts that process the data of the given contract */ public Operator[] getOutputsOfOperator(final Operator contract) { final ArrayList<Operator> outputs = new ArrayList<Operator>(); for (final Operator sink : this.sinks) sink.accept(new Visitor<Operator>() { LinkedList<Operator> outputStack = new LinkedList<Operator>(); @Override public void postVisit(final Operator visitable) { } @Override public boolean preVisit(final Operator visitable) { if (visitable == contract) outputs.add(this.outputStack.peek()); this.outputStack.push(visitable); return true; } }); return outputs.toArray(new Operator[outputs.size()]); }
/** * Accepts the visitor and applies it this instance. The visitors pre-visit method is called and, if returning * <tt>true</tt>, the visitor is recursively applied on the single input. After the recursion returned, * the post-visit method is called. * * @param visitor The visitor. * * @see eu.stratosphere.util.Visitable#accept(eu.stratosphere.util.Visitor) */ @Override public void accept(Visitor<Operator<?>> visitor) { if (visitor.preVisit(this)) { this.input.accept(visitor); for (Operator<?> c : this.broadcastInputs.values()) { c.accept(visitor); } visitor.postVisit(this); } } }
/** * Accepts the visitor and applies it this instance. The visitors pre-visit method is called and, if returning * <tt>true</tt>, the visitor is recursively applied on the single input. After the recursion returned, * the post-visit method is called. * * @param visitor The visitor. * * @see eu.stratosphere.util.Visitable#accept(eu.stratosphere.util.Visitor) */ @Override public void accept(Visitor<Operator<?>> visitor) { if (visitor.preVisit(this)) { this.input.accept(visitor); for (Operator<?> c : this.broadcastInputs.values()) { c.accept(visitor); } visitor.postVisit(this); } } }
@Override public boolean preVisit(Operator<?> visitable) { if (this.seen.add(visitable)) { // add to the map final String name = visitable.getName(); List<Operator<?>> list = this.map.get(name); if (list == null) { list = new ArrayList<Operator<?>>(2); this.map.put(name, list); } list.add(visitable); // recurse into bulk iterations if (visitable instanceof BulkIteration) { ((BulkIteration) visitable).getNextPartialSolution().accept(this); } else if (visitable instanceof DeltaIteration) { ((DeltaIteration) visitable).getSolutionSetDelta().accept(this); ((DeltaIteration) visitable).getNextWorkset().accept(this); } return true; } else { return false; } }
/** * Accepts the visitor and applies it this instance. This method applies the visitor in a depth-first traversal. * The visitors pre-visit method is called and, if returning * <tt>true</tt>, the visitor is recursively applied on the single input. After the recursion returned, * the post-visit method is called. * * @param visitor The visitor. * * @see eu.stratosphere.util.Visitable#accept(eu.stratosphere.util.Visitor) */ @Override public void accept(Visitor<Operator<?>> visitor) { boolean descend = visitor.preVisit(this); if (descend) { this.input.accept(visitor); visitor.postVisit(this); } }
/** * Accepts the visitor and applies it this instance. This method applies the visitor in a depth-first traversal. * The visitors pre-visit method is called and, if returning * <tt>true</tt>, the visitor is recursively applied on the single input. After the recursion returned, * the post-visit method is called. * * @param visitor The visitor. * * @see eu.stratosphere.util.Visitable#accept(eu.stratosphere.util.Visitor) */ @Override public void accept(Visitor<Operator<?>> visitor) { boolean descend = visitor.preVisit(this); if (descend) { this.input.accept(visitor); visitor.postVisit(this); } }
/** * Traverses the plan for all sinks and sources. */ @SuppressWarnings({ "unchecked", "rawtypes" }) private void findSinksAndSources() { for (final Operator contract : this.contracts) contract.accept(new Visitor<Operator>() { @Override public void postVisit(final Operator visitable) { } @Override public boolean preVisit(final Operator visitable) { if (visitable instanceof GenericDataSink && !GenericTestPlan.this.sinks.contains(visitable)) GenericTestPlan.this.sinks.add((GenericDataSink) visitable); if (visitable instanceof GenericDataSource<?> && !GenericTestPlan.this.sources.contains(visitable)) GenericTestPlan.this.sources.add((GenericDataSource<?>) visitable); return true; } }); for (final GenericDataSource<?> source : this.sources) if (source instanceof FileDataSource) this.getInput(source).load( (Class<? extends FileInputFormat>) source.getFormatWrapper().getUserCodeClass(), ((FileDataSource) source).getFilePath(), source.getParameters()); else this.getInput(source).load( (Class<? extends GenericInputFormat>) source.getFormatWrapper().getUserCodeClass(), source.getParameters()); }