Search in sources :

Example 21 with LongValue

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

the class CsvStructGraphOutputTest method testWriteReadVertexWithProperties.

@Test
public void testWriteReadVertexWithProperties() throws IOException {
    UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "false", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "true", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false");
    ComputerContext context = context();
    GraphFactory factory = context.graphFactory();
    Id longId = BytesId.of(100L);
    IdListList idListList = new IdListList();
    IdList idList1 = new IdList();
    idList1.add(BytesId.of(66L));
    IdList idList2 = new IdList();
    idList2.add(BytesId.of(998L));
    idList2.add(BytesId.of(999L));
    idListList.add(idList1);
    idListList.add(idList2);
    Vertex vertex = factory.createVertex(longId, idListList);
    vertex.properties().put("boolean", new BooleanValue(true));
    vertex.properties().put("byte", new IntValue(127));
    vertex.properties().put("short", new IntValue(16383));
    vertex.properties().put("int", new IntValue(1000000));
    vertex.properties().put("long", new LongValue(10000000000L));
    vertex.properties().put("float", new FloatValue(0.1F));
    vertex.properties().put("double", new DoubleValue(-0.01D));
    vertex.properties().put("idvalue", longId);
    String fileName = "output3.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,[[66],[998,999]],{true,127,-0.01,16383," + "100,0.1,1000000,10000000000}" + 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) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BooleanValue(com.baidu.hugegraph.computer.core.graph.value.BooleanValue) 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) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) File(java.io.File) Test(org.junit.Test)

Example 22 with LongValue

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

the class OverwriteCombinerTest method testCombineNull.

@Test
public void testCombineNull() {
    LongValue value1 = new LongValue(1L);
    LongValue value2 = new LongValue(2L);
    OverwriteCombiner<LongValue> combiner = new OverwriteCombiner<>();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(null, value2, value2);
    }, e -> {
        Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(value1, null, value2);
    }, e -> {
        Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(value1, value2, null);
    }, e -> {
        Assert.assertEquals("The combine parameter result can't be null", e.getMessage());
    });
}
Also used : LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Test(org.junit.Test)

Example 23 with LongValue

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

the class PointerCombinerTest method testVertexPropertiesCombiner.

@Test
public void testVertexPropertiesCombiner() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName(), ComputerOptions.WORKER_VERTEX_PROPERTIES_COMBINER_CLASS, MergeOldPropertiesCombiner.class.getName());
    Combiner<Properties> valueCombiner = config.createObject(ComputerOptions.WORKER_VERTEX_PROPERTIES_COMBINER_CLASS);
    GraphFactory graphFactory = graphFactory();
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(graphFactory::createProperties, valueCombiner);
    try (BytesOutput bytesOutput1 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
        BytesOutput bytesOutput2 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        Properties value1 = graphFactory.createProperties();
        value1.put("p1", new LongValue(1L));
        Properties value2 = graphFactory.createProperties();
        value2.put("p2", new LongValue(2L));
        value1.write(bytesOutput1);
        value2.write(bytesOutput2);
        Pointer pointer1 = new InlinePointer(bytesOutput1.buffer(), bytesOutput1.position());
        Pointer pointer2 = new InlinePointer(bytesOutput2.buffer(), bytesOutput2.position());
        Pointer pointer = combiner.combine(pointer1, pointer2);
        BytesInput input = IOFactory.createBytesInput(pointer.bytes());
        Properties combinedValue = graphFactory.createProperties();
        combinedValue.read(input);
        Map<String, Value> map = combinedValue.get();
        Assert.assertEquals(2, map.size());
        Assert.assertEquals(new LongValue(1L), map.get("p1"));
        Assert.assertEquals(new LongValue(2L), map.get("p2"));
    }
}
Also used : GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) Config(com.baidu.hugegraph.computer.core.config.Config) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Value(com.baidu.hugegraph.computer.core.graph.value.Value) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Test(org.junit.Test)

Example 24 with LongValue

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

the class PointerCombinerTest method testCombineEdgePropertiesFail.

@Test
public void testCombineEdgePropertiesFail() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName(), ComputerOptions.WORKER_EDGE_PROPERTIES_COMBINER_CLASS, MergeOldPropertiesCombiner.class.getName());
    Combiner<Properties> valueCombiner = config.createObject(ComputerOptions.WORKER_EDGE_PROPERTIES_COMBINER_CLASS);
    GraphFactory graphFactory = graphFactory();
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(graphFactory::createProperties, valueCombiner);
    try (BytesOutput bytesOutput1 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
        BytesOutput bytesOutput2 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        Properties value1 = graphFactory.createProperties();
        value1.put("p1", new LongValue(1L));
        Properties value2 = graphFactory.createProperties();
        value2.put("p2", new LongValue(2L));
        // Only write count.
        bytesOutput1.writeInt(1);
        value2.write(bytesOutput2);
        Pointer pointer1 = new InlinePointer(bytesOutput1.buffer(), bytesOutput1.position());
        Pointer pointer2 = new InlinePointer(bytesOutput2.buffer(), bytesOutput2.position());
        Assert.assertThrows(ComputerException.class, () -> {
            combiner.combine(pointer1, pointer2);
        }, e -> {
            Assert.assertContains("Failed to combine pointer", e.getMessage());
        });
    }
}
Also used : GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) Config(com.baidu.hugegraph.computer.core.config.Config) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Test(org.junit.Test)

Example 25 with LongValue

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

the class ValueMaxCombinerTest method testCombineNull.

@Test
public void testCombineNull() {
    LongValue value1 = new LongValue(1L);
    LongValue value2 = new LongValue(2L);
    ValueMaxCombiner<LongValue> combiner = new ValueMaxCombiner<>();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(null, value2, value2);
    }, e -> {
        Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(value1, null, value2);
    }, e -> {
        Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(value1, value2, null);
    }, e -> {
        Assert.assertEquals("The combine parameter result can't be null", e.getMessage());
    });
}
Also used : LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Test(org.junit.Test)

Aggregations

LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)48 Test (org.junit.Test)25 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)21 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)19 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)16 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)13 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)13 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)9 Id (com.baidu.hugegraph.computer.core.graph.id.Id)9 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)8 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)8 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)7 DefaultProperties (com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties)7 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)5 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)3 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)3 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)2 Config (com.baidu.hugegraph.computer.core.config.Config)2