use of com.ibm.streams.operator.Tuple in project streamsx.topology by IBMStreams.
the class PythonFunctionalOperatorsTest method testPositionalSampleSimpleFilterUsingSPLType.
@Test
public void testPositionalSampleSimpleFilterUsingSPLType() throws Exception {
Topology topology = new Topology("testPositionalSampleSimpleFilterUsingSPLType");
SPLStream tuples = sampleFilterStream(topology);
addTestToolkit(tuples);
SPLStream viaPython = SPL.invokeOperator("testspl::SF", tuples, tuples.getSchema(), null);
Tester tester = topology.getTester();
Condition<Long> expectedCount = tester.tupleCount(viaPython, 2);
// first attribute is the sum of the first and second input attributes
// others are copied across from in to out.
Tuple r1 = TEST_SCHEMA_SF.getTuple(new Object[] { 32, (short) 25, 34535L });
Tuple r2 = TEST_SCHEMA_SF.getTuple(new Object[] { 5, (short) 3, 654932L });
Condition<List<Tuple>> viaPythonResult = tester.tupleContents(viaPython, r1, r2);
complete(tester, expectedCount, 10, TimeUnit.SECONDS);
assertTrue(expectedCount.valid());
assertTrue(viaPythonResult.toString(), viaPythonResult.valid());
}
use of com.ibm.streams.operator.Tuple in project streamsx.topology by IBMStreams.
the class PythonFunctionalOperatorsTest method testTupleStream.
public static SPLStream testTupleStream(Topology topology, boolean withSets) {
TStream<Long> beacon = BeaconStreams.longBeacon(topology, TUPLE_COUNT);
SPLStream tuples = SPLStreams.convertStream(beacon, new BiFunction<Long, OutputTuple, OutputTuple>() {
private static final long serialVersionUID = 1L;
private transient TupleType type;
private transient Random rand;
@Override
public OutputTuple apply(Long v1, OutputTuple v2) {
if (type == null) {
type = Type.Factory.getTupleType(getPythonTypesSchema(withSets).getLanguageType());
rand = new Random();
}
Tuple randTuple = (Tuple) type.randomValue(rand);
v2.assign(randTuple);
return v2;
}
}, getPythonTypesSchema(withSets));
return tuples;
}
use of com.ibm.streams.operator.Tuple in project streamsx.topology by IBMStreams.
the class SPLStreamsTest method testMaintainSPLStream.
@Test
public void testMaintainSPLStream() {
assumeTrue(isMainRun());
Topology t = new Topology();
SPLStream splStreamA = testTupleStream(t);
assertSPLStream(splStreamA, TEST_SCHEMA);
SPLStream splStreamB = splStreamA.filter(new AllowAll<Tuple>());
assertSPLStream(splStreamB, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamA = splStreamB.sample(1.0);
assertSPLStream(splStreamA, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamB = splStreamA.throttle(1, TimeUnit.MICROSECONDS);
assertSPLStream(splStreamB, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamA = splStreamB.lowLatency();
assertSPLStream(splStreamA, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamA = splStreamA.filter(new AllowAll<Tuple>());
splStreamB = splStreamA.endLowLatency();
assertSPLStream(splStreamB, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamA = splStreamB.parallel(3);
assertSPLStream(splStreamA, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamA = splStreamA.filter(new AllowAll<Tuple>());
splStreamB = splStreamA.endParallel();
assertSPLStream(splStreamB, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamB = splStreamB.filter(new AllowAll<Tuple>());
splStreamA = splStreamB.parallel(of(2), Routing.ROUND_ROBIN);
assertSPLStream(splStreamA, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamA = splStreamA.filter(new AllowAll<Tuple>());
splStreamB = splStreamA.endParallel();
assertSPLStream(splStreamB, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamB = splStreamB.filter(new AllowAll<Tuple>());
splStreamA = splStreamB.isolate();
assertSPLStream(splStreamA, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
splStreamB = splStreamA.autonomous();
assertSPLStream(splStreamB, TEST_SCHEMA);
assertNotSame(splStreamA, splStreamB);
}
use of com.ibm.streams.operator.Tuple in project streamsx.topology by IBMStreams.
the class SlidingSet method handleEvent.
@Override
public final synchronized void handleEvent(StreamWindowEvent<Tuple> event) throws Exception {
final Object partition = event.getPartition();
LinkedList<I> tuples = getPartitionState(partition);
switch(event.getType()) {
case INSERTION:
for (Tuple splTuple : event.getTuples()) {
I tuple = inputMapping.convertFrom(splTuple);
tuples.addLast(tuple);
}
break;
case EVICTION:
// means any eviction is always the oldest N tuples.
for (@SuppressWarnings("unused") Tuple splTuple : event.getTuples()) {
tuples.removeFirst();
}
break;
case PARTITION_EVICTION:
op.getnPartitions().incrementValue(-1);
break;
default:
break;
}
postSetUpdate(event, partition, tuples);
}
use of com.ibm.streams.operator.Tuple in project streamsx.topology by IBMStreams.
the class SPLStreams method toStringStream.
/**
* Convert an {@link SPLStream} to a TStream<String>
* by taking a specific attribute.
* The returned stream will contain a {@code String} tuple for
* each tuple {@code T} on {@code stream}, the value of the
* {@code String} tuple is {@code T.getString(attributeName)}.
* A runtime error will occur if the attribute
* can not be converted using {@code Tuple.getString(attributeName)}.
* @param stream Stream to be converted to a TStream<String>.
* @return Stream that will contain a single attribute of tuples from {@code stream}
*/
public static TStream<String> toStringStream(SPLStream stream, String attributeName) {
Attribute attribute = stream.getSchema().getAttribute(attributeName);
if (attribute == null) {
throw new IllegalArgumentException("Atttribute " + attributeName + " not present in SPL schema " + stream.getSchema().getLanguageType());
}
final int attributeIndex = attribute.getIndex();
return stream.convert(new Function<Tuple, String>() {
private static final long serialVersionUID = 1L;
@Override
public String apply(Tuple tuple) {
return tuple.getString(attributeIndex);
}
});
}
Aggregations