@Override
  public final void doWork() throws OperatorException {
    ExampleSet inputExampleSet = exampleSetInput.getData(ExampleSet.class);
    ExampleSet applySet = null;
    // check for needed copy of original exampleset
    if (originalOutput.isConnected() && writesIntoExistingData()) {
      int type = DataRowFactory.TYPE_DOUBLE_ARRAY;
      if (inputExampleSet.getExampleTable() instanceof MemoryExampleTable) {
        DataRowReader dataRowReader = inputExampleSet.getExampleTable().getDataRowReader();
        if (dataRowReader.hasNext()) {
          type = dataRowReader.next().getType();
        }
      }
      // check if type is supported to be copied
      if (type >= 0) {
        applySet = MaterializeDataInMemory.materializeExampleSet(inputExampleSet, type);
      }
    }

    if (applySet == null) applySet = (ExampleSet) inputExampleSet.clone();

    // we apply on the materialized data, because writing can't take place in views anyway.
    ExampleSet result = apply(applySet);
    originalOutput.deliver(inputExampleSet);
    exampleSetOutput.deliver(result);
  }
  @Override
  public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
    int size = exampleSet.size();

    // cannot bootstrap without any examples
    if (size < 1) {
      throw new UserError(this, 117);
    }

    RandomGenerator random = RandomGenerator.getRandomGenerator(this);
    switch (getParameterAsInt(PARAMETER_SAMPLE)) {
      case SAMPLE_ABSOLUTE:
        size = getParameterAsInt(PARAMETER_SAMPLE_SIZE);
        break;
      case SAMPLE_RELATIVE:
        size = (int) Math.round(exampleSet.size() * getParameterAsDouble(PARAMETER_SAMPLE_RATIO));
        break;
    }

    int[] mapping = null;
    if (getParameterAsBoolean(PARAMETER_USE_WEIGHTS)
        && exampleSet.getAttributes().getWeight() != null) {
      mapping = MappedExampleSet.createWeightedBootstrappingMapping(exampleSet, size, random);
    } else {
      mapping = MappedExampleSet.createBootstrappingMapping(exampleSet, size, random);
    }

    // create and materialize example set
    ExampleSet mappedExampleSet = new MappedExampleSet(exampleSet, mapping, true);
    if (getCompatibilityLevel().isAbove(VERSION_6_4_0)) {
      int type = DataRowFactory.TYPE_DOUBLE_ARRAY;
      if (exampleSet.size() > 0) {
        type = exampleSet.getExampleTable().getDataRow(0).getType();
      }
      mappedExampleSet = MaterializeDataInMemory.materializeExampleSet(mappedExampleSet, type);
    }
    return mappedExampleSet;
  }