use of com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl in project hugegraph-computer by hugegraph.
the class EntryOutputTest method inputFromEntries.
private static BytesInput inputFromEntries(List<Integer> entries, boolean needSort) throws IOException {
/*
* All integer data will convert to Id type, so upper layer also
* needs to use the Id type to make a judgment
*/
List<Id> data = intListToLongIds(entries);
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(output, needSort);
int index = 0;
KvEntryWriter entry1 = entryOutput.writeEntry(data.get(index++));
entry1.writeSubKv(data.get(index++), data.get(index++));
entry1.writeSubKv(data.get(index++), data.get(index++));
entry1.writeSubKv(data.get(index++), data.get(index++));
entry1.writeFinish();
KvEntryWriter entry2 = entryOutput.writeEntry(data.get(index++));
entry2.writeSubKv(data.get(index++), data.get(index++));
entry2.writeSubKv(data.get(index++), data.get(index));
entry2.writeFinish();
return EntriesUtil.inputFromOutput(output);
}
use of com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl in project hugegraph-computer by hugegraph.
the class EntryOutputTest method testWriteKvEntry.
@Test
public void testWriteKvEntry() throws Exception {
List<Integer> entries = ImmutableList.of(1, 5, 6, 6, 2, 1, 4, 8);
List<Id> data = intListToLongIds(entries);
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(output);
for (int i = 0; i < data.size(); ) {
Id id = data.get(i++);
Writable value = data.get(i++);
entryOutput.writeEntry(id, value);
}
// Assert result
BytesInput input = EntriesUtil.inputFromOutput(output);
EntryIterator iter = new KvEntriesInput(input);
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(1), BytesId.of(5));
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(6), BytesId.of(6));
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(2), BytesId.of(1));
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(4), BytesId.of(8));
iter.close();
}
use of com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl in project hugegraph-computer by hugegraph.
the class IOFactory method createGraphOutput.
public static GraphOutput createGraphOutput(ComputerContext context, OutputFormat format, RandomAccessOutput out) {
switch(format) {
case BIN:
EntryOutput entryOutput = new EntryOutputImpl(out);
return new StreamGraphOutput(context, entryOutput);
case CSV:
StructRandomAccessOutput srao;
srao = new StructRandomAccessOutput(out);
return new CsvStructGraphOutput(context, srao);
case JSON:
srao = new StructRandomAccessOutput(out);
return new JsonStructGraphOutput(context, srao);
default:
throw new ComputerException("Can't create GraphOutput for %s", format);
}
}
use of com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl in project hugegraph-computer by hugegraph.
the class ComputeManagerTest method writeEdges.
private static byte[] writeEdges(Vertex vertex, EdgeFrequency freq) throws IOException {
BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
GraphComputeOutput output = new StreamGraphOutput(context(), entryOutput);
Whitebox.setInternalState(output, "frequency", freq);
output.writeEdges(vertex);
return bytesOutput.toByteArray();
}
use of com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl in project hugegraph-computer by hugegraph.
the class EdgesInputTest method writeEdges.
private static byte[] writeEdges(Vertex vertex, EdgeFrequency freq) throws IOException {
BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
GraphComputeOutput output = new StreamGraphOutput(context(), entryOutput);
Whitebox.setInternalState(output, "frequency", freq);
output.writeEdges(vertex);
return bytesOutput.toByteArray();
}
Aggregations