Search in sources :

Example 11 with BytesOutput

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

the class SorterTestUtil method writeSubKvMapToOutput.

public static BytesOutput writeSubKvMapToOutput(List<List<Integer>> data) throws IOException {
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    for (List<Integer> entry : data) {
        Integer key = entry.get(0);
        // Write key
        writeData(output, key);
        // Write subKv
        long position = output.position();
        int count = 0;
        // Write value length placeholder
        output.writeFixedInt(0);
        // Write subKv count placeholder
        output.writeFixedInt(0);
        for (int i = 1; i < entry.size(); ) {
            Integer subKey = entry.get(i++);
            Integer subValue = entry.get(i++);
            writeData(output, subKey);
            writeData(output, subValue);
            count++;
        }
        long currentPosition = output.position();
        output.seek(position);
        output.writeFixedInt((int) (currentPosition - position - 4));
        output.writeFixedInt(count);
        output.seek(currentPosition);
    }
    return output;
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput)

Example 12 with BytesOutput

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

the class EntryOutputTest method inputFromEntries.

private static BytesInput inputFromEntries(List<Integer> entries, boolean needSort) throws IOException {
    /*
         * All integer data will convert to Id type, so upper layer also
         * needs to use the Id type to make a judgment
         */
    List<Id> data = intListToLongIds(entries);
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(output, needSort);
    int index = 0;
    KvEntryWriter entry1 = entryOutput.writeEntry(data.get(index++));
    entry1.writeSubKv(data.get(index++), data.get(index++));
    entry1.writeSubKv(data.get(index++), data.get(index++));
    entry1.writeSubKv(data.get(index++), data.get(index++));
    entry1.writeFinish();
    KvEntryWriter entry2 = entryOutput.writeEntry(data.get(index++));
    entry2.writeSubKv(data.get(index++), data.get(index++));
    entry2.writeSubKv(data.get(index++), data.get(index));
    entry2.writeFinish();
    return EntriesUtil.inputFromOutput(output);
}
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)

Example 13 with BytesOutput

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

the class EntryOutputTest method testWriteKvEntry.

@Test
public void testWriteKvEntry() throws Exception {
    List<Integer> entries = ImmutableList.of(1, 5, 6, 6, 2, 1, 4, 8);
    List<Id> data = intListToLongIds(entries);
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(output);
    for (int i = 0; i < data.size(); ) {
        Id id = data.get(i++);
        Writable value = data.get(i++);
        entryOutput.writeEntry(id, value);
    }
    // Assert result
    BytesInput input = EntriesUtil.inputFromOutput(output);
    EntryIterator iter = new KvEntriesInput(input);
    SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(1), BytesId.of(5));
    SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(6), BytesId.of(6));
    SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(2), BytesId.of(1));
    SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(4), BytesId.of(8));
    iter.close();
}
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) Writable(com.baidu.hugegraph.computer.core.io.Writable) KvEntriesInput(com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Example 14 with BytesOutput

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

the class ComputeManagerTest method writeEdges.

private static byte[] writeEdges(Vertex vertex, EdgeFrequency freq) throws IOException {
    BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
    GraphComputeOutput output = new StreamGraphOutput(context(), entryOutput);
    Whitebox.setInternalState(output, "frequency", freq);
    output.writeEdges(vertex);
    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) StreamGraphOutput(com.baidu.hugegraph.computer.core.io.StreamGraphOutput) GraphComputeOutput(com.baidu.hugegraph.computer.core.io.GraphComputeOutput)

Example 15 with BytesOutput

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

the class EdgesInputTest method writeEdges.

private static byte[] writeEdges(Vertex vertex, EdgeFrequency freq) throws IOException {
    BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
    GraphComputeOutput output = new StreamGraphOutput(context(), entryOutput);
    Whitebox.setInternalState(output, "frequency", freq);
    output.writeEdges(vertex);
    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) StreamGraphOutput(com.baidu.hugegraph.computer.core.io.StreamGraphOutput) GraphComputeOutput(com.baidu.hugegraph.computer.core.io.GraphComputeOutput)

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