Пример #1
0
  private <IN, OUT> List<OUT> executeUnaryOperator(
      SingleInputOperator<?, ?, ?> operator, int superStep) throws Exception {
    Operator<?> inputOp = operator.getInput();
    if (inputOp == null) {
      throw new InvalidProgramException(
          "The unary operation " + operator.getName() + " has no input.");
    }

    @SuppressWarnings("unchecked")
    List<IN> inputData = (List<IN>) execute(inputOp, superStep);

    @SuppressWarnings("unchecked")
    SingleInputOperator<IN, OUT, ?> typedOp = (SingleInputOperator<IN, OUT, ?>) operator;

    // build the runtime context and compute broadcast variables, if necessary
    TaskInfo taskInfo = new TaskInfo(typedOp.getName(), 1, 0, 1, 0);
    RuntimeUDFContext ctx;

    MetricGroup metrics = new UnregisteredMetricsGroup();
    if (RichFunction.class.isAssignableFrom(typedOp.getUserCodeWrapper().getUserCodeClass())) {
      ctx =
          superStep == 0
              ? new RuntimeUDFContext(
                  taskInfo, classLoader, executionConfig, cachedFiles, accumulators, metrics)
              : new IterationRuntimeUDFContext(
                  taskInfo, classLoader, executionConfig, cachedFiles, accumulators, metrics);

      for (Map.Entry<String, Operator<?>> bcInputs : operator.getBroadcastInputs().entrySet()) {
        List<?> bcData = execute(bcInputs.getValue());
        ctx.setBroadcastVariable(bcInputs.getKey(), bcData);
      }
    } else {
      ctx = null;
    }

    return typedOp.executeOnCollections(inputData, ctx, executionConfig);
  }