Search in sources :

Example 6 with IntValue

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

the class MockComputation2 method assertStep1Aggregators.

@Override
protected void assertStep1Aggregators(WorkerContext context) {
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
    Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
    Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
    Assert.assertEquals(new LongValue(10L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
    Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
    Assert.assertEquals(new FloatValue(20.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
    Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
    Assert.assertEquals(new DoubleValue(20.8), 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 7 with IntValue

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

the class MockMasterComputation method updateStep0Aggregators.

protected void updateStep0Aggregators(MasterComputationContext context) {
    // Update UNSTABLE aggregator
    context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE, new FloatValue(8.8f));
    Assert.assertEquals(new FloatValue(8.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
    context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE, new IntValue(888));
    Assert.assertEquals(new IntValue(888), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
    // Update aggregator with error
    this.assertAggregatedValueWithError(context);
}
Also used : FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 8 with IntValue

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

the class MockMasterComputation method registerAggregatorWithError.

private void registerAggregatorWithError(MasterContext context) {
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.registerAggregator("", MockIntAggregator.class);
    }, e -> {
        Assert.assertContains("registered aggregator name can't be empty", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.registerAggregator(null, MockIntAggregator.class);
    }, e -> {
        Assert.assertContains("registered aggregator name can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.registerAggregator("", ValueType.INT, IntValueSumCombiner.class);
    }, e -> {
        Assert.assertContains("registered aggregator name can't be empty", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.registerAggregator(null, ValueType.INT, IntValueSumCombiner.class);
    }, e -> {
        Assert.assertContains("registered aggregator name can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.registerAggregator(AGGR_INT_UNSTABLE, ValueType.INT, null);
    }, e -> {
        Assert.assertContains("combiner of aggregator can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        ValueType type = null;
        context.registerAggregator(AGGR_INT_UNSTABLE, type, IntValueSumCombiner.class);
    }, e -> {
        Assert.assertContains("value type of aggregator can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        IntValue value = null;
        context.registerAggregator(AGGR_INT_UNSTABLE, value, IntValueSumCombiner.class);
    }, e -> {
        Assert.assertContains("The aggregator default value can't be null", e.getMessage());
    });
    // Not applied now, can get it through aggregatedValue() after inited()
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        context.aggregatedValue(AGGR_INT_UNSTABLE, new IntValue(Integer.MAX_VALUE));
    }, e -> {
        Assert.assertContains("Can't get aggregator 'aggr_int_unstable", e.getMessage());
    });
}
Also used : ValueType(com.baidu.hugegraph.computer.core.graph.value.ValueType) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 9 with IntValue

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

the class SortLargeDataTest method mergeFiles.

private static void mergeFiles(Sorter sorter, List<String> files, List<String> outputs) throws Exception {
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
    OuterSortFlusher flusher = new CombineKvOuterSortFlusher(combiner);
    sorter.mergeInputs(files, flusher, outputs, false);
}
Also used : IntValueSumCombiner(com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner) OuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.OuterSortFlusher) KvOuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.KvOuterSortFlusher) CombineKvOuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvOuterSortFlusher) CombineKvOuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvOuterSortFlusher) PointerCombiner(com.baidu.hugegraph.computer.core.combiner.PointerCombiner) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 10 with IntValue

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

the class SortLargeDataTest method sortBuffer.

private static RandomAccessInput sortBuffer(Sorter sorter, RandomAccessInput input) throws Exception {
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
    InnerSortFlusher flusher = new CombineKvInnerSortFlusher(output, combiner);
    sorter.sortBuffer(input, flusher, false);
    return EntriesUtil.inputFromOutput(output);
}
Also used : IntValueSumCombiner(com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher) InnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.InnerSortFlusher) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) PointerCombiner(com.baidu.hugegraph.computer.core.combiner.PointerCombiner) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher)

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