Search in sources :

Example 6 with EntryIterator

use of com.baidu.hugegraph.computer.core.store.EntryIterator in project hugegraph-computer by hugegraph.

the class EdgeMessageRecvPartitionTest method checkTenEdgesWithCombinedProperties.

private static void checkTenEdgesWithCombinedProperties(Iterator<KvEntry> it) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        Assert.assertTrue(it.hasNext());
        KvEntry entry = it.next();
        Id id = ReceiverUtil.readId(entry.key());
        Assert.assertEquals(BytesId.of(i), id);
        EntryIterator subKvIt = EntriesUtil.subKvIterFromEntry(entry);
        for (long j = i + 1; j < i + 3; j++) {
            Assert.assertTrue(subKvIt.hasNext());
            KvEntry subKv = subKvIt.next();
            Id targetId = ReceiverUtil.readId(subKv.key());
            Assert.assertEquals(BytesId.of(j), targetId);
            Properties properties = graphFactory().createProperties();
            ReceiverUtil.readValue(subKv.value(), properties);
            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);
        }
    }
    Assert.assertFalse(it.hasNext());
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) EntryIterator(com.baidu.hugegraph.computer.core.store.EntryIterator) 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 7 with EntryIterator

use of com.baidu.hugegraph.computer.core.store.EntryIterator in project hugegraph-computer by hugegraph.

the class EdgeMessageRecvPartitionTest method checkTenEdges.

public static void checkTenEdges(PeekableIterator<KvEntry> it) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        Assert.assertTrue(it.hasNext());
        KvEntry entry = it.next();
        Id id = ReceiverUtil.readId(entry.key());
        Assert.assertEquals(BytesId.of(i), id);
        EntryIterator subKvIt = EntriesUtil.subKvIterFromEntry(entry);
        for (long j = i + 1; j < i + 3; j++) {
            Assert.assertTrue(subKvIt.hasNext());
            KvEntry subKv = subKvIt.next();
            Id targetId = ReceiverUtil.readId(subKv.key());
            Assert.assertEquals(BytesId.of(j), targetId);
            Properties properties = graphFactory().createProperties();
            ReceiverUtil.readValue(subKv.value(), properties);
            Assert.assertEquals(1, properties.size());
            LongValue v1 = properties.get("p1");
            Assert.assertEquals(new LongValue(i), v1);
        }
    }
    Assert.assertFalse(it.hasNext());
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) EntryIterator(com.baidu.hugegraph.computer.core.store.EntryIterator) 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 8 with EntryIterator

use of com.baidu.hugegraph.computer.core.store.EntryIterator in project hugegraph-computer by hugegraph.

the class FileGraphPartition method writeEdges.

private void writeEdges(Pointer vid, PeekableIterator<KvEntry> edges, BufferedFileOutput edgeOut) throws IOException {
    byte[] vidBytes = vid.bytes();
    while (edges.hasNext()) {
        KvEntry entry = edges.peek();
        Pointer key = entry.key();
        int matched = vid.compareTo(key);
        if (matched < 0) {
            return;
        }
        edges.next();
        if (matched > 0) {
            // Skip stale edges
            continue;
        }
        assert matched == 0;
        edgeOut.writeFixedInt(vidBytes.length);
        edgeOut.write(vidBytes);
        long valuePosition = edgeOut.position();
        edgeOut.writeFixedInt(0);
        this.edgeCount += entry.numSubEntries();
        edgeOut.writeFixedInt((int) entry.numSubEntries());
        EntryIterator subKvIt = EntriesUtil.subKvIterFromEntry(entry);
        while (subKvIt.hasNext()) {
            KvEntry subEntry = subKvIt.next();
            // Not write sub-key length
            edgeOut.write(subEntry.key().bytes());
            // Not write sub-value length
            edgeOut.write(subEntry.value().bytes());
        }
        long valueLength = edgeOut.position() - valuePosition - Constants.INT_LEN;
        edgeOut.writeFixedInt(valuePosition, (int) valueLength);
    }
}
Also used : KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) EntryIterator(com.baidu.hugegraph.computer.core.store.EntryIterator)

Example 9 with EntryIterator

use of com.baidu.hugegraph.computer.core.store.EntryIterator in project hugegraph-computer by hugegraph.

the class FileMergerImpl method mergeInputs.

private void mergeInputs(List<String> inputs, Function<String, EntryIterator> inputToIter, OuterSortFlusher flusher, String output, Function<String, KvEntryFileWriter> fileToWriter) throws Exception {
    /*
         * File value format is different, upper layer is required to
         * provide the file reading mode
         */
    List<EntryIterator> entries = inputs.stream().map(inputToIter).collect(Collectors.toList());
    InputsSorter sorter = new InputsSorterImpl();
    // Merge inputs and write to output
    try (EntryIterator sortedKv = sorter.sort(entries);
        KvEntryFileWriter builder = fileToWriter.apply(output)) {
        flusher.flush(sortedKv, builder);
    }
}
Also used : InputsSorterImpl(com.baidu.hugegraph.computer.core.sort.sorter.InputsSorterImpl) EntryIterator(com.baidu.hugegraph.computer.core.store.EntryIterator) InputsSorter(com.baidu.hugegraph.computer.core.sort.sorter.InputsSorter) KvEntryFileWriter(com.baidu.hugegraph.computer.core.store.KvEntryFileWriter)

Example 10 with EntryIterator

use of com.baidu.hugegraph.computer.core.store.EntryIterator in project hugegraph-computer by hugegraph.

the class DefaultSorter method iterator.

public PeekableIterator<KvEntry> iterator(List<String> inputs, Function<String, EntryIterator> fileToEntries) throws IOException {
    List<EntryIterator> entries = inputs.stream().map(fileToEntries).collect(Collectors.toList());
    InputsSorterImpl sorter = new InputsSorterImpl();
    return PeekableIteratorAdaptor.of(sorter.sort(entries));
}
Also used : InputsSorterImpl(com.baidu.hugegraph.computer.core.sort.sorter.InputsSorterImpl) EntryIterator(com.baidu.hugegraph.computer.core.store.EntryIterator)

Aggregations

EntryIterator (com.baidu.hugegraph.computer.core.store.EntryIterator)11 InputsSorterImpl (com.baidu.hugegraph.computer.core.sort.sorter.InputsSorterImpl)3 KvEntryFileWriter (com.baidu.hugegraph.computer.core.store.KvEntryFileWriter)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)3 Test (org.junit.Test)3 Config (com.baidu.hugegraph.computer.core.config.Config)2 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)2 Id (com.baidu.hugegraph.computer.core.graph.id.Id)2 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)2 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)2 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)2 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)2 InputsSorter (com.baidu.hugegraph.computer.core.sort.sorter.InputsSorter)2 KvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput)2 HgkvDirReaderImpl (com.baidu.hugegraph.computer.core.store.file.hgkvfile.reader.HgkvDirReaderImpl)2 DisperseEvenlySelector (com.baidu.hugegraph.computer.core.store.file.select.DisperseEvenlySelector)2 InputFilesSelector (com.baidu.hugegraph.computer.core.store.file.select.InputFilesSelector)2 SelectedFiles (com.baidu.hugegraph.computer.core.store.file.select.SelectedFiles)2 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)1 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)1