Search in sources :

Example 16 with GraphFactory

use of com.baidu.hugegraph.computer.core.graph.GraphFactory in project hugegraph-computer by hugegraph.

the class StreamGraphOutputInputTest method testWriteReadEdgesWithSinglePerLabelFrequency.

@Test
public void testWriteReadEdgesWithSinglePerLabelFrequency() throws Exception {
    UnitTestBase.updateOptions(ComputerOptions.INPUT_EDGE_FREQ, "SINGLE_PER_LABEL");
    ComputerContext context = ComputerContext.instance();
    GraphFactory graphFactory = context.graphFactory();
    Id longId = BytesId.of(100L);
    LongValue longValue = new LongValue(999L);
    Vertex vertex = graphFactory().createVertex(longId, longValue);
    vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
    vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
    vertex.addEdge(graphFactory.createEdge("watch", BytesId.of(3L)));
    vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
    vertex.addEdge(graphFactory.createEdge("watch", "2222", BytesId.of(4L)));
    byte[] bytes;
    try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        StreamGraphOutput output = newStreamGraphOutput(bao);
        output.writeEdges(vertex);
        bytes = bao.toByteArray();
        bytes = reweaveBytes(bytes);
    }
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        StreamGraphInput input = newStreamGraphInput(bai);
        assertEdgesEqual(vertex, input.readEdges(), EdgeFrequency.SINGLE_PER_LABEL);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Test(org.junit.Test)

Example 17 with GraphFactory

use of com.baidu.hugegraph.computer.core.graph.GraphFactory in project hugegraph-computer by hugegraph.

the class StreamGraphOutputInputTest method testWriteReadEdgesWithMultipleFrequency.

@Test
public void testWriteReadEdgesWithMultipleFrequency() throws Exception {
    UnitTestBase.updateOptions(ComputerOptions.INPUT_EDGE_FREQ, "MULTIPLE");
    ComputerContext context = ComputerContext.instance();
    GraphFactory graphFactory = context.graphFactory();
    Id longId = BytesId.of(100L);
    LongValue longValue = new LongValue(999L);
    Vertex vertex = graphFactory().createVertex(longId, longValue);
    vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
    vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
    vertex.addEdge(graphFactory.createEdge("watch", BytesId.of(3L)));
    vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
    vertex.addEdge(graphFactory.createEdge("watch", "2222", BytesId.of(4L)));
    byte[] bytes;
    try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        StreamGraphOutput output = newStreamGraphOutput(bao);
        output.writeEdges(vertex);
        bytes = bao.toByteArray();
        bytes = reweaveBytes(bytes);
    }
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        StreamGraphInput input = newStreamGraphInput(bai);
        assertEdgesEqual(vertex, input.readEdges(), EdgeFrequency.MULTIPLE);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Test(org.junit.Test)

Example 18 with GraphFactory

use of com.baidu.hugegraph.computer.core.graph.GraphFactory in project hugegraph-computer by hugegraph.

the class CsvStructGraphOutputTest method testWriteReadVertexOnlyIdAndValue.

@Test
public void testWriteReadVertexOnlyIdAndValue() throws IOException {
    UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "false", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "false", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false");
    ComputerContext context = context();
    GraphFactory factory = context.graphFactory();
    Id longId = BytesId.of(100L);
    Value value = BytesId.of(999L);
    Vertex vertex = factory.createVertex(longId, value);
    String fileName = "output.csv";
    File file = new File(fileName);
    try {
        BufferedFileOutput dos = new BufferedFileOutput(file);
        StructGraphOutput output = (StructGraphOutput) IOFactory.createGraphOutput(context, OutputFormat.CSV, dos);
        output.writeVertex(vertex);
        dos.close();
        @SuppressWarnings("deprecation") String text = FileUtils.readFileToString(file);
        Assert.assertEquals("100,999" + System.lineSeparator(), text);
    } finally {
        FileUtils.deleteQuietly(file);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) Value(com.baidu.hugegraph.computer.core.graph.value.Value) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) BooleanValue(com.baidu.hugegraph.computer.core.graph.value.BooleanValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) File(java.io.File) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Test(org.junit.Test)

Aggregations

GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)18 Test (org.junit.Test)17 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)15 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)11 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)9 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)9 Id (com.baidu.hugegraph.computer.core.graph.id.Id)9 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)9 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)6 File (java.io.File)6 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)4 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)4 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)4 Config (com.baidu.hugegraph.computer.core.config.Config)3 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)2 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)2 InlinePointer (com.baidu.hugegraph.computer.core.store.entry.InlinePointer)2 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)2