diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityOutput.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityOutput.java deleted file mode 100644 index f17b42567..000000000 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityOutput.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.algorithm.centrality.betweenness; - -import com.baidu.hugegraph.computer.core.output.hg.HugeGraphOutput; -import com.baidu.hugegraph.structure.constant.WriteType; - -public class BetweennessCentralityOutput extends HugeGraphOutput { - - @Override - public void prepareSchema() { - this.client().schema().propertyKey(this.name()) - .asDouble() - .writeType(WriteType.OLAP_RANGE) - .ifNotExist() - .create(); - } -} diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityParams.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityParams.java index 9e6266cd7..f768b1b87 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityParams.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityParams.java @@ -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 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, diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityParams.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityParams.java index eded57d20..869ac4b75 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityParams.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityParams.java @@ -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 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, diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityParams.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityParams.java index af6e836be..0935f846b 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityParams.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityParams.java @@ -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 params) { this.setIfAbsent(params, ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName()); this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS, - DegreeCentralityOutput.class.getName()); + HugeGraphDoubleOutput.class.getName()); } } diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/pagerank/PageRankParams.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/pagerank/PageRankParams.java index a8d523090..18c668ab2 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/pagerank/PageRankParams.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/pagerank/PageRankParams.java @@ -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 params) { this.setIfAbsent(params, ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName()); this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS, - PageRankOutput.class.getName()); + HugeGraphDoubleOutput.class.getName()); } } diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/kcore/KcoreParams.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/kcore/KcoreParams.java index 6fd26b927..766736d18 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/kcore/KcoreParams.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/kcore/KcoreParams.java @@ -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 params) { this.setIfAbsent(params, ComputerOptions.WORKER_COMBINER_CLASS, ValueMinCombiner.class.getName()); this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS, - LimitedLogOutput.class.getName()); + HugeGraphIdOutput.class.getName()); } } diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/lpa/LpaParams.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/lpa/LpaParams.java index 93de697e2..12b3710f3 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/lpa/LpaParams.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/lpa/LpaParams.java @@ -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 params) { this.setIfAbsent(params, ComputerOptions.ALGORITHM_MESSAGE_CLASS, BytesId.class.getName()); this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS, - LimitedLogOutput.class.getName()); + HugeGraphIdOutput.class.getName()); } } diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCount.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCount.java index fd2c3ea59..7d3d02225 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCount.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCount.java @@ -34,11 +34,9 @@ public class TriangleCount implements Computation { - 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 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 messages) { + private Integer triangleCount(ComputationContext context, Vertex vertex, + Iterator 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 allNeighbors = new HashSet<>(neighbors.values()); while (messages.hasNext()) { diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountParams.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountParams.java index 513d94df3..8cdf5f3ea 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountParams.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountParams.java @@ -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 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()); } diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountValue.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountValue.java index e8019ef07..b687b276b 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountValue.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountValue.java @@ -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 { +public class TriangleCountValue implements CustomizeValue { 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(); } } diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/wcc/WccParams.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/wcc/WccParams.java index 232d7bdb8..bc1ca168a 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/wcc/WccParams.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/wcc/WccParams.java @@ -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 params) { this.setIfAbsent(params, ComputerOptions.WORKER_COMBINER_CLASS, ValueMinCombiner.class.getName()); this.setIfAbsent(params, ComputerOptions.OUTPUT_CLASS, - LimitedLogOutput.class.getName()); + HugeGraphIdOutput.class.getName()); } } diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/path/rings/RingsDetectionOutput.java b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/path/rings/RingsDetectionOutput.java index 9014be18f..d74ec6f29 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/path/rings/RingsDetectionOutput.java +++ b/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/path/rings/RingsDetectionOutput.java @@ -25,7 +25,6 @@ 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> { @@ -33,7 +32,7 @@ public class RingsDetectionOutput extends HugeGraphOutput> { protected void prepareSchema() { this.client().schema().propertyKey(this.name()) .asText() - .writeType(WriteType.OLAP_COMMON) + .writeType(this.writeType()) .valueList() .ifNotExist() .create(); diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/config/ComputerOptions.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/config/ComputerOptions.java index 7ffb41872..20b929d49 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/config/ComputerOptions.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/config/ComputerOptions.java @@ -225,6 +225,16 @@ public static synchronized ComputerOptions instance() { false ); + public static final ConfigOption 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 OUTPUT_BATCH_SIZE = new ConfigOption<>( "output.batch_size", diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/pagerank/PageRankOutput.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphDoubleOutput.java similarity index 77% rename from computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/pagerank/PageRankOutput.java rename to computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphDoubleOutput.java index 667f1e66d..9337213de 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/pagerank/PageRankOutput.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphDoubleOutput.java @@ -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 { +public class HugeGraphDoubleOutput extends HugeGraphOutput { @Override protected void prepareSchema() { this.client().schema().propertyKey(this.name()) .asDouble() - .writeType(WriteType.OLAP_RANGE) + .writeType(this.writeType()) .ifNotExist() .create(); } diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityOutput.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphFloatOutput.java similarity index 74% rename from computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityOutput.java rename to computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphFloatOutput.java index ca3a03de7..eccf4eb38 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityOutput.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphFloatOutput.java @@ -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 { +public class HugeGraphFloatOutput extends HugeGraphOutput { @Override protected void prepareSchema() { this.client().schema().propertyKey(this.name()) - .asDouble() - .writeType(WriteType.OLAP_RANGE) + .asFloat() + .writeType(this.writeType()) .ifNotExist() .create(); } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphIdOutput.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphIdOutput.java new file mode 100644 index 000000000..82a48fbca --- /dev/null +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphIdOutput.java @@ -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 { + + @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(); + } +} diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityOutput.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphIntOutput.java similarity index 71% rename from computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityOutput.java rename to computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphIntOutput.java index 121832c59..6f24c20b1 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityOutput.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphIntOutput.java @@ -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 { +public class HugeGraphIntOutput extends HugeGraphOutput { @Override - public void prepareSchema() { + protected void prepareSchema() { this.client().schema().propertyKey(this.name()) - .asDouble() - .writeType(WriteType.OLAP_RANGE) + .asInt() + .writeType(this.writeType()) .ifNotExist() .create(); } diff --git a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountOutput.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphLongOutput.java similarity index 76% rename from computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountOutput.java rename to computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphLongOutput.java index 9660817a1..1297cc10d 100644 --- a/computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountOutput.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphLongOutput.java @@ -17,18 +17,15 @@ * under the License. */ -package com.baidu.hugegraph.computer.algorithm.community.trianglecount; +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 TriangleCountOutput extends HugeGraphOutput { +public class HugeGraphLongOutput extends HugeGraphOutput { @Override protected void prepareSchema() { this.client().schema().propertyKey(this.name()) .asLong() - .writeType(WriteType.OLAP_RANGE) + .writeType(this.writeType()) .ifNotExist() .create(); } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphOutput.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphOutput.java index 5fa12e9f6..fc829421a 100644 --- a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphOutput.java +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphOutput.java @@ -30,6 +30,7 @@ import com.baidu.hugegraph.computer.core.output.AbstractComputerOutput; import com.baidu.hugegraph.computer.core.output.hg.task.TaskManager; import com.baidu.hugegraph.driver.HugeClient; +import com.baidu.hugegraph.structure.constant.WriteType; import com.baidu.hugegraph.util.Log; public abstract class HugeGraphOutput extends AbstractComputerOutput { @@ -39,6 +40,7 @@ public abstract class HugeGraphOutput extends AbstractComputerOutput { private TaskManager taskManager; private List localVertices; private int batchSize; + private WriteType writeType; @Override public void init(Config config, int partition) { @@ -47,6 +49,8 @@ public void init(Config config, int partition) { this.taskManager = new TaskManager(config); this.batchSize = config.get(ComputerOptions.OUTPUT_BATCH_SIZE); this.localVertices = new ArrayList<>(this.batchSize); + this.writeType = WriteType.valueOf( + config.get(ComputerOptions.OUTPUT_RESULT_WRITE_TYPE)); this.prepareSchema(); } @@ -95,5 +99,9 @@ protected T value(Vertex vertex) { return value; } + protected WriteType writeType() { + return this.writeType; + } + protected abstract void prepareSchema(); } diff --git a/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphStringOutput.java b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphStringOutput.java new file mode 100644 index 000000000..b372b599f --- /dev/null +++ b/computer-core/src/main/java/com/baidu/hugegraph/computer/core/output/hg/HugeGraphStringOutput.java @@ -0,0 +1,32 @@ +/* + * 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; + +public class HugeGraphStringOutput extends HugeGraphOutput { + + @Override + protected void prepareSchema() { + this.client().schema().propertyKey(this.name()) + .asText() + .writeType(this.writeType()) + .ifNotExist() + .create(); + } +} diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityTest.java index b72f94570..535d213cd 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/betweenness/BetweennessCentralityTest.java @@ -27,6 +27,7 @@ import com.baidu.hugegraph.computer.algorithm.AlgorithmTestBase; import com.baidu.hugegraph.computer.core.config.ComputerOptions; +import com.baidu.hugegraph.computer.core.output.hg.HugeGraphDoubleOutput; import com.baidu.hugegraph.driver.GraphManager; import com.baidu.hugegraph.driver.HugeClient; import com.baidu.hugegraph.driver.SchemaManager; @@ -130,7 +131,7 @@ public void testRunAlgorithm() throws InterruptedException { } public static class BetweennessCentralityTestOutput - extends BetweennessCentralityOutput { + extends HugeGraphDoubleOutput { @Override protected Double value( diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityTest.java index 4d4537057..eaaec5ae6 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/closeness/ClosenessCentralityTest.java @@ -27,6 +27,7 @@ import com.baidu.hugegraph.computer.algorithm.AlgorithmTestBase; import com.baidu.hugegraph.computer.core.config.ComputerOptions; +import com.baidu.hugegraph.computer.core.output.hg.HugeGraphDoubleOutput; import com.baidu.hugegraph.driver.GraphManager; import com.baidu.hugegraph.driver.HugeClient; import com.baidu.hugegraph.driver.SchemaManager; @@ -106,7 +107,7 @@ public void testWithWeightProperty() throws InterruptedException { } public static class ClosenessWithWeightPropertyTestOutput - extends ClosenessCentralityOutput { + extends HugeGraphDoubleOutput { private final Map expectResults = ImmutableMap.builder() @@ -140,7 +141,7 @@ public void testWithoutWeightProperty() throws InterruptedException { } public static class ClosenessWithoutWeightPropertyTestOutput - extends ClosenessCentralityOutput { + extends HugeGraphDoubleOutput { private final Map expectResults = ImmutableMap.builder() diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityTest.java index 79ccda145..171fa35ee 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityTest.java @@ -32,6 +32,7 @@ import com.baidu.hugegraph.computer.core.graph.edge.Edge; import com.baidu.hugegraph.computer.core.graph.value.DoubleValue; import com.baidu.hugegraph.computer.core.graph.vertex.Vertex; +import com.baidu.hugegraph.computer.core.output.hg.HugeGraphDoubleOutput; import com.google.common.collect.Streams; public class DegreeCentralityTest extends AlgorithmTestBase { @@ -58,7 +59,7 @@ public void setAlgorithmParameters(Map params) { } public static class DegreeCentralityTestOutput - extends DegreeCentralityOutput { + extends HugeGraphDoubleOutput { private String weight; private static boolean isRun; diff --git a/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountTest.java b/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountTest.java index 9d94159c5..25df59b30 100644 --- a/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountTest.java +++ b/computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/community/trianglecount/TriangleCountTest.java @@ -27,6 +27,7 @@ import com.baidu.hugegraph.computer.algorithm.AlgorithmTestBase; import com.baidu.hugegraph.computer.core.config.ComputerOptions; +import com.baidu.hugegraph.computer.core.output.hg.HugeGraphIntOutput; import com.baidu.hugegraph.driver.GraphManager; import com.baidu.hugegraph.driver.SchemaManager; import com.baidu.hugegraph.structure.constant.T; @@ -41,10 +42,10 @@ public class TriangleCountTest extends AlgorithmTestBase { private static final String EDGE_LABEL = "tc_know"; private static final String PROPERTY_KEY = "tc_weight"; - protected static final Map EXPECTED_RESULTS = - ImmutableMap.of("tc_A", 2L, "tc_B", 1L, - "tc_C", 3L, "tc_D", 2L, - "tc_E", 1L); + protected static final Map EXPECTED_RESULTS = + ImmutableMap.of("tc_A", 2, "tc_B", 1, + "tc_C", 3, "tc_D", 2, + "tc_E", 1); @BeforeClass public static void setup() { @@ -98,32 +99,32 @@ public static void teardown() { public void testRunAlgorithm() throws InterruptedException { runAlgorithm(TriangleCountParams.class.getName(), ComputerOptions.OUTPUT_CLASS.name(), - TriangleCountOutputTest.class.getName()); + TriangleCountIntOutputTest.class.getName()); } @Test public void testTriangleCountValue() { TriangleCountValue value = new TriangleCountValue(); - value.count(10L); + value.count(10); Assert.assertThrows(UnsupportedOperationException.class, () -> value.assign(null)); Assert.assertThrows(UnsupportedOperationException.class, () -> value.compareTo(new TriangleCountValue())); - TriangleCountValue copy = (TriangleCountValue) value.copy(); - Assert.assertEquals(10L, copy.count()); + TriangleCountValue copy = value.copy(); + Assert.assertEquals(10, copy.count()); Assert.assertNotSame(value.idList(), copy.idList()); Assert.assertContains("10", value.toString()); } - public static class TriangleCountOutputTest extends TriangleCountOutput { + public static class TriangleCountIntOutputTest extends HugeGraphIntOutput { @Override - public Long value( + public Integer value( com.baidu.hugegraph.computer.core.graph.vertex.Vertex vertex) { - Long value = (Long) super.value(vertex); - Long expected = EXPECTED_RESULTS.get(vertex.id()); + Integer value = super.value(vertex); + Integer expected = EXPECTED_RESULTS.get(vertex.id()); if (expected != null) { Assert.assertEquals(expected, value); }