Search in sources :

Example 1 with UpdatableRowData

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

the class AbstractPythonStreamGroupAggregateOperator method open.

@Override
public void open() throws Exception {
    // The structure is:  [type]|[normal record]|[timestamp of timer]|[row key]
    // If the type is 'NORMAL_RECORD', store the RowData object in the 2nd column.
    // If the type is 'TRIGGER_TIMER', store the timestamp in 3rd column and the row key
    reuseRowData = new UpdatableRowData(GenericRowData.of(NORMAL_RECORD, null, null, null), 4);
    reuseTimerRowData = new UpdatableRowData(GenericRowData.of(TRIGGER_TIMER, null, null, null), 4);
    timerService = new SimpleTimerService(getInternalTimerService("state-clean-timer", VoidNamespaceSerializer.INSTANCE, this));
    initCleanupTimeState();
    super.open();
}
Also used : SimpleTimerService(org.apache.flink.streaming.api.SimpleTimerService) UpdatableRowData(org.apache.flink.table.data.UpdatableRowData)

Example 2 with UpdatableRowData

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

the class ConstraintEnforcer method processCharConstraint.

private RowData processCharConstraint(RowData rowData) {
    if (typeLengthEnforcer == null || typeLengthEnforcer == TypeLengthEnforcer.IGNORE || charFieldIndices == null) {
        return rowData;
    }
    UpdatableRowData updatedRowData = null;
    for (int i = 0; i < charFieldIndices.length; i++) {
        final int fieldIdx = charFieldIndices[i];
        final int length = charFieldLengths[i];
        final BinaryStringData stringData = (BinaryStringData) rowData.getString(fieldIdx);
        final int sourceStrLength = stringData.numChars();
        if (charFieldCouldPad.get(i) && sourceStrLength < length) {
            if (updatedRowData == null) {
                updatedRowData = new UpdatableRowData(rowData, allFieldNames.length);
            }
            final int srcSizeInBytes = stringData.getSizeInBytes();
            final byte[] newString = new byte[srcSizeInBytes + length - sourceStrLength];
            for (int j = srcSizeInBytes; j < newString.length; j++) {
                // space
                newString[j] = (byte) 32;
            }
            SegmentsUtil.copyToBytes(stringData.getSegments(), 0, newString, 0, srcSizeInBytes);
            updatedRowData.setField(fieldIdx, StringData.fromBytes(newString));
        } else if (sourceStrLength > length) {
            if (updatedRowData == null) {
                updatedRowData = new UpdatableRowData(rowData, allFieldNames.length);
            }
            updatedRowData.setField(fieldIdx, stringData.substring(0, length));
        }
    }
    return updatedRowData != null ? updatedRowData : rowData;
}
Also used : UpdatableRowData(org.apache.flink.table.data.UpdatableRowData) BinaryStringData(org.apache.flink.table.data.binary.BinaryStringData)

Example 3 with UpdatableRowData

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

the class PythonStreamGroupWindowAggregateOperator method open.

@Override
public void open() throws Exception {
    windowSerializer = windowAssigner.getWindowSerializer(new ExecutionConfig());
    internalTimerService = getInternalTimerService("window-timers", windowSerializer, this);
    // The structure is:  [type]|[normal record]|[timestamp]|[current watermark]|[timer data]
    // If the type is 'NORMAL_RECORD', store the RowData object in the 2nd column.
    // If the type is 'TRIGGER_TIMER', store the timestamp in 3rd column and the timer
    // data in 5th column.
    reuseRowData = new UpdatableRowData(GenericRowData.of(NORMAL_RECORD, null, null, null, null), 5);
    reuseTimerRowData = new UpdatableRowData(GenericRowData.of(TRIGGER_TIMER, null, null, null, null), 5);
    // The structure is:  [timer_type]|[row key]|[encoded namespace]
    reuseTimerData = new UpdatableRowData(GenericRowData.of(0, null, 0), 3);
    reuseTimerRowData.setField(4, reuseTimerData);
    keyLength = getKeyType().getFieldCount();
    keySerializer = (RowDataSerializer) getKeySerializer();
    super.open();
}
Also used : ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) UpdatableRowData(org.apache.flink.table.data.UpdatableRowData)

Example 4 with UpdatableRowData

use of org.apache.flink.table.data.UpdatableRowData 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)

Example 5 with UpdatableRowData

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

the class ConstraintEnforcer method processBinaryConstraint.

private RowData processBinaryConstraint(RowData rowData) {
    if (typeLengthEnforcer == null || typeLengthEnforcer == TypeLengthEnforcer.IGNORE || binaryFieldIndices == null) {
        return rowData;
    }
    UpdatableRowData updatedRowData = null;
    for (int i = 0; i < binaryFieldLengths.length; i++) {
        final int fieldIdx = binaryFieldIndices[i];
        final int length = binaryFieldLengths[i];
        final byte[] binaryData = rowData.getBinary(fieldIdx);
        final int sourceLength = binaryData.length;
        // padding because of the longer length, as implicitly the trailing bytes are 0.
        if ((sourceLength > length) || (binaryFieldCouldPad.get(i) && sourceLength < length)) {
            if (updatedRowData == null) {
                updatedRowData = new UpdatableRowData(rowData, allFieldNames.length);
            }
            updatedRowData.setField(fieldIdx, Arrays.copyOf(binaryData, length));
        }
    }
    return updatedRowData != null ? updatedRowData : rowData;
}
Also used : UpdatableRowData(org.apache.flink.table.data.UpdatableRowData)

Aggregations

UpdatableRowData (org.apache.flink.table.data.UpdatableRowData)5 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 ByteArrayOutputStreamWithPos (org.apache.flink.core.memory.ByteArrayOutputStreamWithPos)1 DataOutputViewStreamWrapper (org.apache.flink.core.memory.DataOutputViewStreamWrapper)1 SimpleTimerService (org.apache.flink.streaming.api.SimpleTimerService)1 GenericRowData (org.apache.flink.table.data.GenericRowData)1 BinaryStringData (org.apache.flink.table.data.binary.BinaryStringData)1 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)1 TimeWindow (org.apache.flink.table.runtime.operators.window.TimeWindow)1