public static List<Operator<?>> cloneOperatorTree(List<Operator<?>> roots) {
    if (roots.isEmpty()) {
      return Collections.emptyList();
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
    CompilationOpContext ctx = roots.get(0).getCompilationOpContext();
    serializePlan(roots, baos);
    @SuppressWarnings("unchecked")
    List<Operator<?>> result =
        deserializePlan(new ByteArrayInputStream(baos.toByteArray()),
            roots.getClass());
    // Restore the context.
    LinkedList<Operator<?>> newOps = new LinkedList<>(result);
    while (!newOps.isEmpty()) {
      Operator<?> newOp = newOps.poll();
      newOp.setCompilationOpContext(ctx);
      List<Operator<?>> children = newOp.getChildOperators();
      if (children != null) {
        newOps.addAll(children);
      }
    }
    return result;
  }
Clones using the powers of XML. Do not use unless necessary.
@param roots The roots.
@return The clone.
ql/src/java/org/apache/hadoop/hive/ql/exec/SerializationUtilities.java