Search in sources :

Example 11 with RandomAccessInput

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

the class HgkvFileImpl method readFooter.

private void readFooter() throws IOException {
    File file = new File(this.path);
    // The footerLength occupied 4 bytes, versionLength 2 * 2 bytes
    long versionOffset = file.length() - Short.BYTES * 2 - Integer.BYTES;
    try (RandomAccessInput input = IOFactory.createFileInput(file)) {
        input.seek(versionOffset);
        // Read version
        short majorVersion = input.readShort();
        short minorVersion = input.readShort();
        String version = version(majorVersion, minorVersion);
        // Read footerLength
        int footerLength = input.readFixedInt();
        switch(version) {
            case "1.0":
                this.readFooterV1d0(input, file.length() - footerLength);
                break;
            default:
                throw new ComputerException("Illegal HgkvFile version '%s'", version);
        }
    }
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) File(java.io.File) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 12 with RandomAccessInput

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

the class ReceiverUtil method readValue.

public static void readValue(Pointer pointer, Readable value) throws IOException {
    RandomAccessInput input = pointer.input();
    long position = input.position();
    input.seek(pointer.offset());
    value.read(input);
    input.seek(position);
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput)

Example 13 with RandomAccessInput

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

the class ReceiverUtil method readId.

public static Id readId(Pointer pointer) throws IOException {
    RandomAccessInput input = pointer.input();
    input.seek(pointer.offset());
    return StreamGraphInput.readId(input);
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput)

Example 14 with RandomAccessInput

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

the class VertexMessageRecvPartitionTest method checkTenVertexWithMergedProperties.

private static void checkTenVertexWithMergedProperties(PeekableIterator<KvEntry> it) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        // Assert key
        Assert.assertTrue(it.hasNext());
        KvEntry entry = it.next();
        Id id = ReceiverUtil.readId(entry.key());
        Assert.assertEquals(BytesId.of(i), id);
        // Assert value
        Pointer value = entry.value();
        RandomAccessInput input = value.input();
        long position = input.position();
        input.seek(value.offset());
        String label = StreamGraphInput.readLabel(input);
        Assert.assertEquals("", label);
        Properties properties = graphFactory().createProperties();
        properties.read(input);
        input.seek(position);
        Assert.assertEquals(2, properties.size());
        LongValue v1 = properties.get("p1");
        Assert.assertEquals(new LongValue(i), v1);
        LongValue v2 = properties.get("p2");
        Assert.assertEquals(new LongValue(2L * i), v2);
    }
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties)

Example 15 with RandomAccessInput

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

RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)18 Test (org.junit.Test)7 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)6 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)6 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)4 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)4 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)3 CombineKvOuterSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvOuterSortFlusher)3 ArrayList (java.util.ArrayList)3 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)2 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)2 Config (com.baidu.hugegraph.computer.core.config.Config)2 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)2 KvOuterSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.KvOuterSortFlusher)2 SubKvSorter (com.baidu.hugegraph.computer.core.sort.sorter.SubKvSorter)2 InlinePointer (com.baidu.hugegraph.computer.core.store.entry.InlinePointer)2 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)2 File (java.io.File)2 IOException (java.io.IOException)2 Random (java.util.Random)2