Search in sources :

Example 1 with BOperatorInvocation

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

the class StreamImpl method filter.

@Override
public TStream<T> filter(Predicate<T> filter) {
    String opName = filter.getClass().getSimpleName();
    if (opName.isEmpty()) {
        opName = getTupleName() + "Filter";
    }
    BOperatorInvocation bop = JavaFunctional.addFunctionalOperator(this, opName, FunctionFilter.class, filter);
    SourceInfo.setSourceInfo(bop, StreamImpl.class);
    connectTo(bop, true, null);
    return addMatchingOutput(bop, refineType(Predicate.class, 0, filter));
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) Predicate(com.ibm.streamsx.topology.function.Predicate)

Example 2 with BOperatorInvocation

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

the class StreamImpl method publish.

@Override
public void publish(String topic, boolean allowFilter) {
    checkTopicName(topic);
    Type tupleType = getTupleType();
    if (JSONObject.class.equals(tupleType)) {
        filtersNotAllowed(allowFilter);
        @SuppressWarnings("unchecked") TStream<JSONObject> json = (TStream<JSONObject>) this;
        JSONStreams.toSPL(json).publish(topic, allowFilter);
        return;
    }
    BOperatorInvocation op;
    if (Schemas.usesDirectSchema(tupleType) || ((TStream<T>) this) instanceof SPLStream) {
        // would not allow a filter against.
        if (String.class != tupleType && !(((TStream<T>) this) instanceof SPLStream))
            filtersNotAllowed(allowFilter);
        // Publish as a stream consumable by SPL & Java/Scala
        Map<String, Object> publishParms = new HashMap<>();
        publishParms.put("topic", topic);
        publishParms.put("allowFilter", allowFilter);
        op = builder().addSPLOperator("Publish", "com.ibm.streamsx.topology.topic::Publish", publishParms);
    } else if (getTupleClass() != null) {
        filtersNotAllowed(allowFilter);
        // Publish as a stream consumable only by Java/Scala
        Map<String, Object> params = new HashMap<>();
        params.put("topic", topic);
        params.put("class", getTupleClass().getName());
        op = builder().addSPLOperator("Publish", "com.ibm.streamsx.topology.topic::PublishJava", params);
    } else {
        throw new IllegalStateException("A TStream with a tuple type that contains a generic or unknown type cannot be published");
    }
    SourceInfo.setSourceInfo(op, SPL.class);
    this.connectTo(op, false, null);
}
Also used : HashMap(java.util.HashMap) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) SPLStream(com.ibm.streamsx.topology.spl.SPLStream) TStream(com.ibm.streamsx.topology.TStream) Type(java.lang.reflect.Type) JSONObject(com.ibm.json.java.JSONObject) JSONObject(com.ibm.json.java.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with BOperatorInvocation

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

the class StreamImpl method _multiTransform.

private <U> TStream<U> _multiTransform(Function<T, Iterable<U>> transformer, Type tupleType) {
    String opName = transformer.getClass().getSimpleName();
    if (opName.isEmpty()) {
        opName = TypeDiscoverer.getTupleName(tupleType) + "MultiTransform" + getTupleName();
    }
    BOperatorInvocation bop = JavaFunctional.addFunctionalOperator(this, FunctionMultiTransform.class, transformer);
    SourceInfo.setSourceInfo(bop, StreamImpl.class);
    BInputPort inputPort = connectTo(bop, true, null);
    // By default add a queue
    inputPort.addQueue(true);
    return JavaFunctional.addJavaOutput(this, bop, tupleType);
}
Also used : BInputPort(com.ibm.streamsx.topology.builder.BInputPort) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation)

Example 4 with BOperatorInvocation

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

the class StreamImpl method fixDirectSchema.

private TStream<T> fixDirectSchema(Class<T> tupleClass) {
    BOperatorInvocation bop = JavaFunctional.addFunctionalOperator(this, "SchemaFix", FunctionTransform.class, identity());
    SourceInfo.setSourceInfo(bop, StreamImpl.class);
    connectTo(bop, true, null);
    return JavaFunctional.addJavaOutput(this, bop, tupleClass);
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation)

Example 5 with BOperatorInvocation

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

the class WindowDefinition method aggregate.

private <A> TStream<A> aggregate(Function<List<T>, A> aggregator, java.lang.reflect.Type aggregateType, Policy triggerPolicy, Object triggerConfig, TimeUnit triggerTimeUnit) {
    if (getTupleClass() == null && !isKeyed()) {
        java.lang.reflect.Type tupleType = TypeDiscoverer.determineStreamTypeNested(Function.class, 0, List.class, aggregator);
        setPartitioned(tupleType);
    }
    String opName = LogicUtils.functionName(aggregator);
    if (opName.isEmpty()) {
        opName = TypeDiscoverer.getTupleName(getTupleType()) + "Aggregate";
    }
    BOperatorInvocation aggOp = JavaFunctional.addFunctionalOperator(this, opName, FunctionAggregate.class, aggregator, getOperatorParams());
    SourceInfo.setSourceInfo(aggOp, WindowDefinition.class);
    addInput(aggOp, triggerPolicy, triggerConfig, triggerTimeUnit);
    return JavaFunctional.addJavaOutput(this, aggOp, aggregateType);
}
Also used : 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