use of org.apache.samza.table.Table in project samza by apache.
the class TestLocalTableEndToEnd method testSendTo.
@Test
public void testSendTo() {
MyMapFunction mapFn = new MyMapFunction();
StreamApplication app = appDesc -> {
Table<KV<Integer, Profile>> table = appDesc.getTable(new InMemoryTableDescriptor<>("t1", KVSerde.of(new IntegerSerde(), new ProfileJsonSerde())));
DelegatingSystemDescriptor ksd = new DelegatingSystemDescriptor(SYSTEM_NAME);
GenericInputDescriptor<Profile> isd = ksd.getInputDescriptor(PROFILE_STREAM, new NoOpSerde<>());
appDesc.getInputStream(isd).map(mapFn).sendTo(table);
};
InMemorySystemDescriptor isd = new InMemorySystemDescriptor(SYSTEM_NAME);
InMemoryInputDescriptor<Profile> profileStreamDesc = isd.getInputDescriptor(PROFILE_STREAM, new NoOpSerde<>());
int numProfilesPerPartition = 10;
int numInputPartitions = 4;
Map<Integer, List<Profile>> inputProfiles = TestTableData.generatePartitionedProfiles(numProfilesPerPartition * numInputPartitions, numInputPartitions);
TestRunner.of(app).addInputStream(profileStreamDesc, inputProfiles).run(Duration.ofSeconds(10));
for (int i = 0; i < numInputPartitions; i++) {
MyMapFunction mapFnCopy = MyMapFunction.getMapFunctionByTask(String.format("Partition %d", i));
assertEquals(numProfilesPerPartition, mapFnCopy.received.size());
mapFnCopy.received.forEach(p -> assertNotNull(mapFnCopy.table.get(p.getMemberId())));
}
}
use of org.apache.samza.table.Table in project samza by apache.
the class TestExecutionPlanner method createStreamGraphWithStreamTableJoin.
private StreamApplicationDescriptorImpl createStreamGraphWithStreamTableJoin() {
/**
* Example stream-table join app. Expected partition counts of intermediate streams introduced
* by partitionBy operations are enclosed in quotes.
*
* input2 (16) -> partitionBy ("32") -> send-to-table t
*
* join-table t —————
* | |
* input1 (64) -> partitionBy ("32") _| |
* join -> output1 (8)
* |
* input3 (32) ——————
*/
return new StreamApplicationDescriptorImpl(appDesc -> {
MessageStream<KV<Object, Object>> messageStream1 = appDesc.getInputStream(input1Descriptor);
MessageStream<KV<Object, Object>> messageStream2 = appDesc.getInputStream(input2Descriptor);
MessageStream<KV<Object, Object>> messageStream3 = appDesc.getInputStream(input3Descriptor);
OutputStream<KV<Object, Object>> output1 = appDesc.getOutputStream(output1Descriptor);
TableDescriptor tableDescriptor = new TestLocalTableDescriptor.MockLocalTableDescriptor("table-id", new KVSerde(new StringSerde(), new StringSerde()));
Table table = appDesc.getTable(tableDescriptor);
messageStream2.partitionBy(m -> m.key, m -> m.value, mock(KVSerde.class), "p1").sendTo(table);
messageStream1.partitionBy(m -> m.key, m -> m.value, mock(KVSerde.class), "p2").join(table, mock(StreamTableJoinFunction.class)).join(messageStream3, mock(JoinFunction.class), mock(Serde.class), mock(Serde.class), mock(Serde.class), Duration.ofHours(1), "j2").sendTo(output1);
}, config);
}
use of org.apache.samza.table.Table in project samza by apache.
the class TestExecutionPlanner method createStreamGraphWithInvalidStreamTableJoin.
private StreamApplicationDescriptorImpl createStreamGraphWithInvalidStreamTableJoin() {
/**
* Example stream-table join that is invalid due to disagreement in partition count
* between the 2 input streams.
*
* input1 (64) -> send-to-table t
*
* join-table t -> output1 (8)
* |
* input2 (16) —————————
*/
return new StreamApplicationDescriptorImpl(appDesc -> {
MessageStream<KV<Object, Object>> messageStream1 = appDesc.getInputStream(input1Descriptor);
MessageStream<KV<Object, Object>> messageStream2 = appDesc.getInputStream(input2Descriptor);
OutputStream<KV<Object, Object>> output1 = appDesc.getOutputStream(output1Descriptor);
TableDescriptor tableDescriptor = new TestLocalTableDescriptor.MockLocalTableDescriptor("table-id", new KVSerde(new StringSerde(), new StringSerde()));
Table table = appDesc.getTable(tableDescriptor);
messageStream1.sendTo(table);
messageStream1.join(table, mock(StreamTableJoinFunction.class)).join(messageStream2, mock(JoinFunction.class), mock(Serde.class), mock(Serde.class), mock(Serde.class), Duration.ofHours(1), "j2").sendTo(output1);
}, config);
}
use of org.apache.samza.table.Table in project samza by apache.
the class TestExecutionPlanner method createStreamGraphWithStreamTableJoinAndSendToSameTable.
private StreamApplicationDescriptorImpl createStreamGraphWithStreamTableJoinAndSendToSameTable() {
/**
* A special example of stream-table join where a stream is joined with a table, and the result is
* sent to the same table. This example is necessary to ensure {@link ExecutionPlanner} does not
* get stuck traversing the virtual cycle between stream-table-join and send-to-table operator specs
* indefinitely.
*
* The reason such virtual cycle is present is to support computing partitions of intermediate
* streams participating in stream-table joins. Please, refer to SAMZA SEP-16 for more details.
*/
return new StreamApplicationDescriptorImpl(appDesc -> {
MessageStream<KV<Object, Object>> messageStream1 = appDesc.getInputStream(input1Descriptor);
TableDescriptor tableDescriptor = new TestLocalTableDescriptor.MockLocalTableDescriptor("table-id", new KVSerde(new StringSerde(), new StringSerde()));
Table table = appDesc.getTable(tableDescriptor);
messageStream1.join(table, mock(StreamTableJoinFunction.class)).sendTo(table);
}, config);
}
Aggregations