/** {@inheritDoc} */
  @Override
  public Tuple<Collection<BasicOperator>, Collection<BasicOperator>> transformOperatorGraph(
      final Map<String, BasicOperator> mso, final BasicOperator rootOperator) {
    final Collection<BasicOperator> deleted = new LinkedList<BasicOperator>();
    final Collection<BasicOperator> added = new LinkedList<BasicOperator>();
    final ReplaceVar replaceVar = (ReplaceVar) mso.get("replaceVar");

    final LinkedList<BasicOperator> pres =
        (LinkedList<BasicOperator>) replaceVar.getPrecedingOperators();
    final LinkedList<OperatorIDTuple> succs =
        (LinkedList<OperatorIDTuple>) replaceVar.getSucceedingOperators();

    BasicOperator pre;
    OperatorIDTuple idTuple;
    // Connect all precessors to all successors
    for (int i = 0; i < pres.size(); i++) {
      for (int a = 0; a < succs.size(); a++) {
        idTuple = succs.get(a);
        pre = pres.get(i);
        pre.addSucceedingOperator(new OperatorIDTuple(idTuple.getOperator(), idTuple.getId()));
        pre.removeSucceedingOperator(replaceVar);
      }
    }

    BasicOperator succ;
    // And all successors to all precessors
    for (int i = 0; i < succs.size(); i++) {
      for (int a = 0; a < pres.size(); a++) {
        succ = succs.get(i).getOperator();
        succ.addPrecedingOperator(pres.get(a));
        succ.removePrecedingOperator(replaceVar);
      }
    }

    rootOperator.deleteParents();
    rootOperator.setParents();
    rootOperator.detectCycles();
    // should have been done manually: rootOperator.sendMessage(new
    // BoundVariablesMessage());
    deleted.add(replaceVar);
    if (deleted.size() > 0 || added.size() > 0)
      return new Tuple<Collection<BasicOperator>, Collection<BasicOperator>>(added, deleted);
    else return null;
  }
Esempio n. 2
0
  /**
   * This method clones not only the current operator, but all of its succeeding operators
   * recursively.
   *
   * @return the cloned operator
   */
  public BasicOperator deepClone() {
    final BasicOperator op =
        (BasicOperator)
            visit(
                new SimpleOperatorGraphVisitor() {
                  /** */
                  private static final long serialVersionUID = -2374279115052843835L;

                  final Map<BasicOperator, BasicOperator> clones =
                      new HashMap<BasicOperator, BasicOperator>();

                  @Override
                  public Object visit(final BasicOperator basicOperator) {
                    BasicOperator cloneCurrent;
                    if (this.clones.containsKey(basicOperator)) {
                      cloneCurrent = this.clones.get(basicOperator);
                    } else {
                      cloneCurrent = basicOperator.clone();
                      this.clones.put(basicOperator, cloneCurrent);
                    }

                    final LinkedList<OperatorIDTuple> newSucc = new LinkedList<OperatorIDTuple>();

                    for (final OperatorIDTuple opid : basicOperator.succeedingOperators) {
                      BasicOperator clone = null;
                      if (this.clones.containsKey(opid.getOperator())) {
                        clone = this.clones.get(opid.getOperator());
                      } else {
                        clone = opid.getOperator().clone();
                        this.clones.put(opid.getOperator(), clone);
                      }
                      newSucc.add(new OperatorIDTuple(clone, opid.getId()));
                    }

                    cloneCurrent.setSucceedingOperators(newSucc);
                    return cloneCurrent;
                  }
                });

    op.deleteParents();
    op.setParents();

    return op;
  }
  @Override
  public Tuple<Collection<BasicOperator>, Collection<BasicOperator>> transformOperatorGraph(
      final Map<String, BasicOperator> mso, final BasicOperator rootOperator) {
    final GenerateAddEnv genAdd = (GenerateAddEnv) mso.get("genAdd");
    final Optional optional = (Optional) mso.get("optional");

    final LinkedList<BasicOperator> pres =
        (LinkedList<BasicOperator>) genAdd.getPrecedingOperators();
    final LinkedList<OperatorIDTuple> succs =
        (LinkedList<OperatorIDTuple>) optional.getSucceedingOperators();

    BasicOperator pre;
    for (int i = 0; i < pres.size(); i++) {
      pre = pres.get(i);
      pre.addSucceedingOperator(new OperatorIDTuple(optional, 0));
      pre.removeSucceedingOperator(genAdd);
      optional.addPrecedingOperator(pre);
    }

    optional.removePrecedingOperator(genAdd);
    optional.setSucceedingOperator(new OperatorIDTuple(genAdd, 0));

    genAdd.setPrecedingOperator(optional);
    genAdd.setSucceedingOperators(succs);

    BasicOperator succ;
    for (int i = 0; i < succs.size(); i++) {
      succ = succs.get(i).getOperator();
      succ.addPrecedingOperator(genAdd);
      succ.removePrecedingOperator(optional);
    }

    rootOperator.deleteParents();
    rootOperator.setParents();
    rootOperator.detectCycles();
    rootOperator.sendMessage(new BoundVariablesMessage());
    return null;
  }