use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class GremlinQueryService method edgesOfVertex.
private Map<String, Edge> edgesOfVertex(TypedResult result, Map<Object, Vertex> vertices, HugeClient client) {
final HugeConfig config = this.config;
int batchSize = config.get(HubbleOptions.GREMLIN_BATCH_QUERY_IDS);
int edgeLimit = config.get(HubbleOptions.GREMLIN_EDGES_TOTAL_LIMIT);
int degreeLimit = config.get(HubbleOptions.GREMLIN_VERTEX_DEGREE_LIMIT);
Set<Object> vertexIds = vertices.keySet();
Map<String, Edge> edges = new HashMap<>(vertexIds.size());
Iterables.partition(vertexIds, batchSize).forEach(batch -> {
List<String> escapedIds = batch.stream().map(GremlinUtil::escapeId).collect(Collectors.toList());
String ids = StringUtils.join(escapedIds, ",");
// Any better way to find two vertices has linked?
String gremlin;
if (result.getType().isPath()) {
// If result type is path, the vertices count not too much in theory
gremlin = String.format("g.V(%s).bothE().local(limit(%s)).dedup()", ids, degreeLimit);
} else {
gremlin = String.format("g.V(%s).bothE().dedup().limit(%s)", ids, edgeLimit);
}
ResultSet resultSet = client.gremlin().gremlin(gremlin).execute();
// The edges count for per vertex
Map<Object, Integer> degrees = new HashMap<>(resultSet.size());
for (Iterator<Result> iter = resultSet.iterator(); iter.hasNext(); ) {
Edge edge = iter.next().getEdge();
Object source = edge.sourceId();
Object target = edge.targetId();
// only add the interconnected edges of the found vertices
if (!vertexIds.contains(source) || !vertexIds.contains(target)) {
continue;
}
edges.put(edge.id(), edge);
if (edges.size() >= edgeLimit) {
break;
}
int deg = degrees.compute(source, (k, v) -> v == null ? 1 : v + 1);
if (deg >= degreeLimit) {
break;
}
deg = degrees.compute(target, (k, v) -> v == null ? 1 : v + 1);
if (deg >= degreeLimit) {
break;
}
}
});
return edges;
}
use of com.baidu.hugegraph.structure.graph.Vertex in project hugegraph-computer by hugegraph.
the class SingleInsertTask method run.
@Override
public void run() {
for (Vertex vertex : this.batch) {
try {
this.insertSingle(vertex);
this.increaseLoadSuccess();
} catch (Exception e) {
this.metrics().increaseInsertFailure();
this.handleInsertFailure(e);
}
}
}
use of com.baidu.hugegraph.structure.graph.Vertex in project hugegraph-computer by hugegraph.
the class TriangleCountTest method setup.
@BeforeClass
public static void setup() {
clearAll();
SchemaManager schema = client().schema();
schema.propertyKey(PROPERTY_KEY).asInt().ifNotExist().create();
schema.vertexLabel(VERTX_LABEL).properties(PROPERTY_KEY).useCustomizeStringId().ifNotExist().create();
schema.edgeLabel(EDGE_LABEL).sourceLabel(VERTX_LABEL).targetLabel(VERTX_LABEL).properties(PROPERTY_KEY).ifNotExist().create();
GraphManager graph = client().graph();
Vertex vA = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_A", PROPERTY_KEY, 1);
Vertex vB = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_B", PROPERTY_KEY, 1);
Vertex vC = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_C", PROPERTY_KEY, 1);
Vertex vD = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_D", PROPERTY_KEY, 1);
Vertex vE = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_E", PROPERTY_KEY, 1);
vA.addEdge(EDGE_LABEL, vB, PROPERTY_KEY, 1);
vA.addEdge(EDGE_LABEL, vC, PROPERTY_KEY, 1);
vB.addEdge(EDGE_LABEL, vC, PROPERTY_KEY, 1);
vC.addEdge(EDGE_LABEL, vD, PROPERTY_KEY, 1);
vD.addEdge(EDGE_LABEL, vA, PROPERTY_KEY, 1);
vD.addEdge(EDGE_LABEL, vE, PROPERTY_KEY, 1);
vE.addEdge(EDGE_LABEL, vD, PROPERTY_KEY, 1);
vE.addEdge(EDGE_LABEL, vC, PROPERTY_KEY, 1);
}
use of com.baidu.hugegraph.structure.graph.Vertex in project hugegraph-computer by hugegraph.
the class RingsDetectionWithFilterTest method setup.
@BeforeClass
public static void setup() {
clearAll();
HugeClient client = client();
SchemaManager schema = client.schema();
schema.propertyKey("weight").asInt().ifNotExist().create();
schema.vertexLabel("user").properties("weight").useCustomizeStringId().ifNotExist().create();
schema.edgeLabel("know").sourceLabel("user").targetLabel("user").properties("weight").ifNotExist().create();
GraphManager graph = client.graph();
Vertex vA = graph.addVertex(T.label, "user", T.id, "A", "weight", 1);
Vertex vB = graph.addVertex(T.label, "user", T.id, "B", "weight", 1);
Vertex vC = graph.addVertex(T.label, "user", T.id, "C", "weight", 1);
Vertex vD = graph.addVertex(T.label, "user", T.id, "D", "weight", 1);
Vertex vE = graph.addVertex(T.label, "user", T.id, "E", "weight", 3);
vA.addEdge("know", vB, "weight", 1);
vA.addEdge("know", vC, "weight", 1);
vA.addEdge("know", vD, "weight", 1);
vB.addEdge("know", vA, "weight", 2);
vB.addEdge("know", vC, "weight", 1);
vB.addEdge("know", vE, "weight", 1);
vC.addEdge("know", vA, "weight", 1);
vC.addEdge("know", vB, "weight", 1);
vC.addEdge("know", vD, "weight", 1);
vD.addEdge("know", vC, "weight", 1);
vD.addEdge("know", vE, "weight", 1);
vE.addEdge("know", vC, "weight", 1);
RingsDetectionTestOutput.EXPECT_RINGS = EXPECT_RINGS;
}
use of com.baidu.hugegraph.structure.graph.Vertex in project hugegraph-computer by hugegraph.
the class ClosenessCentralityTest method setup.
@BeforeClass
public static void setup() {
clearAll();
HugeClient client = client();
SchemaManager schema = client.schema();
schema.propertyKey("rate").asInt().ifNotExist().create();
schema.vertexLabel("user").useCustomizeStringId().ifNotExist().create();
schema.edgeLabel("link").sourceLabel("user").targetLabel("user").properties("rate").ifNotExist().create();
GraphManager graph = client.graph();
Vertex vA = graph.addVertex(T.label, "user", T.id, "A");
Vertex vB = graph.addVertex(T.label, "user", T.id, "B");
Vertex vC = graph.addVertex(T.label, "user", T.id, "C");
Vertex vD = graph.addVertex(T.label, "user", T.id, "D");
Vertex vE = graph.addVertex(T.label, "user", T.id, "E");
Vertex vF = graph.addVertex(T.label, "user", T.id, "F");
vA.addEdge("link", vB, "rate", 1);
vB.addEdge("link", vA, "rate", 1);
vB.addEdge("link", vC, "rate", 2);
vC.addEdge("link", vB, "rate", 2);
vB.addEdge("link", vD, "rate", 2);
vD.addEdge("link", vB, "rate", 2);
vC.addEdge("link", vD, "rate", 1);
vD.addEdge("link", vC, "rate", 1);
vC.addEdge("link", vE, "rate", 3);
vE.addEdge("link", vC, "rate", 3);
vD.addEdge("link", vE, "rate", 1);
vE.addEdge("link", vD, "rate", 1);
vD.addEdge("link", vF, "rate", 4);
vF.addEdge("link", vD, "rate", 4);
vE.addEdge("link", vF, "rate", 2);
vF.addEdge("link", vE, "rate", 2);
}
Aggregations