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