Search in sources :

Example 21 with JoinedRowData

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

the class StreamArrowPythonGroupWindowAggregateFunctionOperator method open.

@Override
public void open() throws Exception {
    super.open();
    windowSerializer = windowAssigner.getWindowSerializer(new ExecutionConfig());
    internalTimerService = getInternalTimerService("window-timers", windowSerializer, this);
    triggerContext = new TriggerContext();
    triggerContext.open();
    StateDescriptor<ListState<RowData>, List<RowData>> windowStateDescriptor = new ListStateDescriptor<>("window-input", new RowDataSerializer(inputType));
    StateDescriptor<ListState<RowData>, List<RowData>> dataRetractStateDescriptor = new ListStateDescriptor<>("data-retract", new RowDataSerializer(inputType));
    this.windowAccumulateData = (InternalListState<K, W, RowData>) getOrCreateKeyedState(windowSerializer, windowStateDescriptor);
    this.windowRetractData = (InternalListState<K, W, RowData>) getOrCreateKeyedState(windowSerializer, dataRetractStateDescriptor);
    inputKeyAndWindow = new LinkedList<>();
    windowProperty = new GenericRowData(namedProperties.length);
    windowAggResult = new JoinedRowData();
    WindowContext windowContext = new WindowContext();
    windowAssigner.open(windowContext);
}
Also used : ListState(org.apache.flink.api.common.state.ListState) InternalListState(org.apache.flink.runtime.state.internal.InternalListState) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) GenericRowData(org.apache.flink.table.data.GenericRowData) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer)

Example 22 with JoinedRowData

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

the class EmbeddedPythonScalarFunctionOperator method processElement.

@SuppressWarnings("unchecked")
@Override
public void processElement(StreamRecord<RowData> element) {
    RowData value = element.getValue();
    Object udfArgs = null;
    if (userDefinedFunctionInputArgs.length > 1) {
        for (int i = 0; i < userDefinedFunctionInputArgs.length; i++) {
            userDefinedFunctionInputArgs[i] = userDefinedFunctionInputConverters[i].toExternal(value, udfInputOffsets[i]);
        }
        udfArgs = userDefinedFunctionInputArgs;
    } else if (userDefinedFunctionInputArgs.length == 1) {
        udfArgs = userDefinedFunctionInputConverters[0].toExternal(value, udfInputOffsets[0]);
    }
    if (isOneFieldResult) {
        Object udfResult = interpreter.invokeMethod("scalar_operation", "process_element", udfArgs);
        reuseResultRowData.setField(0, userDefinedFunctionOutputConverters[0].toInternal(udfResult));
    } else {
        Object[] udfResult = (Object[]) interpreter.invokeMethod("scalar_operation", "process_element", udfArgs);
        for (int i = 0; i < udfResult.length; i++) {
            reuseResultRowData.setField(i, userDefinedFunctionOutputConverters[i].toInternal(udfResult[i]));
        }
    }
    if (forwardedFieldProjection != null) {
        BinaryRowData forwardedRowData = forwardedFieldProjection.apply(value).copy();
        JoinedRowData reuseJoinedRow = new JoinedRowData(forwardedRowData, reuseResultRowData);
        rowDataWrapper.collect(reuseJoinedRow);
    } else {
        rowDataWrapper.collect(reuseResultRowData);
    }
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData)

Example 23 with JoinedRowData

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

the class BatchArrowPythonGroupWindowAggregateFunctionOperator method open.

@Override
public void open() throws Exception {
    super.open();
    inputKeyAndWindow = new LinkedList<>();
    windowProperty = new GenericRowData(namedProperties.length);
    windowAggResult = new JoinedRowData();
    windowsGrouping = new HeapWindowsGrouping(maxLimitSize, windowSize, slideSize, inputTimeFieldIndex, false);
    forwardedInputSerializer = new RowDataSerializer(inputType);
}
Also used : JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) GenericRowData(org.apache.flink.table.data.GenericRowData) HeapWindowsGrouping(org.apache.flink.table.runtime.operators.window.grouping.HeapWindowsGrouping) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer)

Example 24 with JoinedRowData

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

the class AbstractPythonScalarFunctionOperator method open.

@SuppressWarnings("unchecked")
@Override
public void open() throws Exception {
    super.open();
    rowDataWrapper = new StreamRecordRowDataWrappingCollector(output);
    reuseJoinedRow = new JoinedRowData();
    udfInputProjection = udfInputGeneratedProjection.newInstance(Thread.currentThread().getContextClassLoader());
    forwardedFieldProjection = forwardedFieldGeneratedProjection.newInstance(Thread.currentThread().getContextClassLoader());
}
Also used : StreamRecordRowDataWrappingCollector(org.apache.flink.table.runtime.operators.python.utils.StreamRecordRowDataWrappingCollector) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData)

Example 25 with JoinedRowData

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

the class PassThroughPythonStreamGroupWindowAggregateOperator method open.

@Override
public void open() throws Exception {
    super.open();
    windowBaos = new ByteArrayOutputStreamWithPos();
    windowBaosWrapper = new DataOutputViewStreamWrapper(windowBaos);
    reusePythonRowData = new UpdatableRowData(GenericRowData.of(NORMAL_RECORD, null, null), 3);
    reusePythonTimerRowData = new UpdatableRowData(GenericRowData.of(TRIGGER_TIMER, null, null), 3);
    reusePythonTimerData = new UpdatableRowData(GenericRowData.of(0, null, null, null), 4);
    reuseJoinedRow = new JoinedRowData();
    windowAggResult = new JoinedRowData();
    reusePythonTimerRowData.setField(2, reusePythonTimerData);
    windowAccumulateData = new HashMap<>();
    windowRetractData = new HashMap<>();
    mockPythonInternalService = (InternalTimerServiceImpl<K, TimeWindow>) getInternalTimerService("python-window-timers", windowSerializer, this.mockPythonWindowOperator);
    this.groupKeyProjection = createProjection("GroupKey", grouping);
    int inputFieldIndex = (int) aggregateFunction.getInputs()[0];
    this.aggExtracter = input -> {
        GenericRowData aggResult = new GenericRowData(1);
        aggResult.setField(0, input.getLong(inputFieldIndex));
        return aggResult;
    };
    this.windowExtractor = window -> {
        GenericRowData windowProperty = new GenericRowData(namedProperties.length);
        for (int i = 0; i < namedProperties.length; i++) {
            switch(namedProperties[i]) {
                case WINDOW_START:
                    windowProperty.setField(i, getShiftEpochMills(window.getStart()));
                    break;
                case WINDOW_END:
                    windowProperty.setField(i, getShiftEpochMills(window.getEnd()));
                    break;
                case ROW_TIME_ATTRIBUTE:
                    windowProperty.setField(i, getShiftEpochMills(window.getEnd() - 1));
                    break;
                case PROC_TIME_ATTRIBUTE:
                    windowProperty.setField(i, -1L);
            }
        }
        return windowProperty;
    };
}
Also used : DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) GenericRowData(org.apache.flink.table.data.GenericRowData) UpdatableRowData(org.apache.flink.table.data.UpdatableRowData) ByteArrayOutputStreamWithPos(org.apache.flink.core.memory.ByteArrayOutputStreamWithPos) TimeWindow(org.apache.flink.table.runtime.operators.window.TimeWindow)

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