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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations