Search in sources :

Example 6 with OutputPort

use of com.datatorrent.api.Operator.OutputPort in project beam by apache.

the class ParDoTranslator method translate.

@Override
public void translate(ParDo.MultiOutput<InputT, OutputT> transform, TranslationContext context) {
    DoFn<InputT, OutputT> doFn = transform.getFn();
    DoFnSignature signature = DoFnSignatures.getSignature(doFn.getClass());
    if (signature.processElement().isSplittable()) {
        throw new UnsupportedOperationException(String.format("%s does not support splittable DoFn: %s", ApexRunner.class.getSimpleName(), doFn));
    }
    if (signature.stateDeclarations().size() > 0) {
        throw new UnsupportedOperationException(String.format("Found %s annotations on %s, but %s cannot yet be used with state in the %s.", DoFn.StateId.class.getSimpleName(), doFn.getClass().getName(), DoFn.class.getSimpleName(), ApexRunner.class.getSimpleName()));
    }
    if (signature.timerDeclarations().size() > 0) {
        throw new UnsupportedOperationException(String.format("Found %s annotations on %s, but %s cannot yet be used with timers in the %s.", DoFn.TimerId.class.getSimpleName(), doFn.getClass().getName(), DoFn.class.getSimpleName(), ApexRunner.class.getSimpleName()));
    }
    Map<TupleTag<?>, PValue> outputs = context.getOutputs();
    PCollection<InputT> input = context.getInput();
    List<PCollectionView<?>> sideInputs = transform.getSideInputs();
    Coder<InputT> inputCoder = input.getCoder();
    WindowedValueCoder<InputT> wvInputCoder = FullWindowedValueCoder.of(inputCoder, input.getWindowingStrategy().getWindowFn().windowCoder());
    ApexParDoOperator<InputT, OutputT> operator = new ApexParDoOperator<>(context.getPipelineOptions(), doFn, transform.getMainOutputTag(), transform.getAdditionalOutputTags().getAll(), input.getWindowingStrategy(), sideInputs, wvInputCoder, context.getStateBackend());
    Map<PCollection<?>, OutputPort<?>> ports = Maps.newHashMapWithExpectedSize(outputs.size());
    for (Entry<TupleTag<?>, PValue> output : outputs.entrySet()) {
        checkArgument(output.getValue() instanceof PCollection, "%s %s outputs non-PCollection %s of type %s", ParDo.MultiOutput.class.getSimpleName(), context.getFullName(), output.getValue(), output.getValue().getClass().getSimpleName());
        PCollection<?> pc = (PCollection<?>) output.getValue();
        if (output.getKey().equals(transform.getMainOutputTag())) {
            ports.put(pc, operator.output);
        } else {
            int portIndex = 0;
            for (TupleTag<?> tag : transform.getAdditionalOutputTags().getAll()) {
                if (tag.equals(output.getKey())) {
                    ports.put(pc, operator.additionalOutputPorts[portIndex]);
                    break;
                }
                portIndex++;
            }
        }
    }
    context.addOperator(operator, ports);
    context.addStream(context.getInput(), operator.input);
    if (!sideInputs.isEmpty()) {
        addSideInputs(operator.sideInput1, sideInputs, context);
    }
}
Also used : OutputPort(com.datatorrent.api.Operator.OutputPort) TupleTag(org.apache.beam.sdk.values.TupleTag) ApexParDoOperator(org.apache.beam.runners.apex.translation.operators.ApexParDoOperator) PValue(org.apache.beam.sdk.values.PValue) PCollection(org.apache.beam.sdk.values.PCollection) PCollectionView(org.apache.beam.sdk.values.PCollectionView) DoFn(org.apache.beam.sdk.transforms.DoFn) DoFnSignature(org.apache.beam.sdk.transforms.reflect.DoFnSignature)

Example 7 with OutputPort

use of com.datatorrent.api.Operator.OutputPort in project apex-core by apache.

the class PlanModifier method addStream.

/**
   * Add stream to logical plan. If a stream with same name and source already
   * exists, the new downstream operator will be attached to it.
   *
   * @param streamName
   * @param sourceOperName
   * @param sourcePortName
   * @param targetOperName
   * @param targetPortName
   */
public void addStream(String streamName, String sourceOperName, String sourcePortName, String targetOperName, String targetPortName) {
    OperatorMeta om = logicalPlan.getOperatorMeta(sourceOperName);
    if (om == null) {
        throw new ValidationException("Invalid operator name " + sourceOperName);
    }
    Operators.PortMappingDescriptor portMap = new Operators.PortMappingDescriptor();
    Operators.describe(om.getOperator(), portMap);
    PortContextPair<OutputPort<?>> sourcePort = portMap.outputPorts.get(sourcePortName);
    if (sourcePort == null) {
        throw new AssertionError(String.format("Invalid port %s (%s)", sourcePortName, om));
    }
    addStream(streamName, sourcePort.component, getInputPort(targetOperName, targetPortName));
}
Also used : OutputPort(com.datatorrent.api.Operator.OutputPort) Operators(com.datatorrent.stram.plan.logical.Operators) ValidationException(javax.validation.ValidationException) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)

Aggregations

OutputPort (com.datatorrent.api.Operator.OutputPort)7 InputPort (com.datatorrent.api.Operator.InputPort)4 Operator (com.datatorrent.api.Operator)2 Sink (com.datatorrent.api.Sink)2 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)2 Operators (com.datatorrent.stram.plan.logical.Operators)2 PortContextPair (com.datatorrent.stram.plan.logical.Operators.PortContextPair)2 GenericOperator (com.datatorrent.api.DAG.GenericOperator)1 StatsListener (com.datatorrent.api.StatsListener)1 OperatorRequest (com.datatorrent.api.StatsListener.OperatorRequest)1 InputPortFieldAnnotation (com.datatorrent.api.annotation.InputPortFieldAnnotation)1 OutputPortFieldAnnotation (com.datatorrent.api.annotation.OutputPortFieldAnnotation)1 AppData (com.datatorrent.common.experimental.AppData)1 NodeActivationEvent (com.datatorrent.stram.api.ContainerEvent.NodeActivationEvent)1 OperatorDeployInfo (com.datatorrent.stram.api.OperatorDeployInfo)1 MuxSink (com.datatorrent.stram.debug.MuxSink)1 InputPortMeta (com.datatorrent.stram.plan.logical.LogicalPlan.InputPortMeta)1 OutputPortMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OutputPortMeta)1 PortMappingDescriptor (com.datatorrent.stram.plan.logical.Operators.PortMappingDescriptor)1 SharedPubSubWebSocketClient (com.datatorrent.stram.util.SharedPubSubWebSocketClient)1