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());
}
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());
}
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);
}
}
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);
}
}
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));
}
Aggregations