Search in sources :

Example 26 with BytesOutput

use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.

the class EdgeMessageRecvPartitionTest method writeEdges.

private static byte[] writeEdges(Vertex vertex) throws IOException {
    BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
    Id id = vertex.id();
    KvEntryWriter subKvWriter = entryOutput.writeEntry(out -> {
        id.write(out);
    });
    for (Edge edge : vertex.edges()) {
        Id targetId = edge.targetId();
        subKvWriter.writeSubKv(out -> {
            targetId.write(out);
        }, out -> {
            edge.properties().write(out);
        });
    }
    subKvWriter.writeFinish();
    return bytesOutput.toByteArray();
}
Also used : EntryOutput(com.baidu.hugegraph.computer.core.store.entry.EntryOutput) EntryOutputImpl(com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) KvEntryWriter(com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 27 with BytesOutput

use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.

the class VertexMessageRecvPartitionTest method writeVertex.

private static byte[] writeVertex(Vertex vertex) throws IOException {
    BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
    entryOutput.writeEntry(out -> {
        vertex.id().write(out);
    }, out -> {
        out.writeUTF(vertex.label());
        vertex.properties().write(out);
    });
    return bytesOutput.toByteArray();
}
Also used : EntryOutput(com.baidu.hugegraph.computer.core.store.entry.EntryOutput) EntryOutputImpl(com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput)

Example 28 with BytesOutput

use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.

the class SorterTest method sortedSubKvBuffer.

private BytesInput sortedSubKvBuffer(Config config) throws Exception {
    List<Integer> kv1 = ImmutableList.of(3, 2, 1, 4, 1);
    List<Integer> kv2 = ImmutableList.of(1, 3, 1, 5, 1);
    List<Integer> kv3 = ImmutableList.of(2, 8, 1, 9, 1);
    List<Integer> kv4 = ImmutableList.of(3, 2, 1, 3, 1);
    List<Integer> kv5 = ImmutableList.of(2, 5, 1, 8, 1);
    List<List<Integer>> data = ImmutableList.of(kv1, kv2, kv3, kv4, kv5);
    BytesInput input = SorterTestUtil.inputFromSubKvMap(data);
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
    int flushThreshold = config.get(ComputerOptions.INPUT_MAX_EDGES_IN_ONE_VERTEX);
    InnerSortFlusher flusher = new CombineSubKvInnerSortFlusher(output, combiner, flushThreshold);
    Sorter sorter = SorterTestUtil.createSorter(config);
    sorter.sortBuffer(input, flusher, true);
    return EntriesUtil.inputFromOutput(output);
}
Also used : IntValueSumCombiner(com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner) CombineSubKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineSubKvInnerSortFlusher) CombineSubKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineSubKvInnerSortFlusher) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher) InnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.InnerSortFlusher) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) PointerCombiner(com.baidu.hugegraph.computer.core.combiner.PointerCombiner) Sorter(com.baidu.hugegraph.computer.core.sort.Sorter) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 29 with BytesOutput

use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.

the class SorterTestUtil method writeKvMapToOutput.

public static BytesOutput writeKvMapToOutput(List<Integer> map) throws IOException {
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    for (int i = 0; i < map.size(); ) {
        writeData(output, map.get(i++));
        writeData(output, map.get(i++));
    }
    return output;
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput)

Example 30 with BytesOutput

use of com.baidu.hugegraph.computer.core.io.BytesOutput in project hugegraph-computer by hugegraph.

the class EntriesUtilTest method testKvEntryWithFirstSubKv.

@Test
public void testKvEntryWithFirstSubKv() throws IOException {
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(output);
    KvEntryWriter subKvWriter = entryOutput.writeEntry(BytesId.of(100));
    subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
    subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
    subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
    subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
    subKvWriter.writeFinish();
    BytesInput input = EntriesUtil.inputFromOutput(output);
    // Read entry from buffer
    KvEntry entry = EntriesUtil.kvEntryFromInput(input, true, true);
    entry = EntriesUtil.kvEntryWithFirstSubKv(entry);
    // Assert subKvEntry size
    Assert.assertEquals(4, entry.numSubEntries());
}
Also used : EntryOutput(com.baidu.hugegraph.computer.core.store.entry.EntryOutput) EntryOutputImpl(com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) KvEntryWriter(com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) Test(org.junit.Test)

Aggregations

BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)36 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)16 Test (org.junit.Test)16 EntryOutput (com.baidu.hugegraph.computer.core.store.entry.EntryOutput)11 EntryOutputImpl (com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl)11 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)7 CombineKvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher)7 InnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.InnerSortFlusher)5 KvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput)5 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)5 ArrayList (java.util.ArrayList)5 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)4 Config (com.baidu.hugegraph.computer.core.config.Config)4 Id (com.baidu.hugegraph.computer.core.graph.id.Id)4 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)4 GraphComputeOutput (com.baidu.hugegraph.computer.core.io.GraphComputeOutput)4 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)4 StreamGraphOutput (com.baidu.hugegraph.computer.core.io.StreamGraphOutput)4 KvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.KvInnerSortFlusher)4 KvEntryWriter (com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter)4