Search in sources :

Example 11 with BytesInput

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

the class FlusherTest method testKvInnerSortFlusher.

@Test
public void testKvInnerSortFlusher() throws Exception {
    List<Integer> map = ImmutableList.of(2, 1, 3, 1, 2, 1, 4, 1);
    BytesInput input = SorterTestUtil.inputFromKvMap(map);
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    Sorter sorter = SorterTestUtil.createSorter(CONFIG);
    sorter.sortBuffer(input, new KvInnerSortFlusher(output), false);
    BytesInput result = EntriesUtil.inputFromOutput(output);
    EntryIterator iter = new KvEntriesInput(result);
    SorterTestUtil.assertKvEntry(iter.next(), 2, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 2, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 3, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 4, 1);
    iter.close();
}
Also used : KvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.KvInnerSortFlusher) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) Sorter(com.baidu.hugegraph.computer.core.sort.Sorter) KvEntriesInput(com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput) EntryIterator(com.baidu.hugegraph.computer.core.store.EntryIterator) Test(org.junit.Test)

Example 12 with BytesInput

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

the class FlusherTest method testOverwriteCombiner.

@Test
public void testOverwriteCombiner() throws Exception {
    List<Integer> data = ImmutableList.of(1, 2, 3, 5, 1, 3, 1, 1, 3, 4);
    BytesInput input = SorterTestUtil.inputFromKvMap(data);
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new OverwriteCombiner<>());
    InnerSortFlusher flusher = new CombineKvInnerSortFlusher(output, combiner);
    Sorter sorter = SorterTestUtil.createSorter(CONFIG);
    sorter.sortBuffer(input, flusher, false);
    BytesInput result = EntriesUtil.inputFromOutput(output);
    // Assert result
    KvEntriesInput iter = new KvEntriesInput(result);
    SorterTestUtil.assertKvEntry(iter.next(), 1, 1);
    SorterTestUtil.assertKvEntry(iter.next(), 3, 4);
    iter.close();
}
Also used : KvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.KvInnerSortFlusher) 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) Sorter(com.baidu.hugegraph.computer.core.sort.Sorter) KvEntriesInput(com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput) PointerCombiner(com.baidu.hugegraph.computer.core.combiner.PointerCombiner) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher) Test(org.junit.Test)

Example 13 with BytesInput

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

the class SorterTestUtil method assertOutputEqualsMap.

public static void assertOutputEqualsMap(BytesOutput output, Map<Integer, List<Integer>> map) throws IOException {
    byte[] buffer = output.buffer();
    BytesInput input = IOFactory.createBytesInput(buffer);
    for (Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
        input.readInt();
        int key = input.readInt();
        Assert.assertEquals(entry.getKey().intValue(), key);
        int valueLength = input.readFixedInt();
        int valueCount = valueLength / Integer.BYTES;
        List<Integer> values = new ArrayList<>();
        for (int i = 0; i < valueCount; i++) {
            values.add(input.readInt());
        }
        Assert.assertEquals(entry.getValue(), values);
    }
}
Also used : BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 14 with BytesInput

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

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

the class EntryOutputTest method testSubKvNotNeedSort.

@Test
public void testSubKvNotNeedSort() throws Exception {
    List<Integer> entries = ImmutableList.of(5, 6, 6, 2, 1, 4, 8, 1, 2, 2, 6, 1);
    BytesInput input = inputFromEntries(entries, false);
    EntryIterator iter = new KvEntriesInput(input, true);
    // Assert entry1
    KvEntry kvEntry1 = iter.next();
    Assert.assertEquals(3, kvEntry1.numSubEntries());
    Id key1 = StoreTestUtil.idFromPointer(kvEntry1.key());
    Assert.assertEquals(BytesId.of(5), key1);
    EntryIterator kvEntry1SubKvs = EntriesUtil.subKvIterFromEntry(kvEntry1);
    KvEntry subKv1 = kvEntry1SubKvs.next();
    Assert.assertEquals(0, subKv1.numSubEntries());
    SorterTestUtil.assertKvEntry(subKv1, BytesId.of(6), BytesId.of(6));
    SorterTestUtil.assertKvEntry(kvEntry1SubKvs.next(), BytesId.of(2), BytesId.of(1));
    SorterTestUtil.assertKvEntry(kvEntry1SubKvs.next(), BytesId.of(4), BytesId.of(8));
    // Assert entry2
    KvEntry kvEntry2 = iter.next();
    Id key2 = StoreTestUtil.idFromPointer(kvEntry2.key());
    Assert.assertEquals(BytesId.of(1), key2);
    EntryIterator kvEntry2SubKvs = EntriesUtil.subKvIterFromEntry(kvEntry2);
    SorterTestUtil.assertKvEntry(kvEntry2SubKvs.next(), BytesId.of(2), BytesId.of(2));
    SorterTestUtil.assertKvEntry(kvEntry2SubKvs.next(), BytesId.of(6), BytesId.of(1));
    iter.close();
}
Also used : BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) 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)

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