Search in sources :

Example 61 with DataOutputSerializer

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

the class FileSourceSplitSerializer method serialize.

@Override
public byte[] serialize(FileSourceSplit split) throws IOException {
    checkArgument(split.getClass() == FileSourceSplit.class, "Cannot serialize subclasses of FileSourceSplit");
    // optimization: the splits lazily cache their own serialized form
    if (split.serializedFormCache != null) {
        return split.serializedFormCache;
    }
    final DataOutputSerializer out = SERIALIZER_CACHE.get();
    out.writeUTF(split.splitId());
    split.path().write(out);
    out.writeLong(split.offset());
    out.writeLong(split.length());
    out.writeLong(split.fileModificationTime());
    out.writeLong(split.fileSize());
    writeStringArray(out, split.hostnames());
    final Optional<CheckpointedPosition> readerPosition = split.getReaderPosition();
    out.writeBoolean(readerPosition.isPresent());
    if (readerPosition.isPresent()) {
        out.writeLong(readerPosition.get().getOffset());
        out.writeLong(readerPosition.get().getRecordsAfterOffset());
    }
    final byte[] result = out.getCopyOfBuffer();
    out.clear();
    // optimization: cache the serialized from, so we avoid the byte work during repeated
    // serialization
    split.serializedFormCache = result;
    return result;
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) CheckpointedPosition(org.apache.flink.connector.file.src.util.CheckpointedPosition)

Example 62 with DataOutputSerializer

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

the class TestManagedSinkCommittableSerializer method serialize.

@Override
public byte[] serialize(TestManagedCommittable committable) throws IOException {
    final DataOutputSerializer out = new DataOutputSerializer(64);
    out.writeInt(committable.getToAdd().size());
    for (Map.Entry<CatalogPartitionSpec, List<RowData>> entry : committable.getToAdd().entrySet()) {
        serializePartitionSpec(out, entry.getKey());
        serializeRowDataElements(out, entry.getValue());
    }
    out.writeInt(committable.getToDelete().size());
    for (Map.Entry<CatalogPartitionSpec, Set<Path>> entry : committable.getToDelete().entrySet()) {
        serializePartitionSpec(out, entry.getKey());
        serializePaths(out, entry.getValue());
    }
    final byte[] result = out.getCopyOfBuffer();
    out.clear();
    return result;
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec)

Example 63 with DataOutputSerializer

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

the class RawFormatSerDeSchemaTest method serializeLocalDateTime.

private static byte[] serializeLocalDateTime(LocalDateTime localDateTime) {
    DataOutputSerializer dos = new DataOutputSerializer(16);
    LocalDateTimeSerializer serializer = new LocalDateTimeSerializer();
    try {
        serializer.serialize(localDateTime, dos);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return dos.getCopyOfBuffer();
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) IOException(java.io.IOException) LocalDateTimeSerializer(org.apache.flink.api.common.typeutils.base.LocalDateTimeSerializer)

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