Search in sources :

Example 21 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class WindowDefinition method joinInternal.

public <J, U> TStream<J> joinInternal(TStream<U> xstream, Function<? super U, ? extends K> xstreamKey, BiFunction<U, List<T>, J> joiner, java.lang.reflect.Type tupleType) {
    String opName = LogicUtils.functionName(joiner);
    if (opName.isEmpty()) {
        opName = TypeDiscoverer.getTupleName(getTupleType()) + "Join";
    }
    Map<String, Object> params = getOperatorParams();
    if (isKeyed() && xstreamKey != null) {
        params.put(FunctionJoin.JOIN_KEY_GETTER_PARAM, ObjectUtils.serializeLogic(xstreamKey));
    }
    BOperatorInvocation joinOp = JavaFunctional.addFunctionalOperator(this, opName, FunctionJoin.class, joiner, params);
    SourceInfo.setSourceInfo(joinOp, WindowDefinition.class);
    @SuppressWarnings("unused") BInputPort input0 = addInput(joinOp, Policy.COUNT, Integer.MAX_VALUE, (TimeUnit) null);
    @SuppressWarnings("unused") BInputPort input1 = xstream.connectTo(joinOp, true, null);
    return JavaFunctional.addJavaOutput(this, joinOp, tupleType);
}
Also used : BInputPort(com.ibm.streamsx.topology.builder.BInputPort) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation)

Example 22 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class JavaFunctional method addFunctionalOperator.

/**
     * Add an operator that executes a Java function (as an instance of a class)
     * for its logic.
     */
public static BOperatorInvocation addFunctionalOperator(TopologyElement te, Class<? extends Operator> opClass, Serializable logic) {
    verifySerializable(logic);
    String logicString = ObjectUtils.serializeLogic(logic);
    BOperatorInvocation bop = te.builder().addOperator(opClass, Collections.singletonMap(FUNCTIONAL_LOGIC_PARAM, logicString));
    addDependency(te, bop, logic);
    return bop;
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation)

Example 23 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class StreamImpl method split.

@Override
public List<TStream<T>> split(int n, ToIntFunction<T> splitter) {
    if (n <= 0)
        throw new IllegalArgumentException("n");
    List<TStream<T>> l = new ArrayList<>(n);
    String opName = splitter.getClass().getSimpleName();
    if (opName.isEmpty()) {
        opName = getTupleName() + "Split";
    }
    BOperatorInvocation bop = JavaFunctional.addFunctionalOperator(this, opName, FunctionSplit.class, splitter);
    SourceInfo.setSourceInfo(bop, StreamImpl.class);
    connectTo(bop, true, null);
    Type outputType = refineType(ToIntFunction.class, 0, splitter);
    for (int i = 0; i < n; i++) {
        TStream<T> splitOutput = JavaFunctional.addJavaOutput(this, bop, outputType);
        l.add(splitOutput);
    }
    return l;
}
Also used : TStream(com.ibm.streamsx.topology.TStream) Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) Print(com.ibm.streamsx.topology.internal.logic.Print)

Example 24 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class StreamImpl method sink.

@Override
public TSink sink(Consumer<T> sinker) {
    String opName = sinker.getClass().getSimpleName();
    if (opName.isEmpty()) {
        opName = getTupleName() + "Sink";
    }
    BOperatorInvocation sink = JavaFunctional.addFunctionalOperator(this, opName, FunctionSink.class, sinker);
    SourceInfo.setSourceInfo(sink, StreamImpl.class);
    connectTo(sink, true, null);
    return new TSinkImpl(this, sink);
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation)

Example 25 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class StreamImpl method _parallel.

private TStream<T> _parallel(Supplier<Integer> width, Function<T, ?> keyer) {
    if (width == null)
        throw new IllegalArgumentException("width");
    Integer widthVal;
    if (width.get() != null)
        widthVal = width.get();
    else if (width instanceof SubmissionParameter<?>)
        widthVal = ((SubmissionParameter<Integer>) width).getDefaultValue();
    else
        throw new IllegalArgumentException("Illegal width Supplier: width.get() returns null.");
    if (widthVal != null && widthVal <= 0)
        throw new IllegalArgumentException("The parallel width must be greater than or equal to 1.");
    BOutput toBeParallelized = output();
    boolean isPartitioned = false;
    if (keyer != null) {
        final ToIntFunction<T> hasher = new KeyFunctionHasher<>(keyer);
        BOperatorInvocation hashAdder = JavaFunctional.addFunctionalOperator(this, "HashAdder", HashAdder.class, hasher);
        // hashAdder.json().put("routing", routing.toString());
        BInputPort ip = connectTo(hashAdder, true, null);
        StreamSchema hashSchema = ip.port().getStreamSchema().extend("int32", "__spl_hash");
        toBeParallelized = hashAdder.addOutput(hashSchema);
        isPartitioned = true;
    }
    BOutput parallelOutput = builder().parallel(toBeParallelized, width);
    if (isPartitioned) {
        parallelOutput.json().put("partitioned", true);
        JSONArray partitionKeys = new JSONArray();
        partitionKeys.add("__spl_hash");
        parallelOutput.json().put("partitionedKeys", partitionKeys);
        // Add hash remover
        StreamImpl<T> parallelStream = new StreamImpl<T>(this, parallelOutput, getTupleType());
        BOperatorInvocation hashRemover = builder().addOperator(HashRemover.class, null);
        BInputPort pip = parallelStream.connectTo(hashRemover, true, null);
        parallelOutput = hashRemover.addOutput(pip.port().getStreamSchema().remove("__spl_hash"));
    }
    return addMatchingStream(parallelOutput);
}
Also used : JSONArray(com.ibm.json.java.JSONArray) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) StreamSchema(com.ibm.streams.operator.StreamSchema) BOutput(com.ibm.streamsx.topology.builder.BOutput) BInputPort(com.ibm.streamsx.topology.builder.BInputPort) KeyFunctionHasher(com.ibm.streamsx.topology.internal.logic.KeyFunctionHasher)

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