use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.
the class SPL method invokeSource.
/**
* Invocation an SPL source operator to produce a Stream.
*
* @param te
* Reference to Topology the operator will be in.
* @param kind
* SPL kind of the operator to be invoked.
* @param params
* Parameters for the SPL operator.
* @param schema
* Schema of the output port.
* @return SPLStream the represents the output of the operator.
*/
public static SPLStream invokeSource(TopologyElement te, String kind, Map<String, Object> params, StreamSchema schema) {
BOperatorInvocation splSource = te.builder().addSPLOperator(opNameFromKind(kind), kind, params);
SourceInfo.setSourceInfo(splSource, SPL.class);
BOutputPort stream = splSource.addOutput(schema);
return new SPLStreamImpl(te, stream);
}
use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.
the class SPL method invokeOperator.
/**
* Invoke an SPL operator with an arbitrary number
* of input and output ports.
* <BR>
* Each input stream or window in {@code inputs} results in
* a input port for the operator with the input port index
* matching the position of the input in {@code inputs}.
* If {@code inputs} is {@code null} or empty then the operator will not
* have any input ports.
* <BR>
* Each SPL schema in {@code outputSchemas} an output port
* for the operator with the output port index
* matching the position of the schema in {@code outputSchemas}.
* If {@code outputSchemas} is {@code null} or empty then the operator will not
* have any output ports.
*
* @param te Reference to Topology the operator will be in.
* @param name Name for the operator invocation.
* @param kind
* SPL kind of the operator to be invoked.
* @param inputs Input streams to be connected to the operator. May be {@code null} if no input streams are required.
* @param outputSchemas Schemas of the output streams. May be {@code null} if no output streams are required.
* @param params
* Parameters for the SPL Java Primitive operator, ignored if {@code null}.
* @return List of {@code SPLStream} instances that represent the outputs of the operator.
*/
public static List<SPLStream> invokeOperator(TopologyElement te, String name, String kind, List<? extends SPLInput> inputs, List<StreamSchema> outputSchemas, Map<String, ? extends Object> params) {
BOperatorInvocation op = te.builder().addSPLOperator(name, kind, params);
SourceInfo.setSourceInfo(op, SPL.class);
if (inputs != null && !inputs.isEmpty()) {
for (SPLInput input : inputs) SPL.connectInputToOperator(input, op);
}
if (outputSchemas == null || outputSchemas.isEmpty())
return Collections.emptyList();
List<SPLStream> streams = new ArrayList<>(outputSchemas.size());
for (StreamSchema outputSchema : outputSchemas) streams.add(new SPLStreamImpl(te, op.addOutput(outputSchema)));
return streams;
}
use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.
the class SPLStreams method convertStream.
/**
* Convert a {@code Stream} to an {@code SPLStream}. For each tuple
* {@code t} on {@code stream}, the returned stream will contain a tuple
* that is the result of {@code converter.apply(t, outTuple)} when the
* return is not {@code null}. {@code outTuple} is a newly created, empty,
* {@code OutputTuple}, the {@code converter.apply()} method populates
* {@code outTuple} from {@code t}.
*
* <P>
* Example of converting a stream containing a {@code Sensor} object to an
* SPL schema of {@code tuple<rstring id, float64 reading>}.
*
* <pre>
* <code>
* Stream<Sensor> sensors = ...
* StreamSchema schema = Type.Factory.getStreamSchema("tuple<rstring id, float64 reading>");
* SPLStream splSensors = SPLStreams.convertStream(sensors,
* new BiFunction<Sensor, OutputTuple, OutputTuple>() {
* @Override
* public OutputTuple apply(Sensor sensor, OutputTuple outTuple) {
* outTuple.setString("id", sensor.getId());
* outTuple.setDouble("reading", sensor.getReading());
* return outTuple;
* }}, schema);
* </code>
* </pre>
*
* </P>
*
* @param stream
* Stream to be converted.
* @param converter
* Converter used to populate the SPL tuple.
* @param schema
* Schema of returned SPLStream.
* @return SPLStream containing the converted tuples.
*
* @see SPLStream#convert(com.ibm.streamsx.topology.function.Function)
*/
public static <T> SPLStream convertStream(TStream<T> stream, BiFunction<T, OutputTuple, OutputTuple> converter, StreamSchema schema) {
String opName = converter.getClass().getSimpleName();
if (opName.isEmpty()) {
opName = "SPLConvert" + TypeDiscoverer.getTupleName(stream.getTupleType());
}
BOperatorInvocation convOp = JavaFunctional.addFunctionalOperator(stream, opName, FunctionConvertToSPL.class, converter);
@SuppressWarnings("unused") BInputPort inputPort = stream.connectTo(convOp, true, null);
BOutputPort convertedTuples = convOp.addOutput(schema);
return new SPLStreamImpl(stream, convertedTuples);
}
use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.
the class SPL method invokeOperator.
/**
* Create an SPLStream from the invocation of an SPL operator
* that consumes a stream and produces a stream.
*
* @param name Name for the operator invocation.
* @param kind
* SPL kind of the operator to be invoked.
* @param input
* Stream that will be connected to the only input port of the
* operator
* @param outputSchema
* SPL schema of the operator's only output port.
* @param params
* Parameters for the SPL operator, ignored if it is null.
* @return SPLStream the represents the output of the operator.
*/
public static SPLStream invokeOperator(String name, String kind, SPLInput input, StreamSchema outputSchema, Map<String, ? extends Object> params) {
BOperatorInvocation op = input.builder().addSPLOperator(name, kind, params);
SourceInfo.setSourceInfo(op, SPL.class);
SPL.connectInputToOperator(input, op);
BOutputPort stream = op.addOutput(outputSchema);
return new SPLStreamImpl(input, stream);
}
use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.
the class JavaFunctional method addFunctionalOperator.
public static BOperatorInvocation addFunctionalOperator(TopologyElement te, String name, Class<? extends Operator> opClass, Serializable logic, Map<String, Object> params) {
if (params == null)
params = new HashMap<>();
verifySerializable(logic);
String logicString = ObjectUtils.serializeLogic(logic);
params.put(FUNCTIONAL_LOGIC_PARAM, logicString);
BOperatorInvocation bop = te.builder().addOperator(name, opClass, params);
addDependency(te, bop, logic);
return bop;
}
Aggregations