use of com.ibm.streamsx.topology.builder.BInputPort 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.BInputPort in project streamsx.topology by IBMStreams.
the class StreamImpl method _transform.
private <U> TStream<U> _transform(Function<T, U> transformer, Type tupleType) {
String opName = transformer.getClass().getSimpleName();
if (opName.isEmpty()) {
opName = TypeDiscoverer.getTupleName(tupleType) + "Transform" + getTupleName();
}
BOperatorInvocation bop = JavaFunctional.addFunctionalOperator(this, opName, FunctionTransform.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.BInputPort 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<Sensor> sensors = ...
* StreamSchema schema = Type.Factory.getStreamSchema("tuple<rstring id, float64 reading>");
* SPLStream splSensors = SPLStreams.convertStream(sensors,
* new BiFunction<Sensor, OutputTuple, OutputTuple>() {
* @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);
}
use of com.ibm.streamsx.topology.builder.BInputPort 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.BInputPort 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