Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: unify naming of degree for oltp algorithms #1433

Merged
merged 9 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hugegraph-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Implementation-Version>0.60.0.0</Implementation-Version>
<Implementation-Version>0.61.0.0</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.List;

import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
imbajin marked this conversation as resolved.
Show resolved Hide resolved

import javax.inject.Singleton;
import javax.ws.rs.DefaultValue;
Expand Down Expand Up @@ -66,7 +66,7 @@ public String get(@Context GraphManager manager,
@QueryParam("label") String edgeLabel,
@QueryParam("max_depth") int depth,
@QueryParam("max_degree")
@DefaultValue(DEFAULT_DEGREE) long degree,
@DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree,
@QueryParam("skip_degree")
@DefaultValue("0") long skipDegree,
@QueryParam("capacity")
Expand All @@ -75,7 +75,7 @@ public String get(@Context GraphManager manager,
"direction {}, edge label {}, max depth '{}', " +
"max degree '{}', skipped degree '{}' and capacity '{}'",
graph, source, target, direction, edgeLabel, depth,
degree, skipDegree, capacity);
maxDegree, skipDegree, capacity);

Id sourceId = VertexAPI.checkAndParseVertexId(source);
Id targetId = VertexAPI.checkAndParseVertexId(target);
Expand All @@ -88,7 +88,7 @@ public String get(@Context GraphManager manager,
ImmutableList.of(edgeLabel);
HugeTraverser.PathSet paths = traverser.allShortestPaths(
sourceId, targetId, dir, edgeLabels,
depth, degree, skipDegree, capacity);
depth, maxDegree, skipDegree, capacity);
return manager.serializer(g).writePaths("paths", paths, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.baidu.hugegraph.api.traversers;

import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_SKIP_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;

Expand Down Expand Up @@ -48,6 +48,7 @@
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;

Expand Down Expand Up @@ -109,7 +110,7 @@ private static class CountRequest {
@Override
public String toString() {
return String.format("CountRequest{source=%s,steps=%s," +
"contains_traversed=%s,dedupSize=%s}",
"containsTraversed=%s,dedupSize=%s}",
this.source, this.steps,
this.containsTraversed, this.dedupSize);
}
Expand All @@ -123,22 +124,23 @@ private static class Step {
public List<String> labels;
@JsonProperty("properties")
public Map<String, Object> properties;
@JsonProperty("degree")
public long degree = Long.valueOf(DEFAULT_DEGREE);
@JsonAlias("degree")
@JsonProperty("max_degree")
imbajin marked this conversation as resolved.
Show resolved Hide resolved
public long maxDegree = Long.parseLong(DEFAULT_MAX_DEGREE);
@JsonProperty("skip_degree")
public long skipDegree = Long.valueOf(DEFAULT_SKIP_DEGREE);
public long skipDegree = Long.parseLong(DEFAULT_SKIP_DEGREE);

@Override
public String toString() {
return String.format("Step{direction=%s,labels=%s,properties=%s" +
"degree=%s,skipDegree=%s}",
"maxDegree=%s,skipDegree=%s}",
this.direction, this.labels, this.properties,
this.degree, this.skipDegree);
this.maxDegree, this.skipDegree);
}

private EdgeStep jsonToStep(HugeGraph graph) {
return new EdgeStep(graph, this.direction, this.labels,
this.properties, this.degree, this.skipDegree);
this.properties, this.maxDegree, this.skipDegree);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.baidu.hugegraph.api.traversers;

import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATHS_LIMIT;

import javax.inject.Singleton;
Expand Down Expand Up @@ -64,7 +64,7 @@ public String get(@Context GraphManager manager,
@QueryParam("label") String edgeLabel,
@QueryParam("max_depth") int depth,
@QueryParam("max_degree")
@DefaultValue(DEFAULT_DEGREE) long degree,
@DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree,
@QueryParam("capacity")
@DefaultValue(DEFAULT_CAPACITY) long capacity,
@QueryParam("limit")
Expand All @@ -73,7 +73,7 @@ public String get(@Context GraphManager manager,
"with direction '{}', edge label '{}', max depth '{}', " +
"max degree '{}', capacity '{}' and limit '{}'",
graph, source, target, direction, edgeLabel,
depth, degree, capacity, limit);
depth, maxDegree, capacity, limit);

Id sourceId = VertexAPI.checkAndParseVertexId(source);
Id targetId = VertexAPI.checkAndParseVertexId(target);
Expand All @@ -83,7 +83,7 @@ public String get(@Context GraphManager manager,
PathsTraverser traverser = new PathsTraverser(g);
HugeTraverser.PathSet paths = traverser.paths(sourceId, dir, targetId,
dir, edgeLabel, depth,
degree, capacity, limit);
maxDegree, capacity, limit);
return manager.serializer(g).writePaths("crosspoints", paths, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.baidu.hugegraph.api.traversers;

import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATHS_LIMIT;

import java.util.ArrayList;
Expand Down Expand Up @@ -53,6 +53,7 @@
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;

@Path("graphs/{graph}/traversers/customizedcrosspoints")
Expand Down Expand Up @@ -136,9 +137,9 @@ private static class CrosspointsRequest {
@JsonProperty("path_patterns")
public List<PathPattern> pathPatterns;
@JsonProperty("capacity")
public long capacity = Long.valueOf(DEFAULT_CAPACITY);
public long capacity = Long.parseLong(DEFAULT_CAPACITY);
@JsonProperty("limit")
public long limit = Long.valueOf(DEFAULT_PATHS_LIMIT);
public long limit = Long.parseLong(DEFAULT_PATHS_LIMIT);
@JsonProperty("with_path")
public boolean withPath = false;
@JsonProperty("with_vertex")
Expand Down Expand Up @@ -173,24 +174,25 @@ private static class Step {
public List<String> labels;
@JsonProperty("properties")
public Map<String, Object> properties;
@JsonProperty("degree")
public long degree = Long.valueOf(DEFAULT_DEGREE);
@JsonAlias("degree")
@JsonProperty("max_degree")
imbajin marked this conversation as resolved.
Show resolved Hide resolved
public long maxDegree = Long.parseLong(DEFAULT_MAX_DEGREE);
@JsonProperty("skip_degree")
public long skipDegree = 0L;

@Override
public String toString() {
return String.format("Step{direction=%s,labels=%s,properties=%s," +
"degree=%s,skipDegree=%s}",
"maxDegree=%s,skipDegree=%s}",
this.direction, this.labels, this.properties,
this.degree, this.skipDegree);
this.maxDegree, this.skipDegree);
}

private CustomizedCrosspointsTraverser.Step jsonToStep(HugeGraph g) {
return new CustomizedCrosspointsTraverser.Step(g, this.direction,
this.labels,
this.properties,
this.degree,
this.maxDegree,
this.skipDegree);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.baidu.hugegraph.api.traversers;

import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATHS_LIMIT;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_SAMPLE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_WEIGHT;
Expand Down Expand Up @@ -56,6 +56,7 @@
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
import com.codahale.metrics.annotation.Timed;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;

@Path("graphs/{graph}/traversers/customizedpaths")
Expand Down Expand Up @@ -136,9 +137,9 @@ private static class PathRequest {
@JsonProperty("sort_by")
public SortBy sortBy;
@JsonProperty("capacity")
public long capacity = Long.valueOf(DEFAULT_CAPACITY);
public long capacity = Long.parseLong(DEFAULT_CAPACITY);
@JsonProperty("limit")
public long limit = Long.valueOf(DEFAULT_PATHS_LIMIT);
public long limit = Long.parseLong(DEFAULT_PATHS_LIMIT);
@JsonProperty("with_vertex")
public boolean withVertex = false;

Expand All @@ -160,31 +161,32 @@ private static class Step {
public List<String> labels;
@JsonProperty("properties")
public Map<String, Object> properties;
@JsonProperty("degree")
public long degree = Long.valueOf(DEFAULT_DEGREE);
@JsonAlias("degree")
@JsonProperty("max_degree")
imbajin marked this conversation as resolved.
Show resolved Hide resolved
public long maxDegree = Long.parseLong(DEFAULT_MAX_DEGREE);
@JsonProperty("skip_degree")
public long skipDegree = 0L;
@JsonProperty("weight_by")
public String weightBy;
@JsonProperty("default_weight")
public double defaultWeight = Double.valueOf(DEFAULT_WEIGHT);
public double defaultWeight = Double.parseDouble(DEFAULT_WEIGHT);
@JsonProperty("sample")
public long sample = Long.valueOf(DEFAULT_SAMPLE);
public long sample = Long.parseLong(DEFAULT_SAMPLE);

@Override
public String toString() {
return String.format("Step{direction=%s,labels=%s,properties=%s," +
"degree=%s,skipDegree=%s," +
"maxDegree=%s,skipDegree=%s," +
"weightBy=%s,defaultWeight=%s,sample=%s}",
this.direction, this.labels, this.properties,
this.degree, this.skipDegree,
this.maxDegree, this.skipDegree,
this.weightBy, this.defaultWeight,
this.sample);
}

private WeightedEdgeStep jsonToStep(HugeGraph g) {
return new WeightedEdgeStep(g, this.direction, this.labels,
this.properties, this.degree,
this.properties, this.maxDegree,
this.skipDegree, this.weightBy,
this.defaultWeight, this.sample);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.baidu.hugegraph.api.traversers;

import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_PATHS_LIMIT;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;

Expand Down Expand Up @@ -75,9 +75,9 @@ public String post(@Context GraphManager manager,
E.checkArgument(request.minNeighbors > 0,
"The min neighbor count must be > 0, but got: %s",
request.minNeighbors);
E.checkArgument(request.degree > 0 || request.degree == NO_LIMIT,
"The degree of request must be > 0, but got: %s",
request.degree);
E.checkArgument(request.maxDegree > 0L || request.maxDegree == NO_LIMIT,
"The max_degree of request must be > 0, but got: %s",
request.maxDegree);
E.checkArgument(request.alpha > 0 && request.alpha <= 1.0,
"The alpha of request must be in range (0, 1], " +
"but got '%s'", request.alpha);
Expand Down Expand Up @@ -107,8 +107,8 @@ public String post(@Context GraphManager manager,
request.minNeighbors, request.alpha,
request.minSimilars, request.top,
request.groupProperty, request.minGroups,
request.degree, request.capacity, request.limit,
request.withIntermediary);
request.maxDegree, request.capacity,
request.limit, request.withIntermediary);

CloseableIterator.closeIterator(sources);

Expand Down Expand Up @@ -140,11 +140,11 @@ private static class FusiformSimilarityRequest {
@JsonProperty("min_groups")
public int minGroups;
@JsonProperty("max_degree")
public long degree = Long.valueOf(DEFAULT_DEGREE);
public long maxDegree = Long.parseLong(DEFAULT_MAX_DEGREE);
@JsonProperty("capacity")
public long capacity = Long.valueOf(DEFAULT_CAPACITY);
public long capacity = Long.parseLong(DEFAULT_CAPACITY);
@JsonProperty("limit")
public long limit = Long.valueOf(DEFAULT_PATHS_LIMIT);
public long limit = Long.parseLong(DEFAULT_PATHS_LIMIT);
@JsonProperty("with_intermediary")
public boolean withIntermediary = false;
@JsonProperty("with_vertex")
Expand All @@ -156,13 +156,13 @@ public String toString() {
"label=%s,direction=%s,minNeighbors=%s," +
"alpha=%s,minSimilars=%s,top=%s," +
"groupProperty=%s,minGroups=%s," +
"degree=%s,capacity=%s,limit=%s," +
"maxDegree=%s,capacity=%s,limit=%s," +
"withIntermediary=%s,withVertex=%s}",
this.sources, this.label, this.direction,
this.minNeighbors, this.alpha,
this.minSimilars, this.top,
this.groupProperty, this.minGroups,
this.degree, this.capacity, this.limit,
this.maxDegree, this.capacity, this.limit,
this.withIntermediary, this.withVertex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.baidu.hugegraph.api.traversers;

import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_MAX_DEGREE;
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_LIMIT;

import java.util.Map;
Expand Down Expand Up @@ -71,10 +71,10 @@ public String get(@Context GraphManager manager,
@QueryParam("direction") String direction,
@QueryParam("label") String edgeLabel,
@QueryParam("max_degree")
@DefaultValue(DEFAULT_DEGREE) long degree) {
@DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree) {
LOG.debug("Graph [{}] get jaccard similarity between '{}' and '{}' " +
"with direction {}, edge label {} and max degree '{}'",
graph, vertex, other, direction, edgeLabel, degree);
graph, vertex, other, direction, edgeLabel, maxDegree);

Id sourceId = VertexAPI.checkAndParseVertexId(vertex);
Id targetId = VertexAPI.checkAndParseVertexId(other);
Expand All @@ -84,8 +84,8 @@ public String get(@Context GraphManager manager,
double similarity;
try (JaccardSimilarTraverser traverser =
new JaccardSimilarTraverser(g)) {
similarity = traverser.jaccardSimilarity(sourceId, targetId,
dir, edgeLabel, degree);
similarity = traverser.jaccardSimilarity(sourceId, targetId, dir,
edgeLabel, maxDegree);
}
return JsonUtil.toJson(ImmutableMap.of("jaccard_similarity",
similarity));
Expand Down Expand Up @@ -132,9 +132,9 @@ private static class Request {
@JsonProperty("step")
public TraverserAPI.Step step;
@JsonProperty("top")
public int top = Integer.valueOf(DEFAULT_LIMIT);
public int top = Integer.parseInt(DEFAULT_LIMIT);
@JsonProperty("capacity")
public long capacity = Long.valueOf(DEFAULT_CAPACITY);
public long capacity = Long.parseLong(DEFAULT_CAPACITY);

@Override
public String toString() {
Expand Down
Loading