Search in sources :

Example 16 with BOperatorInvocation

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);
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) BOutputPort(com.ibm.streamsx.topology.builder.BOutputPort)

Example 17 with BOperatorInvocation

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;
}
Also used : ArrayList(java.util.ArrayList) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) StreamSchema(com.ibm.streams.operator.StreamSchema)

Example 18 with BOperatorInvocation

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&lt;Sensor> sensors = ...
     * StreamSchema schema = Type.Factory.getStreamSchema("tuple&lt;rstring id, float64 reading>");
     * SPLStream splSensors = SPLStreams.convertStream(sensors,
     *   new BiFunction&lt;Sensor, OutputTuple, OutputTuple>() {
     *             &#64;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);
}
Also used : BInputPort(com.ibm.streamsx.topology.builder.BInputPort) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) BOutputPort(com.ibm.streamsx.topology.builder.BOutputPort)

Example 19 with BOperatorInvocation

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);
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) BOutputPort(com.ibm.streamsx.topology.builder.BOutputPort)

Example 20 with BOperatorInvocation

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;
}
Also used : HashMap(java.util.HashMap) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation)

Aggregations

BOperatorInvocation (com.ibm.streamsx.topology.builder.BOperatorInvocation)26 BInputPort (com.ibm.streamsx.topology.builder.BInputPort)6 BOutputPort (com.ibm.streamsx.topology.builder.BOutputPort)4 ArrayList (java.util.ArrayList)4 JSONObject (com.ibm.json.java.JSONObject)3 StreamSchema (com.ibm.streams.operator.StreamSchema)3 HashMap (java.util.HashMap)3 JSONArray (com.ibm.json.java.JSONArray)2 TStream (com.ibm.streamsx.topology.TStream)2 TSinkImpl (com.ibm.streamsx.topology.internal.core.TSinkImpl)2 Constants (com.ibm.streamsx.topology.internal.logic.Constants)2 Type (java.lang.reflect.Type)2 BOperator (com.ibm.streamsx.topology.builder.BOperator)1 BOutput (com.ibm.streamsx.topology.builder.BOutput)1 Predicate (com.ibm.streamsx.topology.function.Predicate)1 KeyFunctionHasher (com.ibm.streamsx.topology.internal.logic.KeyFunctionHasher)1 Print (com.ibm.streamsx.topology.internal.logic.Print)1 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)1 Path (java.nio.file.Path)1 Map (java.util.Map)1