Search in sources :

Example 86 with RowData

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

the class StreamArrowPythonRowTimeBoundedRowsOperatorTest method testFinishBundleTriggeredByTime.

@Test
public void testFinishBundleTriggeredByTime() throws Exception {
    Configuration conf = new Configuration();
    conf.setInteger(PythonOptions.MAX_BUNDLE_SIZE, 10);
    conf.setLong(PythonOptions.MAX_BUNDLE_TIME_MILLS, 1000L);
    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, 1L), initialTime + 1));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c4", 1L, 1L), initialTime + 2));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c6", 2L, 10L), initialTime + 3));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c2", "c8", 3L, 2L), initialTime + 3));
    testHarness.processWatermark(new Watermark(10000L));
    expectedOutput.add(new Watermark(10000L));
    assertOutputEquals("FinishBundle should not be triggered.", expectedOutput, testHarness.getOutput());
    testHarness.setProcessingTime(1000L);
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c2", 0L, 1L, 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c4", 1L, 1L, 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", "c8", 3L, 2L, 3L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c6", 2L, 10L, 1L)));
    assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
    testHarness.close();
}
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 87 with RowData

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

the class StreamArrowPythonRowTimeBoundedRowsOperatorTest 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, 1L), initialTime + 1));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c4", 1L, 1L), initialTime + 2));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c1", "c6", 2L, 10L), initialTime + 3));
    testHarness.processElement(new StreamRecord<>(newBinaryRow(true, "c2", "c8", 3L, 2L), initialTime + 3));
    testHarness.processWatermark(Long.MAX_VALUE);
    testHarness.close();
    expectedOutput.add(new Watermark(Long.MAX_VALUE));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c2", 0L, 1L, 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c4", 1L, 1L, 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", "c8", 3L, 2L, 3L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", "c6", 2L, 10L, 1L)));
    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 88 with RowData

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

the class PassThroughPythonStreamGroupWindowAggregateOperator method cleanWindowIfNeeded.

private void cleanWindowIfNeeded(RowData key, TimeWindow window, long currentTime) throws IOException {
    if (currentTime == cleanupTime(window)) {
        // 1. delete state
        // only output first value in group window.
        DataOutputSerializer output = new DataOutputSerializer(1);
        RowData windowProperty = windowExtractor.apply(window);
        windowAggResult.replace(GenericRowData.of(StringData.fromString("state_cleanup_triggered: " + key.getString(0).toString() + " : " + window)), GenericRowData.of(0L));
        reuseJoinedRow.replace(windowAggResult, windowProperty);
        reusePythonRowData.setField(1, reuseJoinedRow);
        udfOutputTypeSerializer.serialize(reusePythonRowData, output);
        resultBuffer.add(output.getCopyOfBuffer());
        // 2. delete window timer
        if (windowAssigner.isEventTime()) {
            deleteEventTimeTimer(key, window);
        } else {
            deleteProcessingTimeTimer(key, window);
        }
    }
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) UpdatableRowData(org.apache.flink.table.data.UpdatableRowData)

Example 89 with RowData

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

the class PassThroughPythonStreamGroupWindowAggregateOperator method triggerWindowProcess.

private void triggerWindowProcess(RowData key, TimeWindow window) throws Exception {
    DataOutputSerializer output = new DataOutputSerializer(1);
    Iterable<RowData> currentWindowAccumulateData = windowAccumulateData.get(key.getString(0).toString()).get(window);
    Iterable<RowData> currentWindowRetractData = windowRetractData.get(key.getString(0).toString()).get(window);
    if (currentWindowAccumulateData != null) {
        for (RowData accumulateData : currentWindowAccumulateData) {
            if (!hasRetractData(accumulateData, currentWindowRetractData)) {
                // only output first value in group window.
                RowData aggResult = aggExtracter.apply(accumulateData);
                RowData windowProperty = windowExtractor.apply(window);
                windowAggResult.replace(key, aggResult);
                reuseJoinedRow.replace(windowAggResult, windowProperty);
                reusePythonRowData.setField(1, reuseJoinedRow);
                udfOutputTypeSerializer.serialize(reusePythonRowData, output);
                resultBuffer.add(output.getCopyOfBuffer());
                break;
            }
        }
    }
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) UpdatableRowData(org.apache.flink.table.data.UpdatableRowData)

Example 90 with RowData

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

the class PythonStreamGroupTableAggregateOperatorTest method testFinishBundleTriggeredOnCheckpoint.

@Test
public void testFinishBundleTriggeredOnCheckpoint() throws Exception {
    Configuration conf = new Configuration();
    conf.setInteger(PythonOptions.MAX_BUNDLE_SIZE, 10);
    OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = getTestHarness(conf);
    long initialTime = 0L;
    ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
    testHarness.open();
    testHarness.processElement(new StreamRecord<>(newRow(true, "c1", 0L), initialTime + 1));
    testHarness.processElement(new StreamRecord<>(newRow(true, "c2", 1L), initialTime + 2));
    testHarness.processElement(new StreamRecord<>(newRow(true, "c3", 2L), initialTime + 3));
    // checkpoint trigger finishBundle
    testHarness.prepareSnapshotPreBarrier(0L);
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c1", 0L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", 1L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c2", 1L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c3", 2L)));
    expectedOutput.add(new StreamRecord<>(newRow(true, "c3", 2L)));
    assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
    testHarness.close();
}
Also used : RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) Configuration(org.apache.flink.configuration.Configuration) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) 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