use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class GraphService method updateVertex.
public Vertex updateVertex(int connId, VertexEntity entity) {
HugeClient client = this.client(connId);
GraphManager graph = client.graph();
Vertex vertex = this.buildVertex(connId, entity);
// TODO: client should add updateVertex() method
return graph.addVertex(vertex);
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class GraphService method addEdge.
public GraphView addEdge(int connId, EdgeEntity entity) {
HugeClient client = this.client(connId);
GraphManager graph = client.graph();
EdgeHolder edgeHolder = this.buildEdge(connId, entity);
Edge edge = graph.addEdge(edgeHolder.edge);
Vertex source = edgeHolder.source;
Vertex target = edgeHolder.target;
return GraphView.builder().vertices(ImmutableSet.of(source, target)).edges(ImmutableSet.of(edge)).build();
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class EdgeBuilder method build.
@Override
public List<Edge> build(String[] names, Object[] values) {
if (this.vertexIdsIndex == null || !Arrays.equals(this.lastNames, names)) {
this.vertexIdsIndex = this.extractVertexIdsIndex(names);
}
this.lastNames = names;
EdgeKVPairs kvPairs = this.newEdgeKVPairs();
kvPairs.source.extractFromEdge(names, values, this.vertexIdsIndex.sourceIndexes);
kvPairs.target.extractFromEdge(names, values, this.vertexIdsIndex.targetIndexes);
kvPairs.extractProperties(names, values);
List<Vertex> sources = kvPairs.source.buildVertices(false);
List<Vertex> targets = kvPairs.target.buildVertices(false);
if (sources.isEmpty() || targets.isEmpty()) {
return ImmutableList.of();
}
E.checkArgument(sources.size() == 1 || targets.size() == 1 || sources.size() == targets.size(), "The elements number of source and target must be: " + "1 to n, n to 1, n to n");
int size = Math.max(sources.size(), targets.size());
List<Edge> edges = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
Vertex source = i < sources.size() ? sources.get(i) : sources.get(0);
Vertex target = i < targets.size() ? targets.get(i) : targets.get(0);
Edge edge = new Edge(this.mapping.label());
edge.source(source);
edge.target(target);
// Add properties
this.addProperties(edge, kvPairs.properties);
this.checkNonNullableKeys(edge);
edges.add(edge);
}
return edges;
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class GraphManager method addVertex.
public Vertex addVertex(String label, Object id, Map<String, Object> properties) {
Vertex vertex = new Vertex(label);
vertex.id(id);
this.attachProperties(vertex, properties);
return this.addVertex(vertex);
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class JDBCLoadTest method testCustomizedSchema.
@Test
public void testCustomizedSchema() {
dbUtil.insert("INSERT INTO `person` VALUES " + "(1,'marko',29,'Beijing')," + "(2,'vadas',27,'HongKong')," + "(3,'josh',32,'Beijing')," + "(4,'peter',35,'Shanghai')," + "(5,'li,nary',26,'Wu,han')," + "(6,'tom',NULL,NULL);");
dbUtil.insert("INSERT INTO `software` VALUES " + "(100,'lop','java',328.00)," + "(200,'ripple','java',199.00);");
dbUtil.insert("INSERT INTO `knows` VALUES " + "(1,1,2,'2016-01-10',0.50)," + "(2,1,3,'2013-02-20',1.00);");
dbUtil.insert("INSERT INTO `created` VALUES " + "(1,1,100,'2017-12-10',0.40)," + "(2,3,100,'2009-11-11',0.40)," + "(3,3,200,'2017-12-10',1.00)," + "(4,4,100,'2017-03-24',0.20);");
String[] args = new String[] { "-f", configPath("jdbc_customized_schema/struct.json"), "-s", configPath("jdbc_customized_schema/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2", "--test-mode", "true" };
HugeGraphLoader.main(args);
List<Vertex> vertices = CLIENT.graph().listVertices();
List<Edge> edges = CLIENT.graph().listEdges();
Assert.assertEquals(8, vertices.size());
Assert.assertEquals(6, edges.size());
for (Vertex vertex : vertices) {
Assert.assertEquals(Integer.class, vertex.id().getClass());
}
for (Edge edge : edges) {
Assert.assertEquals(Integer.class, edge.sourceId().getClass());
Assert.assertEquals(Integer.class, edge.targetId().getClass());
}
}
Aggregations