Search in sources :

Example 6 with InputOperatorSpec

use of org.apache.samza.operators.spec.InputOperatorSpec in project samza by apache.

the class TestStreamApplicationDescriptorImpl method testGetInputStreamWithTransformFunction.

@Test
public void testGetInputStreamWithTransformFunction() {
    String streamId = "test-stream-1";
    Serde mockValueSerde = mock(Serde.class);
    InputTransformer transformer = ime -> ime;
    MockTransformingSystemDescriptor sd = new MockTransformingSystemDescriptor("mockSystem", transformer);
    MockInputDescriptor isd = sd.getInputDescriptor(streamId, mockValueSerde);
    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(transformer, inputOpSpec.getTransformer());
}
Also used : Serde(org.apache.samza.serializers.Serde) IntegerSerde(org.apache.samza.serializers.IntegerSerde) NoOpSerde(org.apache.samza.serializers.NoOpSerde) KVSerde(org.apache.samza.serializers.KVSerde) SystemDescriptor(org.apache.samza.system.descriptors.SystemDescriptor) GenericSystemDescriptor(org.apache.samza.system.descriptors.GenericSystemDescriptor) IntermediateMessageStreamImpl(org.apache.samza.operators.stream.IntermediateMessageStreamImpl) HashMap(java.util.HashMap) Serde(org.apache.samza.serializers.Serde) GenericInputDescriptor(org.apache.samza.system.descriptors.GenericInputDescriptor) AtomicReference(java.util.concurrent.atomic.AtomicReference) TableImpl(org.apache.samza.operators.TableImpl) ArrayList(java.util.ArrayList) OutputStreamImpl(org.apache.samza.operators.spec.OutputStreamImpl) OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) BaseTableDescriptor(org.apache.samza.table.descriptors.BaseTableDescriptor) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ApplicationConfig(org.apache.samza.config.ApplicationConfig) InputTransformer(org.apache.samza.system.descriptors.InputTransformer) ProcessorLifecycleListenerFactory(org.apache.samza.runtime.ProcessorLifecycleListenerFactory) Assert.fail(org.junit.Assert.fail) MapConfig(org.apache.samza.config.MapConfig) IntegerSerde(org.apache.samza.serializers.IntegerSerde) NoOpSerde(org.apache.samza.serializers.NoOpSerde) Mockito.doReturn(org.mockito.Mockito.doReturn) TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) OpCode(org.apache.samza.operators.spec.OperatorSpec.OpCode) InputDescriptor(org.apache.samza.system.descriptors.InputDescriptor) ApplicationContainerContextFactory(org.apache.samza.context.ApplicationContainerContextFactory) GenericOutputDescriptor(org.apache.samza.system.descriptors.GenericOutputDescriptor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TransformingInputDescriptorProvider(org.apache.samza.system.descriptors.TransformingInputDescriptorProvider) SamzaException(org.apache.samza.SamzaException) ApplicationTaskContextFactory(org.apache.samza.context.ApplicationTaskContextFactory) ExpandingInputDescriptorProvider(org.apache.samza.system.descriptors.ExpandingInputDescriptorProvider) StreamExpander(org.apache.samza.system.descriptors.StreamExpander) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Config(org.apache.samza.config.Config) KVSerde(org.apache.samza.serializers.KVSerde) StreamApplication(org.apache.samza.application.StreamApplication) Assert.assertEquals(org.junit.Assert.assertEquals) InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec) Mockito.mock(org.mockito.Mockito.mock) InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec) InputTransformer(org.apache.samza.system.descriptors.InputTransformer) Test(org.junit.Test)

Example 7 with InputOperatorSpec

use of org.apache.samza.operators.spec.InputOperatorSpec 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());
}
Also used : Serde(org.apache.samza.serializers.Serde) IntegerSerde(org.apache.samza.serializers.IntegerSerde) NoOpSerde(org.apache.samza.serializers.NoOpSerde) KVSerde(org.apache.samza.serializers.KVSerde) OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec) KVSerde(org.apache.samza.serializers.KVSerde) TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) Test(org.junit.Test)

Example 8 with InputOperatorSpec

use of org.apache.samza.operators.spec.InputOperatorSpec in project samza by apache.

the class OperatorSpecGraph method findAllOperatorSpecs.

private HashSet<OperatorSpec> findAllOperatorSpecs() {
    Collection<InputOperatorSpec> inputOperatorSpecs = this.inputOperators.values();
    HashSet<OperatorSpec> operatorSpecs = new HashSet<>();
    for (InputOperatorSpec inputOperatorSpec : inputOperatorSpecs) {
        operatorSpecs.add(inputOperatorSpec);
        doGetOperatorSpecs(inputOperatorSpec, operatorSpecs);
    }
    return operatorSpecs;
}
Also used : OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec) InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec) HashSet(java.util.HashSet)

Example 9 with InputOperatorSpec

use of org.apache.samza.operators.spec.InputOperatorSpec in project samza by apache.

the class ExecutionPlanner method getStreamSet.

/**
 * Creates a {@link StreamSet} whose Id is {@code setId}, and {@link StreamEdge}s
 * correspond to the provided {@code inputOpSpecs}.
 */
private static StreamSet getStreamSet(String setId, Iterable<InputOperatorSpec> inputOpSpecs, JobGraph jobGraph) {
    Set<StreamEdge> streamEdges = new HashSet<>();
    for (InputOperatorSpec inputOpSpec : inputOpSpecs) {
        StreamEdge streamEdge = jobGraph.getStreamEdge(inputOpSpec.getStreamId());
        streamEdges.add(streamEdge);
    }
    return new StreamSet(setId, streamEdges);
}
Also used : InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec) HashSet(java.util.HashSet)

Example 10 with InputOperatorSpec

use of org.apache.samza.operators.spec.InputOperatorSpec in project samza by apache.

the class OperatorSpecGraphAnalyzer method getJoinToInputOperatorSpecs.

/**
 * Returns a grouping of {@link InputOperatorSpec}s by the joins, i.e. {@link JoinOperatorSpec}s and
 * {@link StreamTableJoinOperatorSpec}s, they participate in.
 *
 * The key of the returned Multimap is of type {@link OperatorSpec} due to the lack of a stricter
 * base type for {@link JoinOperatorSpec} and {@link StreamTableJoinOperatorSpec}. However, key
 * objects are guaranteed to be of either type only.
 */
public static Multimap<OperatorSpec, InputOperatorSpec> getJoinToInputOperatorSpecs(Collection<InputOperatorSpec> inputOpSpecs) {
    Multimap<OperatorSpec, InputOperatorSpec> joinToInputOpSpecs = HashMultimap.create();
    // Create a getNextOpSpecs() function that emulates connections between every SendToTableOperatorSpec
    // — which are terminal OperatorSpecs — and all StreamTableJoinOperatorSpecs referencing the same table.
    // 
    // This is necessary to support Stream-Table Join scenarios because it allows us to associate streams behind
    // SendToTableOperatorSpecs with streams participating in Stream-Table Joins, a connection that would not be
    // easy to make otherwise since SendToTableOperatorSpecs are terminal operator specs.
    Function<OperatorSpec, Iterable<OperatorSpec>> getNextOpSpecs = getCustomGetNextOpSpecs(inputOpSpecs);
    // and join-related operator specs.
    for (InputOperatorSpec inputOpSpec : inputOpSpecs) {
        // Observe all join-related operator specs reachable from this input operator spec.
        JoinVisitor joinVisitor = new JoinVisitor();
        traverse(inputOpSpec, joinVisitor, getNextOpSpecs);
        // Associate every encountered join-related operator spec with this input operator spec.
        for (OperatorSpec joinOpSpec : joinVisitor.getJoins()) {
            joinToInputOpSpecs.put(joinOpSpec, inputOpSpec);
        }
    }
    return joinToInputOpSpecs;
}
Also used : JoinOperatorSpec(org.apache.samza.operators.spec.JoinOperatorSpec) SendToTableOperatorSpec(org.apache.samza.operators.spec.SendToTableOperatorSpec) OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) StreamTableJoinOperatorSpec(org.apache.samza.operators.spec.StreamTableJoinOperatorSpec) InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec) InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec)

Aggregations

InputOperatorSpec (org.apache.samza.operators.spec.InputOperatorSpec)23 Test (org.junit.Test)13 Serde (org.apache.samza.serializers.Serde)11 KVSerde (org.apache.samza.serializers.KVSerde)10 OperatorSpec (org.apache.samza.operators.spec.OperatorSpec)9 NoOpSerde (org.apache.samza.serializers.NoOpSerde)9 IntegerSerde (org.apache.samza.serializers.IntegerSerde)8 GenericSystemDescriptor (org.apache.samza.system.descriptors.GenericSystemDescriptor)7 GenericInputDescriptor (org.apache.samza.system.descriptors.GenericInputDescriptor)6 ArrayList (java.util.ArrayList)5 OutputStreamImpl (org.apache.samza.operators.spec.OutputStreamImpl)5 StreamTableJoinOperatorSpec (org.apache.samza.operators.spec.StreamTableJoinOperatorSpec)5 IntermediateMessageStreamImpl (org.apache.samza.operators.stream.IntermediateMessageStreamImpl)5 Config (org.apache.samza.config.Config)4 HashSet (java.util.HashSet)3 ApplicationConfig (org.apache.samza.config.ApplicationConfig)3 MapConfig (org.apache.samza.config.MapConfig)3 TestMessageEnvelope (org.apache.samza.operators.data.TestMessageEnvelope)3 IncomingMessageEnvelope (org.apache.samza.system.IncomingMessageEnvelope)3 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)3