Skip to content
Permalink
Browse files
refactor: add common hugegraph-output and writeType config (#175)
  • Loading branch information
coderzc committed Jan 14, 2022
1 parent 8308ffd commit 0ae7fea8a6924da76c9330ef1823a082228db97b
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 104 deletions.

This file was deleted.

@@ -26,6 +26,7 @@
import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.input.filter.ExtractAllPropertyInputFilter;
import com.baidu.hugegraph.computer.core.master.DefaultMasterComputation;
import com.baidu.hugegraph.computer.core.output.hg.HugeGraphDoubleOutput;

public class BetweennessCentralityParams implements AlgorithmParams {

@@ -40,7 +41,7 @@ public void setAlgorithmParameters(Map<String, String> params) {
this.setIfAbsent(params, ComputerOptions.ALGORITHM_MESSAGE_CLASS,
BetweennessMessage.class.getName());
this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS,
BetweennessCentralityOutput.class.getName());
HugeGraphDoubleOutput.class.getName());
this.setIfAbsent(params, ComputerOptions.INPUT_FILTER_CLASS,
ExtractAllPropertyInputFilter.class.getName());
this.setIfAbsent(params, ClosenessCentrality.OPTION_SAMPLE_RATE,
@@ -25,6 +25,7 @@
import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.input.filter.ExtractAllPropertyInputFilter;
import com.baidu.hugegraph.computer.core.master.DefaultMasterComputation;
import com.baidu.hugegraph.computer.core.output.hg.HugeGraphDoubleOutput;

public class ClosenessCentralityParams implements AlgorithmParams {

@@ -39,7 +40,7 @@ public void setAlgorithmParameters(Map<String, String> params) {
this.setIfAbsent(params, ComputerOptions.ALGORITHM_MESSAGE_CLASS,
ClosenessMessage.class.getName());
this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS,
ClosenessCentralityOutput.class.getName());
HugeGraphDoubleOutput.class.getName());
this.setIfAbsent(params, ComputerOptions.INPUT_FILTER_CLASS,
ExtractAllPropertyInputFilter.class.getName());
this.setIfAbsent(params, ClosenessCentrality.OPTION_SAMPLE_RATE,
@@ -26,6 +26,7 @@
import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.graph.value.DoubleValue;
import com.baidu.hugegraph.computer.core.master.DefaultMasterComputation;
import com.baidu.hugegraph.computer.core.output.hg.HugeGraphDoubleOutput;

public class DegreeCentralityParams implements AlgorithmParams {

@@ -42,6 +43,6 @@ public void setAlgorithmParameters(Map<String, String> params) {
this.setIfAbsent(params, ComputerOptions.WORKER_COMBINER_CLASS,
DoubleValueSumCombiner.class.getName());
this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS,
DegreeCentralityOutput.class.getName());
HugeGraphDoubleOutput.class.getName());
}
}
@@ -25,6 +25,7 @@
import com.baidu.hugegraph.computer.core.combiner.DoubleValueSumCombiner;
import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.graph.value.DoubleValue;
import com.baidu.hugegraph.computer.core.output.hg.HugeGraphDoubleOutput;

public class PageRankParams implements AlgorithmParams {

@@ -41,6 +42,6 @@ public void setAlgorithmParameters(Map<String, String> params) {
this.setIfAbsent(params, ComputerOptions.WORKER_COMBINER_CLASS,
DoubleValueSumCombiner.class.getName());
this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS,
PageRankOutput.class.getName());
HugeGraphDoubleOutput.class.getName());
}
}
@@ -25,7 +25,7 @@
import com.baidu.hugegraph.computer.core.combiner.ValueMinCombiner;
import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.graph.id.BytesId;
import com.baidu.hugegraph.computer.core.output.LimitedLogOutput;
import com.baidu.hugegraph.computer.core.output.hg.HugeGraphIdOutput;

public class KcoreParams implements AlgorithmParams {

@@ -40,6 +40,6 @@ public void setAlgorithmParameters(Map<String, String> params) {
this.setIfAbsent(params, ComputerOptions.WORKER_COMBINER_CLASS,
ValueMinCombiner.class.getName());
this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS,
LimitedLogOutput.class.getName());
HugeGraphIdOutput.class.getName());
}
}
@@ -24,7 +24,7 @@
import com.baidu.hugegraph.computer.algorithm.AlgorithmParams;
import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.graph.id.BytesId;
import com.baidu.hugegraph.computer.core.output.LimitedLogOutput;
import com.baidu.hugegraph.computer.core.output.hg.HugeGraphIdOutput;

public class LpaParams implements AlgorithmParams {

@@ -37,6 +37,6 @@ public void setAlgorithmParameters(Map<String, String> params) {
this.setIfAbsent(params, ComputerOptions.ALGORITHM_MESSAGE_CLASS,
BytesId.class.getName());
this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS,
LimitedLogOutput.class.getName());
HugeGraphIdOutput.class.getName());
}
}
@@ -34,11 +34,9 @@

public class TriangleCount implements Computation<IdList> {

public static final String ALGORITHM_NAME = "triangle_count";

@Override
public String name() {
return ALGORITHM_NAME;
return "triangle_count";
}

@Override
@@ -60,15 +58,15 @@ public void compute0(ComputationContext context, Vertex vertex) {
@Override
public void compute(ComputationContext context, Vertex vertex,
Iterator<IdList> messages) {
Long count = this.triangleCount(context, vertex, messages);
Integer count = this.triangleCount(context, vertex, messages);
if (count != null) {
((TriangleCountValue) vertex.value()).count(count);
vertex.inactivate();
}
}

private Long triangleCount(ComputationContext context, Vertex vertex,
Iterator<IdList> messages) {
private Integer triangleCount(ComputationContext context, Vertex vertex,
Iterator<IdList> messages) {
IdList neighbors = ((TriangleCountValue) vertex.value()).idList();

if (context.superstep() == 1) {
@@ -91,7 +89,7 @@ private Long triangleCount(ComputationContext context, Vertex vertex,
context.sendMessage(targetId, neighbors);
}
} else if (context.superstep() == 2) {
long count = 0L;
int count = 0;

Set<Id> allNeighbors = new HashSet<>(neighbors.values());
while (messages.hasNext()) {
@@ -25,6 +25,7 @@
import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.config.EdgeFrequency;
import com.baidu.hugegraph.computer.core.graph.value.IdList;
import com.baidu.hugegraph.computer.core.output.hg.HugeGraphIntOutput;

public class TriangleCountParams implements AlgorithmParams {

@@ -37,7 +38,7 @@ public void setAlgorithmParameters(Map<String, String> params) {
this.setIfAbsent(params, ComputerOptions.ALGORITHM_RESULT_CLASS,
TriangleCountValue.class.getName());
this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS,
TriangleCountOutput.class.getName());
HugeGraphIntOutput.class.getName());
this.setIfAbsent(params, ComputerOptions.INPUT_EDGE_FREQ.name(),
EdgeFrequency.SINGLE.name());
}
@@ -24,19 +24,19 @@
import org.apache.commons.lang3.builder.ToStringBuilder;

import com.baidu.hugegraph.computer.core.graph.value.IdList;
import com.baidu.hugegraph.computer.core.graph.value.LongValue;
import com.baidu.hugegraph.computer.core.graph.value.IntValue;
import com.baidu.hugegraph.computer.core.graph.value.Value.CustomizeValue;
import com.baidu.hugegraph.computer.core.io.RandomAccessInput;
import com.baidu.hugegraph.computer.core.io.RandomAccessOutput;

public class TriangleCountValue implements CustomizeValue<Long> {
public class TriangleCountValue implements CustomizeValue<Integer> {

private IdList idList;
private LongValue count;
private IntValue count;

public TriangleCountValue() {
this.idList = new IdList();
this.count = new LongValue();
this.count = new IntValue();
}

public IdList idList() {
@@ -47,7 +47,7 @@ public long count() {
return this.count.longValue();
}

public void count(long count) {
public void count(int count) {
this.count.value(count);
}

@@ -80,7 +80,7 @@ public String toString() {
}

@Override
public Long value() {
public Integer value() {
return this.count.value();
}
}
@@ -25,7 +25,7 @@
import com.baidu.hugegraph.computer.core.combiner.ValueMinCombiner;
import com.baidu.hugegraph.computer.core.config.ComputerOptions;
import com.baidu.hugegraph.computer.core.graph.id.BytesId;
import com.baidu.hugegraph.computer.core.output.LimitedLogOutput;
import com.baidu.hugegraph.computer.core.output.hg.HugeGraphIdOutput;

public class WccParams implements AlgorithmParams {

@@ -40,6 +40,6 @@ public void setAlgorithmParameters(Map<String, String> params) {
this.setIfAbsent(params, ComputerOptions.WORKER_COMBINER_CLASS,
ValueMinCombiner.class.getName());
this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS,
LimitedLogOutput.class.getName());
HugeGraphIdOutput.class.getName());
}
}
@@ -25,15 +25,14 @@
import com.baidu.hugegraph.computer.core.graph.value.IdListList;
import com.baidu.hugegraph.computer.core.graph.vertex.Vertex;
import com.baidu.hugegraph.computer.core.output.hg.HugeGraphOutput;
import com.baidu.hugegraph.structure.constant.WriteType;

public class RingsDetectionOutput extends HugeGraphOutput<List<String>> {

@Override
protected void prepareSchema() {
this.client().schema().propertyKey(this.name())
.asText()
.writeType(WriteType.OLAP_COMMON)
.writeType(this.writeType())
.valueList()
.ifNotExist()
.create();
@@ -225,6 +225,16 @@ public static synchronized ComputerOptions instance() {
false
);

public static final ConfigOption<String> OUTPUT_RESULT_WRITE_TYPE =
new ConfigOption<>(
"output.result_write_type",
"The result write-type to output to hugegraph, " +
"allowed values are: " +
"[OLAP_COMMON, OLAP_SECONDARY, OLAP_RANGE].",
allowValues("OLAP_COMMON", "OLAP_SECONDARY", "OLAP_RANGE"),
"OLAP_COMMON"
);

public static final ConfigOption<Integer> OUTPUT_BATCH_SIZE =
new ConfigOption<>(
"output.batch_size",
@@ -17,18 +17,15 @@
* under the License.
*/

package com.baidu.hugegraph.computer.algorithm.centrality.pagerank;
package com.baidu.hugegraph.computer.core.output.hg;

import com.baidu.hugegraph.computer.core.output.hg.HugeGraphOutput;
import com.baidu.hugegraph.structure.constant.WriteType;

public class PageRankOutput extends HugeGraphOutput<Double> {
public class HugeGraphDoubleOutput extends HugeGraphOutput<Double> {

@Override
protected void prepareSchema() {
this.client().schema().propertyKey(this.name())
.asDouble()
.writeType(WriteType.OLAP_RANGE)
.writeType(this.writeType())
.ifNotExist()
.create();
}
@@ -17,18 +17,15 @@
* under the License.
*/

package com.baidu.hugegraph.computer.algorithm.centrality.degree;
package com.baidu.hugegraph.computer.core.output.hg;

import com.baidu.hugegraph.computer.core.output.hg.HugeGraphOutput;
import com.baidu.hugegraph.structure.constant.WriteType;

public class DegreeCentralityOutput extends HugeGraphOutput<Double> {
public class HugeGraphFloatOutput extends HugeGraphOutput<Float> {

@Override
protected void prepareSchema() {
this.client().schema().propertyKey(this.name())
.asDouble()
.writeType(WriteType.OLAP_RANGE)
.asFloat()
.writeType(this.writeType())
.ifNotExist()
.create();
}
@@ -0,0 +1,39 @@
/*
* Copyright 2017 HugeGraph Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.baidu.hugegraph.computer.core.output.hg;

import com.baidu.hugegraph.computer.core.graph.vertex.Vertex;

public class HugeGraphIdOutput extends HugeGraphOutput<String> {

@Override
protected void prepareSchema() {
this.client().schema().propertyKey(this.name())
.asText()
.writeType(this.writeType())
.ifNotExist()
.create();
}

@Override
protected String value(Vertex vertex) {
return vertex.value().string();
}
}
@@ -17,18 +17,15 @@
* under the License.
*/

package com.baidu.hugegraph.computer.algorithm.centrality.closeness;
package com.baidu.hugegraph.computer.core.output.hg;

import com.baidu.hugegraph.computer.core.output.hg.HugeGraphOutput;
import com.baidu.hugegraph.structure.constant.WriteType;

public class ClosenessCentralityOutput extends HugeGraphOutput<Double> {
public class HugeGraphIntOutput extends HugeGraphOutput<Integer> {

@Override
public void prepareSchema() {
protected void prepareSchema() {
this.client().schema().propertyKey(this.name())
.asDouble()
.writeType(WriteType.OLAP_RANGE)
.asInt()
.writeType(this.writeType())
.ifNotExist()
.create();
}

0 comments on commit 0ae7fea

Please sign in to comment.