Search in sources :

Example 76 with RowData

use of org.apache.flink.table.data.RowData in project flink by apache.

the class StreamArrowPythonProcTimeBoundedRangeOperatorTest method testOverWindowAggregateFunction.

@Test
public void testOverWindowAggregateFunction() throws Exception {
    OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = getTestHarness(new Configuration());
    ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
    testHarness.open();
    testHarness.setProcessingTime(100);
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c2", 0L)));
    testHarness.setProcessingTime(150);
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c4", 1L)));
    testHarness.setProcessingTime(200);
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c6", 2L)));
    testHarness.setProcessingTime(300);
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c2", "c8", 3L)));
    testHarness.setProcessingTime(600);
    testHarness.close();
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c2", 0L, 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c4", 1L, 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c6", 2L, 1L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", "c8", 3L, 3L)));
    assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
}
Also used : RowData(org.apache.flink.table.data.RowData) Configuration(org.apache.flink.configuration.Configuration) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 77 with RowData

use of org.apache.flink.table.data.RowData in project flink by apache.

the class StreamArrowPythonRowTimeBoundedRangeOperatorTest method testStateCleanup.

@Test
public void testStateCleanup() throws Exception {
    Configuration conf = new Configuration();
    OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = getTestHarness(conf);
    AbstractStreamOperator<RowData> operator = testHarness.getOperator();
    testHarness.open();
    AbstractKeyedStateBackend stateBackend = (AbstractKeyedStateBackend) operator.getKeyedStateBackend();
    assertEquals("Initial state is not empty", 0, stateBackend.numKeyValueStateEntries());
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c2", 0L, 100L)));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c4", 1L, 100L)));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c6", 2L, 500L)));
    testHarness.processWatermark(new Watermark(1000L));
    // at this moment we expect the function to have some records in state
    testHarness.processWatermark(new Watermark(4000L));
    // at this moment the function should have cleaned up states
    assertEquals("State has not been cleaned up", 0, stateBackend.numKeyValueStateEntries());
    testHarness.close();
}
Also used : RowData(org.apache.flink.table.data.RowData) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) Configuration(org.apache.flink.configuration.Configuration) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test)

Example 78 with RowData

use of org.apache.flink.table.data.RowData in project flink by apache.

the class BatchArrowPythonOverWindowAggregateFunctionOperatorTest method testOverWindowAggregateFunction.

@Test
public void testOverWindowAggregateFunction() throws Exception {
    OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = getTestHarness(new Configuration());
    long initialTime = 0L;
    ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
    testHarness.open();
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c2", 0L, 0L), initialTime + 1));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c4", 1L, 0L), initialTime + 2));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c6", 2L, 10L), initialTime + 3));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c2", "c8", 3L, 0L), initialTime + 3));
    testHarness.close();
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c2", 0L, 0L, 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c4", 1L, 0L, 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c6", 2L, 10L, 2L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", "c8", 3L, 0L, 3L)));
    assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
}
Also used : RowData(org.apache.flink.table.data.RowData) Configuration(org.apache.flink.configuration.Configuration) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 79 with RowData

use of org.apache.flink.table.data.RowData in project flink by apache.

the class StreamArrowPythonGroupWindowAggregateFunctionOperatorTest method testGroupWindowAggregateFunction.

@Test
public void testGroupWindowAggregateFunction() throws Exception {
    OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = getTestHarness(new Configuration());
    long initialTime = 0L;
    ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
    testHarness.open();
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c2", 0L, 0L), initialTime + 1));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c4", 1L, 6000L), initialTime + 2));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c6", 2L, 10000L), initialTime + 3));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c2", "c8", 3L, 0L), initialTime + 4));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c3", "c8", 3L, 0L), initialTime + 5));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(false, "c3", "c8", 3L, 0L), initialTime + 6));
    testHarness.processWatermark(Long.MAX_VALUE);
    testHarness.close();
    expectedOutput.add(new Watermark(Long.MAX_VALUE));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 0L, TimestampData.fromEpochMillis(-5000L), TimestampData.fromEpochMillis(5000L))));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", 3L, TimestampData.fromEpochMillis(-5000L), TimestampData.fromEpochMillis(5000L))));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 0L, TimestampData.fromEpochMillis(0L), TimestampData.fromEpochMillis(10000L))));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", 3L, TimestampData.fromEpochMillis(0L), TimestampData.fromEpochMillis(10000L))));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 1L, TimestampData.fromEpochMillis(5000L), TimestampData.fromEpochMillis(15000L))));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 2L, TimestampData.fromEpochMillis(10000L), TimestampData.fromEpochMillis(20000L))));
    assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
}
Also used : RowData(org.apache.flink.table.data.RowData) Configuration(org.apache.flink.configuration.Configuration) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test)

Example 80 with RowData

use of org.apache.flink.table.data.RowData in project flink by apache.

the class StreamArrowPythonGroupWindowAggregateFunctionOperatorTest method testFinishBundleTriggeredByCount.

@Test
public void testFinishBundleTriggeredByCount() throws Exception {
    Configuration conf = new Configuration();
    conf.setInteger(PythonOptions.MAX_BUNDLE_SIZE, 4);
    OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = getTestHarness(conf);
    long initialTime = 0L;
    ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
    testHarness.open();
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c2", 0L, 0L), initialTime + 1));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c4", 1L, 6000L), initialTime + 2));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c6", 2L, 10000L), initialTime + 3));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c2", "c8", 3L, 0L), initialTime + 4));
    testHarness.processWatermark(new Watermark(10000L));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 0L, TimestampData.fromEpochMillis(-5000L), TimestampData.fromEpochMillis(5000L))));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", 3L, TimestampData.fromEpochMillis(-5000L), TimestampData.fromEpochMillis(5000L))));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", 3L, TimestampData.fromEpochMillis(0L), TimestampData.fromEpochMillis(10000L))));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 0L, TimestampData.fromEpochMillis(0L), TimestampData.fromEpochMillis(10000L))));
    expectedOutput.add(new Watermark(10000L));
    assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
    testHarness.processWatermark(20000L);
    testHarness.close();
    expectedOutput.add(new Watermark(20000L));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 1L, TimestampData.fromEpochMillis(5000L), TimestampData.fromEpochMillis(15000L))));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 2L, TimestampData.fromEpochMillis(10000L), TimestampData.fromEpochMillis(20000L))));
    assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
}
Also used : RowData(org.apache.flink.table.data.RowData) Configuration(org.apache.flink.configuration.Configuration) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test)

Aggregations

RowData (org.apache.flink.table.data.RowData)602 Test (org.junit.Test)201 GenericRowData (org.apache.flink.table.data.GenericRowData)178 ArrayList (java.util.ArrayList)109 RowType (org.apache.flink.table.types.logical.RowType)105 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)90 Watermark (org.apache.flink.streaming.api.watermark.Watermark)84 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)72 Transformation (org.apache.flink.api.dag.Transformation)70 Configuration (org.apache.flink.configuration.Configuration)68 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)67 List (java.util.List)65 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)54 DataType (org.apache.flink.table.types.DataType)52 Map (java.util.Map)42 LogicalType (org.apache.flink.table.types.logical.LogicalType)41 TableException (org.apache.flink.table.api.TableException)34 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)33 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)32 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)31