use of org.apache.samza.serializers.KVSerde in project samza by apache.
the class ApplicationDescriptorImpl method getOrCreateStreamSerdes.
KV<Serde, Serde> getOrCreateStreamSerdes(String streamId, Serde serde) {
Serde keySerde, valueSerde;
KV<Serde, Serde> currentSerdePair = streamSerdes.get(streamId);
if (serde instanceof KVSerde) {
keySerde = ((KVSerde) serde).getKeySerde();
valueSerde = ((KVSerde) serde).getValueSerde();
} else {
keySerde = new NoOpSerde();
valueSerde = serde;
}
if (currentSerdePair == null) {
if (keySerde instanceof NoOpSerde) {
LOGGER.info("Using NoOpSerde as the key serde for stream " + streamId + ". Keys will not be (de)serialized");
}
if (valueSerde instanceof NoOpSerde) {
LOGGER.info("Using NoOpSerde as the value serde for stream " + streamId + ". Values will not be (de)serialized");
}
streamSerdes.put(streamId, KV.of(keySerde, valueSerde));
} else if (!currentSerdePair.getKey().getClass().equals(keySerde.getClass()) || !currentSerdePair.getValue().getClass().equals(valueSerde.getClass())) {
throw new IllegalArgumentException(String.format("Serde for streamId: %s is already defined. Cannot change it to " + "different serdes.", streamId));
} else {
LOGGER.warn("Using previously defined serde for streamId: " + streamId + ".");
}
return streamSerdes.get(streamId);
}
use of org.apache.samza.serializers.KVSerde in project samza by apache.
the class TestStreamApplicationDescriptorImpl method testGetInputStreamWithKeyValueSerde.
@Test
public void testGetInputStreamWithKeyValueSerde() {
String streamId = "test-stream-1";
KVSerde mockKVSerde = mock(KVSerde.class);
Serde mockKeySerde = mock(Serde.class);
Serde mockValueSerde = mock(Serde.class);
doReturn(mockKeySerde).when(mockKVSerde).getKeySerde();
doReturn(mockValueSerde).when(mockKVSerde).getValueSerde();
GenericSystemDescriptor sd = new GenericSystemDescriptor("mockSystem", "mockSystemFactoryClass");
GenericInputDescriptor isd = sd.getInputDescriptor(streamId, mockKVSerde);
StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> {
appDesc.getInputStream(isd);
}, getConfig());
InputOperatorSpec inputOpSpec = streamAppDesc.getInputOperators().get(streamId);
assertEquals(OpCode.INPUT, inputOpSpec.getOpCode());
assertEquals(streamId, inputOpSpec.getStreamId());
assertEquals(isd, streamAppDesc.getInputDescriptors().get(streamId));
assertEquals(mockKeySerde, inputOpSpec.getKeySerde());
assertEquals(mockValueSerde, inputOpSpec.getValueSerde());
}
use of org.apache.samza.serializers.KVSerde in project samza by apache.
the class TestStreamApplicationDescriptorImpl method testGetIntermediateStreamWithKeyValueSerde.
@Test
public void testGetIntermediateStreamWithKeyValueSerde() {
String streamId = "streamId";
StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> {
}, getConfig());
KVSerde mockKVSerde = mock(KVSerde.class);
Serde mockKeySerde = mock(Serde.class);
Serde mockValueSerde = mock(Serde.class);
doReturn(mockKeySerde).when(mockKVSerde).getKeySerde();
doReturn(mockValueSerde).when(mockKVSerde).getValueSerde();
IntermediateMessageStreamImpl<TestMessageEnvelope> intermediateStreamImpl = streamAppDesc.getIntermediateStream(streamId, mockKVSerde, false);
assertEquals(streamAppDesc.getInputOperators().get(streamId), intermediateStreamImpl.getOperatorSpec());
assertEquals(streamAppDesc.getOutputStreams().get(streamId), intermediateStreamImpl.getOutputStream());
assertEquals(streamId, intermediateStreamImpl.getStreamId());
assertEquals(mockKeySerde, intermediateStreamImpl.getOutputStream().getKeySerde());
assertEquals(mockValueSerde, intermediateStreamImpl.getOutputStream().getValueSerde());
assertEquals(mockKeySerde, ((InputOperatorSpec) (OperatorSpec) intermediateStreamImpl.getOperatorSpec()).getKeySerde());
assertEquals(mockValueSerde, ((InputOperatorSpec) (OperatorSpec) intermediateStreamImpl.getOperatorSpec()).getValueSerde());
}
use of org.apache.samza.serializers.KVSerde in project samza by apache.
the class TestExecutionPlanner method createStreamGraphWithStreamTableJoinWithSideInputs.
private StreamApplicationDescriptorImpl createStreamGraphWithStreamTableJoinWithSideInputs() {
/**
* Example stream-table join where table t is configured with input1 (64) as a side-input stream.
*
* join-table t -> output1 (8)
* |
* input2 (16) -> partitionBy ("64") __|
*/
return new StreamApplicationDescriptorImpl(appDesc -> {
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())).withSideInputs(Arrays.asList("input1")).withSideInputsProcessor(mock(SideInputsProcessor.class));
Table table = appDesc.getTable(tableDescriptor);
messageStream2.partitionBy(m -> m.key, m -> m.value, mock(KVSerde.class), "p1").join(table, mock(StreamTableJoinFunction.class)).sendTo(output1);
}, config);
}
use of org.apache.samza.serializers.KVSerde in project samza by apache.
the class TestExecutionPlanner method setup.
@Before
public void setup() {
Map<String, String> configMap = new HashMap<>();
configMap.put(JobConfig.JOB_NAME, "test-app");
configMap.put(JobConfig.JOB_DEFAULT_SYSTEM, DEFAULT_SYSTEM);
StreamTestUtils.addStreamConfigs(configMap, "input1", "system1", "input1");
StreamTestUtils.addStreamConfigs(configMap, "input2", "system2", "input2");
StreamTestUtils.addStreamConfigs(configMap, "input3", "system2", "input3");
StreamTestUtils.addStreamConfigs(configMap, "input4", "system1", "input4");
StreamTestUtils.addStreamConfigs(configMap, "output1", "system1", "output1");
StreamTestUtils.addStreamConfigs(configMap, "output2", "system2", "output2");
config = new MapConfig(configMap);
input1Spec = new StreamSpec("input1", "input1", "system1");
input2Spec = new StreamSpec("input2", "input2", "system2");
input3Spec = new StreamSpec("input3", "input3", "system2");
output1Spec = new StreamSpec("output1", "output1", "system1");
output2Spec = new StreamSpec("output2", "output2", "system2");
KVSerde<Object, Object> kvSerde = new KVSerde<>(new NoOpSerde(), new NoOpSerde());
String mockSystemFactoryClass = "factory.class.name";
system1Descriptor = new GenericSystemDescriptor("system1", mockSystemFactoryClass);
system2Descriptor = new GenericSystemDescriptor("system2", mockSystemFactoryClass);
input1Descriptor = system1Descriptor.getInputDescriptor("input1", kvSerde);
input2Descriptor = system2Descriptor.getInputDescriptor("input2", kvSerde);
input3Descriptor = system2Descriptor.getInputDescriptor("input3", kvSerde);
input4Descriptor = system1Descriptor.getInputDescriptor("input4", kvSerde);
output1Descriptor = system1Descriptor.getOutputDescriptor("output1", kvSerde);
output2Descriptor = system2Descriptor.getOutputDescriptor("output2", kvSerde);
// clean and set up sets and maps of descriptors
systemDescriptors.clear();
inputDescriptors.clear();
outputDescriptors.clear();
tableDescriptors.clear();
systemDescriptors.add(system1Descriptor);
systemDescriptors.add(system2Descriptor);
inputDescriptors.put(input1Descriptor.getStreamId(), input1Descriptor);
inputDescriptors.put(input2Descriptor.getStreamId(), input2Descriptor);
inputDescriptors.put(input3Descriptor.getStreamId(), input3Descriptor);
inputDescriptors.put(input4Descriptor.getStreamId(), input4Descriptor);
outputDescriptors.put(output1Descriptor.getStreamId(), output1Descriptor);
outputDescriptors.put(output2Descriptor.getStreamId(), output2Descriptor);
// set up external partition count
Map<String, Integer> system1Map = new HashMap<>();
system1Map.put("input1", 64);
system1Map.put("output1", 8);
system1Map.put("input4", IntermediateStreamManager.MAX_INFERRED_PARTITIONS * 2);
Map<String, Integer> system2Map = new HashMap<>();
system2Map.put("input2", 16);
system2Map.put("input3", 32);
system2Map.put("output2", 16);
SystemAdmin systemAdmin1 = createSystemAdmin(system1Map);
SystemAdmin systemAdmin2 = createSystemAdmin(system2Map);
systemAdmins = mock(SystemAdmins.class);
when(systemAdmins.getSystemAdmin("system1")).thenReturn(systemAdmin1);
when(systemAdmins.getSystemAdmin("system2")).thenReturn(systemAdmin2);
streamManager = new StreamManager(systemAdmins);
}
Aggregations