use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class MultiNodeShortestPathTraverser method multiNodeShortestPath.
public List<Path> multiNodeShortestPath(Iterator<Vertex> vertices, EdgeStep step, int maxDepth, long capacity) {
List<Vertex> vertexList = IteratorUtils.list(vertices);
int vertexCount = vertexList.size();
E.checkState(vertexCount >= 2 && vertexCount <= MAX_VERTICES, "The number of vertices of multiple node shortest path " + "must in [2, %s], but got: %s", MAX_VERTICES, vertexList.size());
List<Pair<Id, Id>> pairs = newList();
cmn(vertexList, vertexCount, 2, 0, null, r -> {
Id source = ((HugeVertex) r.get(0)).id();
Id target = ((HugeVertex) r.get(1)).id();
Pair<Id, Id> pair = Pair.of(source, target);
pairs.add(pair);
});
if (maxDepth >= this.concurrentDepth() && vertexCount > 10) {
return this.multiNodeShortestPathConcurrent(pairs, step, maxDepth, capacity);
} else {
return this.multiNodeShortestPathSingle(pairs, step, maxDepth, capacity);
}
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class StandardTaskScheduler method save.
@Override
public <V> void save(HugeTask<V> task) {
LOG.debug("Saving task: {}", task);
task.scheduler(this);
E.checkArgumentNotNull(task, "Task can't be null");
this.call(() -> {
// Construct vertex from task
HugeVertex vertex = this.tx().constructVertex(task);
// Delete index of old vertex to avoid stale index
this.tx().deleteIndex(vertex);
// Add or update task info to backend store
return this.tx().addVertex(vertex);
});
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class StandardTaskScheduler method delete.
@Override
public <V> HugeTask<V> delete(Id id) {
this.checkOnMasterNode("delete");
HugeTask<?> task = this.task(id);
/*
* The following is out of date when task running on worker node:
* HugeTask<?> task = this.tasks.get(id);
* Tasks are removed from memory after completed at most time,
* but there is a tiny gap between tasks are completed and
* removed from memory.
* We assume tasks only in memory may be incomplete status,
* in fact, it is also possible to appear on the backend tasks
* when the database status is inconsistent.
*/
if (task != null) {
E.checkArgument(task.completed(), "Can't delete incomplete task '%s' in status %s" + ", Please try to cancel the task first", id, task.status());
this.remove(task);
}
return this.call(() -> {
Iterator<Vertex> vertices = this.tx().queryVertices(id);
HugeVertex vertex = (HugeVertex) QueryResults.one(vertices);
if (vertex == null) {
return null;
}
HugeTask<V> result = HugeTask.fromVertex(vertex);
E.checkState(result.completed(), "Can't delete incomplete task '%s' in status %s", id, result.status());
this.tx().removeVertex(vertex);
return result;
});
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class HugeVariables method queryVariableVertex.
private HugeVertex queryVariableVertex(String key) {
GraphTransaction tx = this.params.graphTransaction();
Query query = this.createVariableQuery(key);
Iterator<Vertex> vertices = tx.queryVertices(query);
return (HugeVertex) QueryResults.one(vertices);
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class RamTableTest method testReloadAndQueryWithProperty.
@Test
public void testReloadAndQueryWithProperty() throws Exception {
HugeGraph graph = this.graph();
SchemaManager schema = graph.schema();
schema.propertyKey("name").asText().create();
schema.vertexLabel("person").properties("name").useCustomizeNumberId().create();
schema.edgeLabel("next").sourceLabel("person").targetLabel("person").properties("name").create();
GraphTraversalSource g = graph.traversal();
g.addV("person").property(T.id, 1).property("name", "A").as("a").addV("person").property(T.id, 2).property("name", "B").as("b").addV("person").property(T.id, 3).property("name", "C").as("c").addV("person").property(T.id, 4).property("name", "D").as("d").addV("person").property(T.id, 5).property("name", "E").as("e").addV("person").property(T.id, 6).property("name", "F").as("f").addE("next").from("a").to("b").property("name", "ab").addE("next").from("b").to("c").property("name", "bc").addE("next").from("b").to("d").property("name", "bd").addE("next").from("c").to("d").property("name", "cd").addE("next").from("c").to("e").property("name", "ce").addE("next").from("d").to("e").property("name", "de").addE("next").from("e").to("f").property("name", "ef").addE("next").from("f").to("d").property("name", "fd").iterate();
graph.tx().commit();
Object ramtable = Whitebox.getInternalState(graph, "ramtable");
Assert.assertNotNull("The ramtable is not enabled", ramtable);
// reload ramtable
Whitebox.invoke(graph.getClass(), "reloadRamtable", graph);
GraphTraversal<Vertex, Vertex> vertices;
HugeVertex vertex;
GraphTraversal<Vertex, Edge> edges;
HugeEdge edge;
// A
vertices = g.V(1).out();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertFalse(vertex.isPropLoaded());
Assert.assertEquals(2L, vertex.id().asObject());
Assert.assertEquals("B", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(1).outE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertFalse(edge.isPropLoaded());
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("ab", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(1).in();
Assert.assertFalse(vertices.hasNext());
edges = g.V(1).inE();
Assert.assertFalse(edges.hasNext());
vertices = g.V(1).both();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(2L, vertex.id().asObject());
Assert.assertEquals("B", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(1).bothE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("ab", edge.value("name"));
Assert.assertFalse(edges.hasNext());
// B
vertices = g.V(2).out();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(3L, vertex.id().asObject());
Assert.assertEquals("C", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(4L, vertex.id().asObject());
Assert.assertEquals("D", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(2).outE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("bc", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("bd", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(2).in();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(1L, vertex.id().asObject());
Assert.assertEquals("A", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(2).inE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("ab", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(2).both();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(3L, vertex.id().asObject());
Assert.assertEquals("C", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(4L, vertex.id().asObject());
Assert.assertEquals("D", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(1L, vertex.id().asObject());
Assert.assertEquals("A", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(2).bothE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("bc", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("bd", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("ab", edge.value("name"));
Assert.assertFalse(edges.hasNext());
// C
vertices = g.V(3).out();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(4L, vertex.id().asObject());
Assert.assertEquals("D", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(5L, vertex.id().asObject());
Assert.assertEquals("E", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(3).outE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("cd", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("ce", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(3).in();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(2L, vertex.id().asObject());
Assert.assertEquals("B", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(3).inE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("bc", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(3).both();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(4L, vertex.id().asObject());
Assert.assertEquals("D", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(5L, vertex.id().asObject());
Assert.assertEquals("E", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(2L, vertex.id().asObject());
Assert.assertEquals("B", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(3).bothE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("cd", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("ce", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("bc", edge.value("name"));
Assert.assertFalse(edges.hasNext());
// D
vertices = g.V(4).out();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(5L, vertex.id().asObject());
Assert.assertEquals("E", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(4).outE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("de", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(4).in();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(2L, vertex.id().asObject());
Assert.assertEquals("B", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(3L, vertex.id().asObject());
Assert.assertEquals("C", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(6L, vertex.id().asObject());
Assert.assertEquals("F", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(4).inE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("bd", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("cd", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("fd", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(4).both();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(5L, vertex.id().asObject());
Assert.assertEquals("E", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(2L, vertex.id().asObject());
Assert.assertEquals("B", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(3L, vertex.id().asObject());
Assert.assertEquals("C", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(6L, vertex.id().asObject());
Assert.assertEquals("F", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(4).bothE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("de", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("bd", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("cd", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("fd", edge.value("name"));
Assert.assertFalse(edges.hasNext());
// E
vertices = g.V(5).out();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(6L, vertex.id().asObject());
Assert.assertEquals("F", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(5).outE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("ef", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(5).in();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(3L, vertex.id().asObject());
Assert.assertEquals("C", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(4L, vertex.id().asObject());
Assert.assertEquals("D", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(5).inE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("ce", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("de", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(5).both();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(6L, vertex.id().asObject());
Assert.assertEquals("F", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(3L, vertex.id().asObject());
Assert.assertEquals("C", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(4L, vertex.id().asObject());
Assert.assertEquals("D", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(5).bothE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("ef", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("ce", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("de", edge.value("name"));
Assert.assertFalse(edges.hasNext());
// F
vertices = g.V(6).out();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(4L, vertex.id().asObject());
Assert.assertEquals("D", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(6).outE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("fd", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(6).in();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(5L, vertex.id().asObject());
Assert.assertEquals("E", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(6).inE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("ef", edge.value("name"));
Assert.assertFalse(edges.hasNext());
vertices = g.V(6).both();
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(4L, vertex.id().asObject());
Assert.assertEquals("D", vertex.value("name"));
Assert.assertTrue(vertices.hasNext());
vertex = (HugeVertex) vertices.next();
Assert.assertEquals(5L, vertex.id().asObject());
Assert.assertEquals("E", vertex.value("name"));
Assert.assertFalse(vertices.hasNext());
edges = g.V(6).bothE();
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.OUT, edge.id().direction());
Assert.assertEquals("fd", edge.value("name"));
Assert.assertTrue(edges.hasNext());
edge = (HugeEdge) edges.next();
Assert.assertEquals(Directions.IN, edge.id().direction());
Assert.assertEquals("ef", edge.value("name"));
Assert.assertFalse(edges.hasNext());
}
Aggregations