Search in sources :

Example 1 with OneInput

use of org.apache.flink.table.runtime.operators.multipleinput.input.OneInput in project flink by apache.

the class BatchMultipleInputStreamOperatorTest method testProcess.

@Test
public void testProcess() throws Exception {
    TestingBatchMultipleInputStreamOperator op = createMultipleInputStreamOperator();
    List<StreamElement> outputData = op.getOutputData();
    TestingTwoInputStreamOperator joinOp2 = (TestingTwoInputStreamOperator) op.getTailWrapper().getStreamOperator();
    TableOperatorWrapper<?> joinWrapper1 = op.getTailWrapper().getInputWrappers().get(0);
    TestingTwoInputStreamOperator joinOp1 = (TestingTwoInputStreamOperator) joinWrapper1.getStreamOperator();
    TableOperatorWrapper<?> aggWrapper1 = joinWrapper1.getInputWrappers().get(0);
    TestingOneInputStreamOperator aggOp1 = (TestingOneInputStreamOperator) aggWrapper1.getStreamOperator();
    TableOperatorWrapper<?> aggWrapper2 = joinWrapper1.getInputWrappers().get(1);
    TestingOneInputStreamOperator aggOp2 = (TestingOneInputStreamOperator) aggWrapper2.getStreamOperator();
    List<Input> inputs = op.getInputs();
    assertEquals(3, inputs.size());
    Input input1 = inputs.get(0);
    Input input2 = inputs.get(1);
    Input input3 = inputs.get(2);
    assertTrue(input1 instanceof OneInput);
    assertTrue(input2 instanceof OneInput);
    assertTrue(input3 instanceof SecondInputOfTwoInput);
    assertNull(joinOp2.getCurrentElement1());
    assertNull(joinOp2.getCurrentElement2());
    assertNull(joinOp1.getCurrentElement1());
    assertNull(joinOp1.getCurrentElement2());
    assertNull(aggOp1.getCurrentElement());
    assertNull(aggOp2.getCurrentElement());
    assertTrue(outputData.isEmpty());
    // process first input (input id is 3)
    StreamRecord<RowData> element1 = new StreamRecord<>(GenericRowData.of(StringData.fromString("123")), 456);
    input3.processElement(element1);
    assertEquals(element1, joinOp2.getCurrentElement2());
    assertNull(joinOp2.getCurrentElement1());
    assertTrue(outputData.isEmpty());
    // finish first input
    assertTrue(joinOp2.getEndInputs().isEmpty());
    op.endInput(3);
    assertTrue(outputData.isEmpty());
    assertEquals(Collections.singletonList(2), joinOp2.getEndInputs());
    // process second input (input id is 1)
    StreamRecord<RowData> element2 = new StreamRecord<>(GenericRowData.of(StringData.fromString("124")), 457);
    input1.processElement(element2);
    assertEquals(element2, aggOp1.getCurrentElement());
    assertNull(joinOp1.getCurrentElement1());
    assertNull(joinOp2.getCurrentElement1());
    assertTrue(outputData.isEmpty());
    // finish second input
    assertTrue(joinOp1.getEndInputs().isEmpty());
    op.endInput(1);
    assertEquals(Collections.singletonList(1), joinOp1.getEndInputs());
    assertEquals(Collections.singletonList(2), joinOp2.getEndInputs());
    assertEquals(element2, joinOp1.getCurrentElement1());
    assertTrue(outputData.isEmpty());
    // process third input (input id is 2)
    StreamRecord<RowData> element3 = new StreamRecord<>(GenericRowData.of(StringData.fromString("125")), 458);
    input2.processElement(element3);
    assertEquals(element3, aggOp2.getCurrentElement());
    assertNull(joinOp1.getCurrentElement2());
    assertNull(joinOp2.getCurrentElement1());
    assertTrue(outputData.isEmpty());
    // finish third input
    assertEquals(Collections.singletonList(1), joinOp1.getEndInputs());
    op.endInput(2);
    assertEquals(Arrays.asList(1, 2), joinOp1.getEndInputs());
    assertEquals(Arrays.asList(2, 1), joinOp2.getEndInputs());
    assertEquals(element3, joinOp1.getCurrentElement2());
    assertEquals(3, outputData.size());
}
Also used : SecondInputOfTwoInput(org.apache.flink.table.runtime.operators.multipleinput.input.SecondInputOfTwoInput) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) SecondInputOfTwoInput(org.apache.flink.table.runtime.operators.multipleinput.input.SecondInputOfTwoInput) OneInput(org.apache.flink.table.runtime.operators.multipleinput.input.OneInput) Input(org.apache.flink.streaming.api.operators.Input) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) OneInput(org.apache.flink.table.runtime.operators.multipleinput.input.OneInput) Test(org.junit.Test)

Aggregations

Input (org.apache.flink.streaming.api.operators.Input)1 StreamElement (org.apache.flink.streaming.runtime.streamrecord.StreamElement)1 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)1 GenericRowData (org.apache.flink.table.data.GenericRowData)1 RowData (org.apache.flink.table.data.RowData)1 OneInput (org.apache.flink.table.runtime.operators.multipleinput.input.OneInput)1 SecondInputOfTwoInput (org.apache.flink.table.runtime.operators.multipleinput.input.SecondInputOfTwoInput)1 Test (org.junit.Test)1