Search in sources :

Example 1 with CombineKvInnerSortFlusher

use of com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher in project hugegraph-computer by hugegraph.

the class SortManager method createSortFlusher.

private InnerSortFlusher createSortFlusher(MessageType type, RandomAccessOutput output, int flushThreshold) {
    PointerCombiner combiner;
    boolean needSortSubKv;
    switch(type) {
        case VERTEX:
            combiner = new VertexValueCombiner(this.context);
            needSortSubKv = false;
            break;
        case EDGE:
            combiner = new EdgeValueCombiner(this.context);
            needSortSubKv = true;
            break;
        case MSG:
            combiner = this.createMessageCombiner();
            needSortSubKv = false;
            break;
        default:
            throw new ComputerException("Unsupported combine message " + "type for %s", type);
    }
    InnerSortFlusher flusher;
    if (combiner == null) {
        flusher = new KvInnerSortFlusher(output);
    } else {
        if (needSortSubKv) {
            flusher = new CombineSubKvInnerSortFlusher(output, combiner, flushThreshold);
        } else {
            flusher = new CombineKvInnerSortFlusher(output, combiner);
        }
    }
    return flusher;
}
Also used : CombineSubKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineSubKvInnerSortFlusher) KvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.KvInnerSortFlusher) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher) CombineSubKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineSubKvInnerSortFlusher) CombineSubKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineSubKvInnerSortFlusher) 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) EdgeValueCombiner(com.baidu.hugegraph.computer.core.combiner.EdgeValueCombiner) VertexValueCombiner(com.baidu.hugegraph.computer.core.combiner.VertexValueCombiner) PointerCombiner(com.baidu.hugegraph.computer.core.combiner.PointerCombiner) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher)

Example 2 with CombineKvInnerSortFlusher

use of com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher in project hugegraph-computer by hugegraph.

the class SortLargeDataTest method sortBuffer.

private static RandomAccessInput sortBuffer(Sorter sorter, RandomAccessInput input) throws Exception {
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
    InnerSortFlusher flusher = new CombineKvInnerSortFlusher(output, combiner);
    sorter.sortBuffer(input, flusher, false);
    return EntriesUtil.inputFromOutput(output);
}
Also used : IntValueSumCombiner(com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher) InnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.InnerSortFlusher) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) 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)

Example 3 with CombineKvInnerSortFlusher

use of com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher in project hugegraph-computer by hugegraph.

the class SorterTest method testSortKvBuffer.

@Test
public void testSortKvBuffer() throws Exception {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.HGKV_MAX_FILE_SIZE, "32", ComputerOptions.HGKV_DATABLOCK_SIZE, "16", ComputerOptions.HGKV_MERGE_FILES_NUM, "3");
    List<Integer> map = ImmutableList.of(2, 3, 1, 23, 6, 2, 5, 9, 2, 2, 6, 1, 1, 20);
    BytesInput input = SorterTestUtil.inputFromKvMap(map);
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    Sorter sorter = SorterTestUtil.createSorter(config);
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
    sorter.sortBuffer(input, new CombineKvInnerSortFlusher(output, combiner), false);
    BytesInput resultInput = EntriesUtil.inputFromOutput(output);
    KvEntriesInput iter = new KvEntriesInput(resultInput);
    SorterTestUtil.assertKvEntry(iter.next(), 1, 43);
    SorterTestUtil.assertKvEntry(iter.next(), 2, 5);
    SorterTestUtil.assertKvEntry(iter.next(), 5, 9);
    SorterTestUtil.assertKvEntry(iter.next(), 6, 3);
    iter.close();
}
Also used : IntValueSumCombiner(com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) Config(com.baidu.hugegraph.computer.core.config.Config) 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 4 with CombineKvInnerSortFlusher

use of com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher 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)

Aggregations

PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)4 CombineKvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher)4 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)3 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)3 InnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.InnerSortFlusher)3 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)2 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)2 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)2 KvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.KvInnerSortFlusher)2 KvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput)2 Test (org.junit.Test)2 EdgeValueCombiner (com.baidu.hugegraph.computer.core.combiner.EdgeValueCombiner)1 VertexValueCombiner (com.baidu.hugegraph.computer.core.combiner.VertexValueCombiner)1 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)1 Config (com.baidu.hugegraph.computer.core.config.Config)1 CombineSubKvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineSubKvInnerSortFlusher)1