Search in sources :

Example 21 with BytesInput

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

the class StoreTestUtil method hgkvDirFromSubKvMap.

public static void hgkvDirFromSubKvMap(Config config, List<List<Integer>> map, String path) throws IOException {
    BytesInput input = SorterTestUtil.inputFromSubKvMap(map);
    KvEntriesInput iter = new KvEntriesInput(input, true);
    try (KvEntryFileWriter builder = new HgkvDirBuilderImpl(config, path)) {
        while (iter.hasNext()) {
            builder.write(iter.next());
        }
    }
    iter.close();
}
Also used : BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) KvEntriesInput(com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput) HgkvDirBuilderImpl(com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvDirBuilderImpl)

Example 22 with BytesInput

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

the class UnitTestBase method assertIdEqualAfterWriteAndRead.

public static void assertIdEqualAfterWriteAndRead(Id oldId) throws IOException {
    byte[] bytes;
    try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        oldId.write(bao);
        bytes = bao.toByteArray();
    }
    Id newId = IdFactory.createId(oldId.idType());
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        newId.read(bai);
        Assert.assertEquals(oldId, newId);
    }
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) Id(com.baidu.hugegraph.computer.core.graph.id.Id)

Example 23 with BytesInput

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

the class KvEntryWriterImpl method sortAndWriteSubKvs.

private void sortAndWriteSubKvs() throws IOException {
    BytesInput input = EntriesUtil.inputFromOutput(this.subKvBuffer);
    InputSorter sorter = new JavaInputSorter();
    Iterator<KvEntry> subKvs = sorter.sort(new KvEntriesInput(input));
    while (subKvs.hasNext()) {
        KvEntry subKv = subKvs.next();
        subKv.key().write(this.output);
        subKv.value().write(this.output);
    }
}
Also used : JavaInputSorter(com.baidu.hugegraph.computer.core.sort.sorter.JavaInputSorter) InputSorter(com.baidu.hugegraph.computer.core.sort.sorter.InputSorter) JavaInputSorter(com.baidu.hugegraph.computer.core.sort.sorter.JavaInputSorter) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) KvEntriesInput(com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput)

Example 24 with BytesInput

use of com.baidu.hugegraph.computer.core.io.BytesInput 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 25 with BytesInput

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

the class FlusherTest method testKvOuterSortFlusher.

@Test
public void testKvOuterSortFlusher() throws Exception {
    List<Integer> map1 = ImmutableList.of(2, 1, 2, 1, 3, 1, 4, 1);
    List<Integer> map2 = ImmutableList.of(1, 1, 3, 1, 6, 1);
    BytesInput input1 = SorterTestUtil.inputFromKvMap(map1);
    BytesInput input2 = SorterTestUtil.inputFromKvMap(map2);
    List<RandomAccessInput> inputs = ImmutableList.of(input1, input2);
    String resultFile = StoreTestUtil.availablePathById("1");
    Sorter sorter = SorterTestUtil.createSorter(CONFIG);
    sorter.mergeBuffers(inputs, new KvOuterSortFlusher(), resultFile, false);
    ImmutableList<String> outputs = ImmutableList.of(resultFile);
    Iterator<KvEntry> iter = sorter.iterator(outputs, false);
    SorterTestUtil.assertKvEntry(iter.next(), 1, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 2, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 2, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 3, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 3, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 4, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 6, 1);
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) KvOuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.KvOuterSortFlusher) Sorter(com.baidu.hugegraph.computer.core.sort.Sorter) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) Test(org.junit.Test)

Aggregations

BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)32 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)16 Test (org.junit.Test)16 KvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput)10 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)8 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)7 Config (com.baidu.hugegraph.computer.core.config.Config)5 Id (com.baidu.hugegraph.computer.core.graph.id.Id)5 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)4 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)4 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)4 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)4 CombineKvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)3 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)3 EntryOutput (com.baidu.hugegraph.computer.core.store.entry.EntryOutput)3 EntryOutputImpl (com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl)3 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)3