Search in sources :

Example 6 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class RowTimeRowsBoundedPrecedingFunction method open.

@Override
public void open(Configuration parameters) throws Exception {
    function = genAggsHandler.newInstance(getRuntimeContext().getUserCodeClassLoader());
    function.open(new PerKeyStateDataViewStore(getRuntimeContext()));
    output = new JoinedRowData();
    ValueStateDescriptor<Long> lastTriggeringTsDescriptor = new ValueStateDescriptor<Long>("lastTriggeringTsState", Types.LONG);
    lastTriggeringTsState = getRuntimeContext().getState(lastTriggeringTsDescriptor);
    ValueStateDescriptor<Long> dataCountStateDescriptor = new ValueStateDescriptor<Long>("processedCountState", Types.LONG);
    counterState = getRuntimeContext().getState(dataCountStateDescriptor);
    InternalTypeInfo<RowData> accTypeInfo = InternalTypeInfo.ofFields(accTypes);
    ValueStateDescriptor<RowData> accStateDesc = new ValueStateDescriptor<RowData>("accState", accTypeInfo);
    accState = getRuntimeContext().getState(accStateDesc);
    // input element are all binary row as they are came from network
    InternalTypeInfo<RowData> inputType = InternalTypeInfo.ofFields(inputFieldTypes);
    ListTypeInfo<RowData> rowListTypeInfo = new ListTypeInfo<RowData>(inputType);
    MapStateDescriptor<Long, List<RowData>> inputStateDesc = new MapStateDescriptor<Long, List<RowData>>("inputState", Types.LONG, rowListTypeInfo);
    inputState = getRuntimeContext().getMapState(inputStateDesc);
    initCleanupTimeState("RowTimeBoundedRowsOverCleanupTime");
    // metrics
    this.numLateRecordsDropped = getRuntimeContext().getMetricGroup().counter(LATE_ELEMENTS_DROPPED_METRIC_NAME);
}
Also used : MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) RowData(org.apache.flink.table.data.RowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) ListTypeInfo(org.apache.flink.api.java.typeutils.ListTypeInfo) ArrayList(java.util.ArrayList) List(java.util.List) PerKeyStateDataViewStore(org.apache.flink.table.runtime.dataview.PerKeyStateDataViewStore)

Example 7 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class StreamingJoinOperator method open.

@Override
public void open() throws Exception {
    super.open();
    this.outRow = new JoinedRowData();
    this.leftNullRow = new GenericRowData(leftType.toRowSize());
    this.rightNullRow = new GenericRowData(rightType.toRowSize());
    // initialize states
    if (leftIsOuter) {
        this.leftRecordStateView = OuterJoinRecordStateViews.create(getRuntimeContext(), "left-records", leftInputSideSpec, leftType, stateRetentionTime);
    } else {
        this.leftRecordStateView = JoinRecordStateViews.create(getRuntimeContext(), "left-records", leftInputSideSpec, leftType, stateRetentionTime);
    }
    if (rightIsOuter) {
        this.rightRecordStateView = OuterJoinRecordStateViews.create(getRuntimeContext(), "right-records", rightInputSideSpec, rightType, stateRetentionTime);
    } else {
        this.rightRecordStateView = JoinRecordStateViews.create(getRuntimeContext(), "right-records", rightInputSideSpec, rightType, stateRetentionTime);
    }
}
Also used : JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) GenericRowData(org.apache.flink.table.data.GenericRowData)

Example 8 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class BufferDataOverWindowOperator method processCurrentData.

private void processCurrentData() throws Exception {
    currentData.complete();
    for (OverWindowFrame frame : overWindowFrames) {
        frame.prepare(currentData);
    }
    int rowIndex = 0;
    ResettableExternalBuffer.BufferIterator bufferIterator = currentData.newIterator();
    while (bufferIterator.advanceNext()) {
        BinaryRowData currentRow = bufferIterator.getRow();
        RowData output = currentRow;
        // JoinedRowData is slow.
        for (int i = 0; i < overWindowFrames.length; i++) {
            OverWindowFrame frame = overWindowFrames[i];
            RowData value = frame.process(rowIndex, currentRow);
            output = joinedRows[i].replace(output, value);
        }
        collector.collect(output);
        rowIndex += 1;
    }
    bufferIterator.close();
    currentData.reset();
}
Also used : RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) ResettableExternalBuffer(org.apache.flink.table.runtime.util.ResettableExternalBuffer) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) OverWindowFrame(org.apache.flink.table.runtime.operators.over.frame.OverWindowFrame)

Example 9 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class String2SortMergeJoinOperatorTest method testFullJoin.

@Test
public void testFullJoin() throws Exception {
    StreamOperator joinOperator = newOperator(FlinkJoinType.FULL, leftIsSmall);
    TwoInputStreamTaskTestHarness<BinaryRowData, BinaryRowData, JoinedRowData> testHarness = buildSortMergeJoin(joinOperator);
    ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
    expectedOutput.add(new StreamRecord<>(newRow("a", "02")));
    expectedOutput.add(new StreamRecord<>(newRow("b", "14")));
    expectedOutput.add(new StreamRecord<>(newRow("c", "2null")));
    expectedOutput.add(new StreamRecord<>(newRow("d", "0null")));
    testHarness.waitForTaskCompletion();
    TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, transformToBinary(testHarness.getOutput()));
}
Also used : JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) Test(org.junit.Test)

Example 10 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class String2SortMergeJoinOperatorTest method testLeftOuterJoin.

@Test
public void testLeftOuterJoin() throws Exception {
    StreamOperator joinOperator = newOperator(FlinkJoinType.LEFT, leftIsSmall);
    TwoInputStreamTaskTestHarness<BinaryRowData, BinaryRowData, JoinedRowData> testHarness = buildSortMergeJoin(joinOperator);
    ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
    expectedOutput.add(new StreamRecord<>(newRow("a", "02")));
    expectedOutput.add(new StreamRecord<>(newRow("b", "14")));
    expectedOutput.add(new StreamRecord<>(newRow("d", "0null")));
    testHarness.waitForTaskCompletion();
    TestHarnessUtil.assertOutputEquals("Output was not correct.", expectedOutput, transformToBinary(testHarness.getOutput()));
}
Also used : JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) Test(org.junit.Test)

Aggregations

JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)47 RowData (org.apache.flink.table.data.RowData)22 GenericRowData (org.apache.flink.table.data.GenericRowData)17 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)12 PerKeyStateDataViewStore (org.apache.flink.table.runtime.dataview.PerKeyStateDataViewStore)12 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)11 ArrayList (java.util.ArrayList)7 List (java.util.List)7 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)7 ListTypeInfo (org.apache.flink.api.java.typeutils.ListTypeInfo)5 StreamOperator (org.apache.flink.streaming.api.operators.StreamOperator)5 Test (org.junit.Test)5 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)4 StateTtlConfig (org.apache.flink.api.common.state.StateTtlConfig)4 Configuration (org.apache.flink.configuration.Configuration)4 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)3 TwoInputStreamTask (org.apache.flink.streaming.runtime.tasks.TwoInputStreamTask)3 TwoInputStreamTaskTestHarness (org.apache.flink.streaming.runtime.tasks.TwoInputStreamTaskTestHarness)3 StreamRecordRowDataWrappingCollector (org.apache.flink.table.runtime.operators.python.utils.StreamRecordRowDataWrappingCollector)3 RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)3