Java Code Examples for com.datatorrent.api.Operator#OutputPort

The following examples show how to use com.datatorrent.api.Operator#OutputPort . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogicalPlan.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
@Override
public StreamMeta setSource(Operator.OutputPort<?> port)
{
  if (port instanceof ProxyOutputPort) {
    proxySource = port;
    return this;
  }
  OutputPortMeta portMeta = assertGetPortMeta(port);
  OperatorMeta om = portMeta.getOperatorMeta();
  if (om.outputStreams.containsKey(portMeta)) {
    String msg = String.format("Operator %s already connected to %s", om.name, om.outputStreams.get(portMeta).id);
    throw new IllegalArgumentException(msg);
  }
  this.source = portMeta;
  om.outputStreams.put(portMeta, this);
  return this;
}
 
Example 2
Source File: PlanModifier.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
public <T> StreamMeta addStream(String id, Operator.OutputPort<? extends T> source, Operator.InputPort<?>... sinks)
{
  StreamMeta sm = logicalPlan.getStream(id);
  if (sm != null) {
    if (sm.getSource().getOperatorMeta().getMeta(source) != sm.getSource()) {
      throw new AssertionError(String.format("Stream %s already connected to %s", sm, sm.getSource()));
    }
  } else {
    // fails on duplicate stream name
    @SuppressWarnings("unchecked")
    StreamMeta newStream = logicalPlan.addStream(id, source);
    sm = newStream;
  }
  return addSinks(id, sinks);
}
 
Example 3
Source File: DagMeta.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
public NodeMeta addNode(Operator operator, NodeMeta parent, Operator.OutputPort parentOutput, Operator.InputPort inputPort, Option... options)
{

  NodeMeta newNode = new NodeMeta(operator, options);
  if (parent == null) {
    heads.add(newNode);
  } else {
    parent.nodeStreams.get(parentOutput).getLeft().add(inputPort);
    parent.children.add(newNode);
    newNode.parent.add(parent);
  }
  return newNode;
}
 
Example 4
Source File: ApexStreamImpl.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
private void checkArguments(Operator op, Operator.InputPort inputPort, Operator.OutputPort outputPort)
{
  if (op == null) {
    throw new IllegalArgumentException("Operator can not be null");
  }

  boolean foundInput = inputPort == null;
  boolean foundOutput = outputPort == null;
  for (Field f : op.getClass().getFields()) {
    int modifiers = f.getModifiers();
    if (!Modifier.isPublic(modifiers) || !Modifier.isTransient(modifiers)) {
      continue;
    }
    Object obj = null;
    try {
      obj = f.get(op);
    } catch (IllegalAccessException e) {
      // NonAccessible field is not a valid port object
    }
    if (obj == outputPort) {
      foundOutput = true;
    }
    if (obj == inputPort) {
      foundInput = true;
    }
  }
  if (!foundInput || !foundOutput) {
    throw new IllegalArgumentException("Input port " + inputPort + " and/or Output port " + outputPort + " is/are not owned by Operator " + op);
  }

}
 
Example 5
Source File: Operators.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void addOutputPort(Operator.OutputPort<?> port, Field field, OutputPortFieldAnnotation portAnnotation, AppData.ResultPort adrAnnotation)
{
  if (!outputPorts.containsKey(field.getName())) {
    outputPorts.put(field.getName(), new PortContextPair<OutputPort<?>>(port));
  }
}
 
Example 6
Source File: LogicalPlan.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> StreamMeta addStream(String id, Operator.OutputPort<? extends T> source, Operator.InputPort<? super T> sink1, Operator.InputPort<? super T> sink2)
{
  @SuppressWarnings("rawtypes")
  InputPort[] ports = new Operator.InputPort[] {sink1, sink2};
  return addStream(id, source, ports);
}
 
Example 7
Source File: LogicalPlan.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> StreamMeta addStream(String id, Operator.OutputPort<? extends T> source, Operator.InputPort<? super T> sink1)
{
  @SuppressWarnings("rawtypes")
  InputPort[] ports = new Operator.InputPort[]{sink1};
  return addStream(id, source, ports);
}
 
Example 8
Source File: LogicalPlan.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> StreamMeta addStream(@Nonnull String id, Operator.OutputPort<? extends T> source, Operator.InputPort<? super T>... sinks)
{
  StreamMeta s = addStream(id);
  s.setSource(source);
  for (Operator.InputPort<?> sink : sinks) {
    s.addSink(sink);
  }
  return s;
}
 
Example 9
Source File: RelInfo.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public Operator.OutputPort getOutPort()
{
  return outPort;
}
 
Example 10
Source File: StreamEndpoint.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public StreamEndpoint(Operator.OutputPort outputPort, Class pojoClass)
{
  this.outputPort = outputPort;
  this.pojoClass = pojoClass;
}
 
Example 11
Source File: LogicalPlan.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
@Override
public <T> void setUnifierAttribute(Operator.OutputPort<?> port, Attribute<T> key, T value)
{
  assertGetPortMeta(port).getUnifierMeta().attributes.put(key, value);
}
 
Example 12
Source File: StreamEndpoint.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public StreamEndpoint(Operator.OutputPort port, Map<String, Class> fieldMapping)
{
  this.outputPort = port;
  this.fieldMapping = fieldMapping;
}
 
Example 13
Source File: ApexStreamImpl.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public void setLastOutput(Operator.OutputPort<T> lastOutput)
{
  this.lastOutput = lastOutput;
}
 
Example 14
Source File: ApexStreamImpl.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public void setLastStream(Pair<Operator.OutputPort, Operator.InputPort> lastStream)
{
  this.lastStream = lastStream;
}
 
Example 15
Source File: RelInfo.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public void setOutPort(Operator.OutputPort outPort)
{
  this.outPort = outPort;
}
 
Example 16
Source File: RelNodeVisitor.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
/**
 * This is the main method in this relational node visitor which traverses the relational algebra in reverse direction
 * and populate the given underlying DAG object.
 *
 * @param relNode RelNode which needs to be traversed.
 *
 * @return RelInfo representing information of current stage
 * @throws Exception
 */
public final RelInfo traverse(RelNode relNode) throws Exception
{
  List<RelInfo> inputStreams = new ArrayList<>();
  for (RelNode input : relNode.getInputs()) {
    inputStreams.add(traverse(input));
  }

  ApexRelNode.RelContext relContext = new ApexRelNode.RelContext(dag, typeFactory, tupleSchemaRegistry);

  RelInfo currentNodeRelInfo;
  ApexRelNode apexRelNode = ApexRelNode.relNodeMapping.get(relNode.getClass());
  if (apexRelNode == null) {
    throw new UnsupportedOperationException("RelNode " + relNode.getRelTypeName() + " is not supported.");
  }
  currentNodeRelInfo = apexRelNode.visit(relContext, relNode, inputStreams);

  if (currentNodeRelInfo != null && inputStreams.size() != 0) {
    for (int i = 0; i < inputStreams.size(); i++) {
      RelInfo inputStream = inputStreams.get(i);
      Operator.OutputPort outputPort = inputStream.getOutPort();
      Operator.InputPort inputPort = currentNodeRelInfo.getInputPorts().get(i);

      String streamName = OperatorUtils.getUniqueStreamName(inputStream.getRelName(),
          currentNodeRelInfo.getRelName());
      Class schema;
      if (inputStream.getOutRelDataType() != null) {
        schema = TupleSchemaRegistry.getSchemaForRelDataType(tupleSchemaRegistry, streamName,
            inputStream.getOutRelDataType());
      } else if (inputStream.getClazz() != null) {
        schema = inputStream.getClazz();
      } else {
        throw new RuntimeException("Unexpected condition reached.");
      }
      dag.setOutputPortAttribute(outputPort, Context.PortContext.TUPLE_CLASS, schema);
      dag.setInputPortAttribute(inputPort, Context.PortContext.TUPLE_CLASS, schema);
      dag.addStream(streamName, outputPort, inputPort);
    }
  }

  if (currentNodeRelInfo.getOutPort() == null) {
    // End of the pipeline.
    String schemaJar = tupleSchemaRegistry.generateCommonJar();

    String jars = dag.getAttributes().get(Context.DAGContext.LIBRARY_JARS);
    dag.setAttribute(Context.DAGContext.LIBRARY_JARS,
        ((jars != null) && (jars.length() != 0)) ? jars + "," + schemaJar : schemaJar);
  }

  return currentNodeRelInfo;
}
 
Example 17
Source File: DagMeta.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public Map<Operator.OutputPort, Pair<List<Operator.InputPort>, DAG.Locality>> getNodeStreams()
{
  return nodeStreams;
}
 
Example 18
Source File: LogicalPlan.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
@Override
public OutputPortMeta getMeta(Operator.OutputPort<?> port)
{
  return getPortMapping().outPortMap.get(port);
}
 
Example 19
Source File: ApexStream.java    From attic-apex-malhar with Apache License 2.0 2 votes vote down vote up
/**
 * Extend the dag by adding one operator<br>
 * @param op Operator added to the stream
 * @param inputPort InputPort of the operator that is connected to last exposed OutputPort in the stream
 * @param outputPort OutputPort of the operator will be connected to next operator
 * @param <O> type of the output
 * @return new stream of type O
 */
<O, STREAM extends ApexStream<O>> STREAM addOperator(Operator op, Operator.InputPort<T> inputPort,  Operator.OutputPort<O> outputPort, Option... opts);
 
Example 20
Source File: Operators.java    From attic-apex-core with Apache License 2.0 votes vote down vote up
void addOutputPort(Operator.OutputPort<?> port, Field field, OutputPortFieldAnnotation portAnnotation, AppData.ResultPort adrAnnotation);