Search in sources :

Example 21 with IntValue

use of com.baidu.hugegraph.computer.core.graph.value.IntValue 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 IntValue

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

the class MockMasterComputation method assertStep0Aggregators.

protected void assertStep0Aggregators(MasterComputationContext context) {
    Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
    Assert.assertEquals(new FloatValue(5.2f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
    Assert.assertEquals(new FloatValue(3.14f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
    Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
    Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
    Assert.assertEquals(new LongValue(5L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
    Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
    Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
    Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
    Assert.assertEquals(new DoubleValue(10.4), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
    Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 23 with IntValue

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

the class MockMasterComputation method init.

@SuppressWarnings("unchecked")
@Override
public void init(MasterContext context) {
    context.registerAggregator(AGGR_CUSTOM_INT, MockIntAggregator.class);
    context.registerAggregator(AGGR_CUSTOM_FLOAT, MockFloatAggregator.class);
    context.registerAggregator(AGGR_FLOAT_UNSTABLE, MockFloatAggregator.class);
    context.registerAggregator(AGGR_INT_UNSTABLE, new IntValue(0), ValueMinCombiner.class);
    // overwrite is ok
    context.registerAggregator(// overwrite is ok
    AGGR_INT_UNSTABLE, new IntValue(Integer.MAX_VALUE), ValueMinCombiner.class);
    context.registerAggregator(AGGR_INT_SUM, ValueType.INT, IntValueSumCombiner.class);
    context.registerAggregator(AGGR_INT_MAX, ValueType.INT, ValueMaxCombiner.class);
    context.registerAggregator(AGGR_LONG_SUM, ValueType.LONG, LongValueSumCombiner.class);
    context.registerAggregator(AGGR_LONG_MAX, ValueType.LONG, ValueMaxCombiner.class);
    context.registerAggregator(AGGR_FLOAT_SUM, ValueType.FLOAT, FloatValueSumCombiner.class);
    context.registerAggregator(AGGR_FLOAT_MIN, ValueType.FLOAT, ValueMinCombiner.class);
    context.registerAggregator(AGGR_DOUBLE_SUM, ValueType.DOUBLE, DoubleValueSumCombiner.class);
    context.registerAggregator(AGGR_DOUBLE_MIN, ValueType.DOUBLE, ValueMinCombiner.class);
    this.registerAggregatorWithError(context);
}
Also used : IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 24 with IntValue

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

the class MockMasterComputation method assertAggregatedValueWithError.

private void assertAggregatedValueWithError(MasterComputationContext context) {
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM, new LongValue(7L));
    }, e -> {
        Assert.assertContains("Can't set long value '7' to int aggregator", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM, new IntValue(7));
    }, e -> {
        Assert.assertContains("Can't set int value '7' to long aggregator", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM, new FloatValue(7f));
    }, e -> {
        Assert.assertContains("Can't set float value '7.0' to double ", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN, null);
    }, e -> {
        Assert.assertContains("Can't set value to null for aggregator " + "'aggr_double_min'", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT, null);
    }, e -> {
        Assert.assertContains("Can't set value to null for aggregator " + "'aggr_int'", e.getMessage());
    });
    Assert.assertThrows(ClassCastException.class, () -> {
        context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT, new IntValue(7));
    }, e -> {
        Assert.assertContains("IntValue cannot be cast to", e.getMessage());
        Assert.assertContains("FloatValue", e.getMessage());
    });
}
Also used : LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 25 with IntValue

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

the class MockMasterComputation method assertStep1Aggregators.

protected void assertStep1Aggregators(MasterComputationContext context) {
    Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
    Assert.assertEquals(new FloatValue(5.2f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
    Assert.assertEquals(new FloatValue(3.14f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
    Assert.assertEquals(new IntValue(9), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
    Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
    Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
    Assert.assertEquals(new LongValue(5L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
    Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
    Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
    Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
    Assert.assertEquals(new DoubleValue(10.4), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
    Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Aggregations

IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)34 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)15 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)14 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)13 Test (org.junit.Test)12 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)10 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)9 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)7 CombineKvOuterSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvOuterSortFlusher)6 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)4 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)4 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)4 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)4 CombineKvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher)4 OuterSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.OuterSortFlusher)4 Config (com.baidu.hugegraph.computer.core.config.Config)3 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)3 InnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.InnerSortFlusher)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)3