use of com.baidu.hugegraph.computer.core.io.RandomAccessInput in project hugegraph-computer by hugegraph.
the class VertexInput method next.
public Vertex next() {
this.readCount++;
try {
this.idPointer.read(this.input);
this.valuePointer.read(this.input);
RandomAccessInput valueInput = this.valuePointer.input();
this.vertex.label(StreamGraphInput.readLabel(valueInput));
this.properties.read(valueInput);
this.vertex.id(StreamGraphInput.readId(this.idPointer.input()));
this.vertex.properties(this.properties);
} catch (IOException e) {
throw new ComputerException("Can't read vertex from input '%s'", e, this.vertexFile.getAbsolutePath());
}
return this.vertex;
}
use of com.baidu.hugegraph.computer.core.io.RandomAccessInput in project hugegraph-computer by hugegraph.
the class AbstractPointerCombiner method combine.
public Pointer combine(Pointer v1, Pointer v2) {
try {
RandomAccessInput input1 = v1.input();
RandomAccessInput input2 = v2.input();
input1.seek(v1.offset());
input2.seek(v2.offset());
this.v1.read(input1);
this.v2.read(input2);
this.combiner.combine(this.v1, this.v2, this.result);
this.output.seek(0L);
this.result.write(this.output);
return new InlinePointer(this.output.buffer(), this.output.position());
} catch (Exception e) {
throw new ComputerException("Failed to combine pointer1(offset=%s, length=%s) and " + "pointer2(offset=%s, length=%s)'", e, v1.offset(), v1.length(), v2.offset(), v2.length());
}
}
use of com.baidu.hugegraph.computer.core.io.RandomAccessInput in project hugegraph-computer by hugegraph.
the class CombineSubKvOuterSortFlusher method flush.
@Override
public void flush(EntryIterator entries, KvEntryFileWriter writer) throws IOException {
E.checkArgument(entries.hasNext(), "Parameter entries can't be empty");
PeekableIterator<KvEntry> kvEntries = PeekableIteratorAdaptor.of(entries);
SubKvSorter sorter = new SubKvSorter(kvEntries, this.sources);
KvEntry currentKv = sorter.currentKv();
while (true) {
currentKv.key().write(this.output);
long position = this.output.position();
// Write total sub-entry length placeholder
this.output.writeFixedInt(0);
// Write sub-entry count placeholder
this.output.writeFixedInt(0);
int writtenCount = 0;
// Iterate subKv of currentKv
KvEntry lastSubKv = sorter.next();
Pointer lastSubValue = lastSubKv.value();
while (true) {
KvEntry current = null;
if (sorter.hasNext()) {
current = sorter.next();
if (lastSubKv.compareTo(current) == 0) {
lastSubValue = this.combiner.combine(lastSubValue, current.value());
continue;
}
}
lastSubKv.key().write(this.output);
lastSubValue.write(this.output);
writtenCount++;
/*
* Fill placeholder if the number of subkvs with different
* keys is equal to the subKvFlushThreshold.
*/
if (current == null || writtenCount == this.subKvFlushThreshold) {
long currentPosition = this.output.position();
this.output.seek(position);
this.output.writeFixedInt((int) (currentPosition - position - Integer.BYTES));
this.output.writeFixedInt(writtenCount);
this.output.seek(currentPosition);
// Write kvEntry to file.
RandomAccessInput input = EntriesUtil.inputFromOutput(this.output);
writer.write(EntriesUtil.kvEntryFromInput(input, true, true));
this.output.seek(0);
if (current == null) {
break;
}
currentKv.key().write(this.output);
position = this.output.position();
// Write value length placeholder
this.output.writeFixedInt(0);
// Write subKv count placeholder
this.output.writeFixedInt(0);
writtenCount = 0;
}
lastSubKv = current;
lastSubValue = lastSubKv.value();
}
sorter.reset();
// Get next KV
if ((currentKv = sorter.currentKv()) == null) {
break;
}
}
writer.finish();
}
Aggregations