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