use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.
the class StoreTestUtil method hgkvDirFromSubKvMap.
public static void hgkvDirFromSubKvMap(Config config, List<List<Integer>> map, String path) throws IOException {
BytesInput input = SorterTestUtil.inputFromSubKvMap(map);
KvEntriesInput iter = new KvEntriesInput(input, true);
try (KvEntryFileWriter builder = new HgkvDirBuilderImpl(config, path)) {
while (iter.hasNext()) {
builder.write(iter.next());
}
}
iter.close();
}
use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.
the class UnitTestBase method assertIdEqualAfterWriteAndRead.
public static void assertIdEqualAfterWriteAndRead(Id oldId) throws IOException {
byte[] bytes;
try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
oldId.write(bao);
bytes = bao.toByteArray();
}
Id newId = IdFactory.createId(oldId.idType());
try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
newId.read(bai);
Assert.assertEquals(oldId, newId);
}
}
use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.
the class KvEntryWriterImpl method sortAndWriteSubKvs.
private void sortAndWriteSubKvs() throws IOException {
BytesInput input = EntriesUtil.inputFromOutput(this.subKvBuffer);
InputSorter sorter = new JavaInputSorter();
Iterator<KvEntry> subKvs = sorter.sort(new KvEntriesInput(input));
while (subKvs.hasNext()) {
KvEntry subKv = subKvs.next();
subKv.key().write(this.output);
subKv.value().write(this.output);
}
}
use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.
the class SorterTest method sortedSubKvBuffer.
private BytesInput sortedSubKvBuffer(Config config) throws Exception {
List<Integer> kv1 = ImmutableList.of(3, 2, 1, 4, 1);
List<Integer> kv2 = ImmutableList.of(1, 3, 1, 5, 1);
List<Integer> kv3 = ImmutableList.of(2, 8, 1, 9, 1);
List<Integer> kv4 = ImmutableList.of(3, 2, 1, 3, 1);
List<Integer> kv5 = ImmutableList.of(2, 5, 1, 8, 1);
List<List<Integer>> data = ImmutableList.of(kv1, kv2, kv3, kv4, kv5);
BytesInput input = SorterTestUtil.inputFromSubKvMap(data);
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
int flushThreshold = config.get(ComputerOptions.INPUT_MAX_EDGES_IN_ONE_VERTEX);
InnerSortFlusher flusher = new CombineSubKvInnerSortFlusher(output, combiner, flushThreshold);
Sorter sorter = SorterTestUtil.createSorter(config);
sorter.sortBuffer(input, flusher, true);
return EntriesUtil.inputFromOutput(output);
}
use of com.baidu.hugegraph.computer.core.io.BytesInput 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