Search in sources :

Example 11 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer in project flink by apache.

the class CompositeTypeSerializerSnapshotTest method testRestoreCompositeTypeSerializer.

// ------------------------------------------------------------------------------------------------
// Scope: tests CompositeTypeSerializerSnapshot#restoreSerializer
// ------------------------------------------------------------------------------------------------
@Test
public void testRestoreCompositeTypeSerializer() throws IOException {
    // the target compatibilities of the nested serializers doesn't matter,
    // because we're only testing the restore serializer
    TypeSerializer<?>[] testNestedSerializers = { new NestedSerializer(TargetCompatibility.COMPATIBLE_AS_IS), new NestedSerializer(TargetCompatibility.INCOMPATIBLE), new NestedSerializer(TargetCompatibility.COMPATIBLE_AFTER_MIGRATION) };
    TestCompositeTypeSerializer testSerializer = new TestCompositeTypeSerializer(testNestedSerializers);
    TypeSerializerSnapshot<String> testSerializerSnapshot = testSerializer.snapshotConfiguration();
    DataOutputSerializer out = new DataOutputSerializer(128);
    TypeSerializerSnapshot.writeVersionedSnapshot(out, testSerializerSnapshot);
    DataInputDeserializer in = new DataInputDeserializer(out.getCopyOfBuffer());
    testSerializerSnapshot = TypeSerializerSnapshot.readVersionedSnapshot(in, Thread.currentThread().getContextClassLoader());
    // now, restore the composite type serializer;
    // the restored nested serializer should be a RestoredNestedSerializer
    testSerializer = (TestCompositeTypeSerializer) testSerializerSnapshot.restoreSerializer();
    Assert.assertTrue(testSerializer.getNestedSerializers()[0].getClass() == RestoredNestedSerializer.class);
    Assert.assertTrue(testSerializer.getNestedSerializers()[1].getClass() == RestoredNestedSerializer.class);
    Assert.assertTrue(testSerializer.getNestedSerializers()[2].getClass() == RestoredNestedSerializer.class);
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) DataInputDeserializer(org.apache.flink.core.memory.DataInputDeserializer) Test(org.junit.Test)

Example 12 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer in project flink by apache.

the class SerializableHadoopConfigWrapper method writeObject.

// ------------------------------------------------------------------------
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();
    // we write the Hadoop config through a separate serializer to avoid cryptic exceptions when
    // it
    // corrupts the serialization stream
    final DataOutputSerializer ser = new DataOutputSerializer(256);
    hadoopConfig.write(ser);
    out.writeInt(ser.length());
    out.write(ser.getSharedBuffer(), 0, ser.length());
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer)

Example 13 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer in project flink by apache.

the class TypeInformationSerializationSchema method serialize.

@Override
public byte[] serialize(T element) {
    if (dos == null) {
        dos = new DataOutputSerializer(16);
    }
    try {
        serializer.serialize(element, dos);
    } catch (IOException e) {
        throw new RuntimeException("Unable to serialize record", e);
    }
    byte[] ret = dos.getCopyOfBuffer();
    dos.clear();
    return ret;
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) IOException(java.io.IOException)

Example 14 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer 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 15 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer 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)

Aggregations

DataOutputSerializer (org.apache.flink.core.memory.DataOutputSerializer)63 DataInputDeserializer (org.apache.flink.core.memory.DataInputDeserializer)15 Test (org.junit.Test)15 IOException (java.io.IOException)10 ByteBuffer (java.nio.ByteBuffer)6 List (java.util.List)4 IntSerializer (org.apache.flink.api.common.typeutils.base.IntSerializer)4 StringSerializer (org.apache.flink.api.common.typeutils.base.StringSerializer)4 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)4 ArrayList (java.util.ArrayList)3 IntStream (java.util.stream.IntStream)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)3 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Function (java.util.function.Function)2 Stream (java.util.stream.Stream)2 ValueState (org.apache.flink.api.common.state.ValueState)2 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)2