Search in sources :

Example 31 with IntValue

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

the class SorterTest method sortedSubKvBuffer.

private BytesInput sortedSubKvBuffer(Config config) throws Exception {
    List<Integer> kv1 = ImmutableList.of(3, 2, 1, 4, 1);
    List<Integer> kv2 = ImmutableList.of(1, 3, 1, 5, 1);
    List<Integer> kv3 = ImmutableList.of(2, 8, 1, 9, 1);
    List<Integer> kv4 = ImmutableList.of(3, 2, 1, 3, 1);
    List<Integer> kv5 = ImmutableList.of(2, 5, 1, 8, 1);
    List<List<Integer>> data = ImmutableList.of(kv1, kv2, kv3, kv4, kv5);
    BytesInput input = SorterTestUtil.inputFromSubKvMap(data);
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
    int flushThreshold = config.get(ComputerOptions.INPUT_MAX_EDGES_IN_ONE_VERTEX);
    InnerSortFlusher flusher = new CombineSubKvInnerSortFlusher(output, combiner, flushThreshold);
    Sorter sorter = SorterTestUtil.createSorter(config);
    sorter.sortBuffer(input, flusher, true);
    return EntriesUtil.inputFromOutput(output);
}
Also used : IntValueSumCombiner(com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner) CombineSubKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineSubKvInnerSortFlusher) CombineSubKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineSubKvInnerSortFlusher) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher) InnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.InnerSortFlusher) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) PointerCombiner(com.baidu.hugegraph.computer.core.combiner.PointerCombiner) Sorter(com.baidu.hugegraph.computer.core.sort.Sorter) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 32 with IntValue

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

the class HugeConverterTest method testConvertValue.

@Test
public void testConvertValue() {
    Assert.assertEquals(NullValue.get(), HugeConverter.convertValue(null));
    Assert.assertEquals(new BooleanValue(true), HugeConverter.convertValue(true));
    Assert.assertEquals(new IntValue(1), HugeConverter.convertValue(1));
    Assert.assertEquals(new LongValue(-1L), HugeConverter.convertValue(-1L));
    Assert.assertEquals(new FloatValue(0.999F), HugeConverter.convertValue(0.999F));
    Assert.assertEquals(new DoubleValue(-0.001D), HugeConverter.convertValue(-0.001D));
    Assert.assertEquals(new StringValue("test"), HugeConverter.convertValue("test"));
    ListValue<IntValue> listValue = new ListValue<>(ValueType.INT);
    listValue.add(new IntValue(1));
    listValue.add(new IntValue(2));
    List<Integer> list = ImmutableList.of(1, 2);
    Assert.assertEquals(listValue, HugeConverter.convertValue(list));
    ListValue<ListValue<LongValue>> nestListValue = new ListValue<>(ValueType.LIST_VALUE);
    ListValue<LongValue> subListValue1 = new ListValue<>(ValueType.LONG);
    subListValue1.add(new LongValue(1L));
    subListValue1.add(new LongValue(2L));
    ListValue<LongValue> subListValue2 = new ListValue<>(ValueType.LONG);
    subListValue2.add(new LongValue(3L));
    subListValue2.add(new LongValue(4L));
    nestListValue.add(subListValue1);
    nestListValue.add(subListValue2);
    List<List<Long>> nestList = ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(3L, 4L));
    Assert.assertEquals(nestListValue, HugeConverter.convertValue(nestList));
    Assert.assertThrows(ComputerException.class, () -> HugeConverter.convertValue(new byte[0]));
}
Also used : ListValue(com.baidu.hugegraph.computer.core.graph.value.ListValue) 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) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) StringValue(com.baidu.hugegraph.computer.core.graph.value.StringValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) Test(org.junit.Test)

Example 33 with IntValue

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

the class HugeConverterTest method testConvertProperties.

@Test
public void testConvertProperties() {
    Map<String, Object> rawProperties = new HashMap<>();
    rawProperties.put("null-value", null);
    rawProperties.put("boolean-value", true);
    rawProperties.put("int-value", 1);
    rawProperties.put("long-value", 2L);
    rawProperties.put("float-value", 0.3F);
    rawProperties.put("double-value", 0.4D);
    rawProperties.put("list-value", ImmutableList.of(1, 2));
    Properties properties = graphFactory().createProperties();
    properties.put("null-value", NullValue.get());
    properties.put("boolean-value", new BooleanValue(true));
    properties.put("int-value", new IntValue(1));
    properties.put("long-value", new LongValue(2L));
    properties.put("float-value", new FloatValue(0.3F));
    properties.put("double-value", new DoubleValue(0.4D));
    ListValue<IntValue> listValue = new ListValue<>(ValueType.INT);
    listValue.add(new IntValue(1));
    listValue.add(new IntValue(2));
    properties.put("list-value", listValue);
    Assert.assertEquals(properties, HugeConverter.convertProperties(rawProperties));
}
Also used : HashMap(java.util.HashMap) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BooleanValue(com.baidu.hugegraph.computer.core.graph.value.BooleanValue) ListValue(com.baidu.hugegraph.computer.core.graph.value.ListValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) Test(org.junit.Test)

Example 34 with IntValue

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

the class Bsp4Worker method waitMasterResumeDone.

/**
 * The master set this signal to let workers knows the first superstep to
 * start with.
 */
public int waitMasterResumeDone() {
    LOG.info("Worker({}) is waiting for master resume-done", this.workerInfo.id());
    String path = this.constructPath(BspEvent.BSP_MASTER_RESUME_DONE);
    byte[] bytes = this.bspClient().get(path, this.barrierOnMasterTimeout(), this.logInterval());
    IntValue superstep = new IntValue();
    SerializeUtil.fromBytes(bytes, superstep);
    LOG.info("Worker({}) waited master resume-done({})", this.workerInfo.id(), superstep.value());
    return superstep.value();
}
Also used : 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