use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class FileLoadTest method testCustomizedSchema.
@Test
public void testCustomizedSchema() {
ioUtil.write("vertex_person.csv", "name,age,city", "marko,29,Beijing", "vadas,27,Hongkong", "josh,32,Beijing", "peter,35,Shanghai", "\"li,nary\",26,\"Wu,han\"");
ioUtil.write("vertex_software.csv", GBK, "name,lang,price", "lop,java,328", "ripple,java,199");
ioUtil.write("edge_knows.csv", "source_name,target_name,date,weight", "marko,vadas,20160110,0.5", "marko,josh,20130220,1.0");
ioUtil.write("edge_created.csv", "source_name,target_name,date,weight", "marko,lop,20171210,0.4", "josh,lop,20091111,0.4", "josh,ripple,20171210,1.0", "peter,lop,20170324,0.2");
String[] args = new String[] { "-f", structPath("customized_schema/struct.json"), "-s", configPath("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(7, vertices.size());
Assert.assertEquals(6, edges.size());
boolean interestedVertex = false;
for (Vertex vertex : vertices) {
Assert.assertEquals(String.class, vertex.id().getClass());
if (((String) vertex.id()).contains("li,nary")) {
interestedVertex = true;
Assert.assertEquals(26, vertex.property("age"));
Assert.assertEquals("Wu,han", vertex.property("city"));
}
}
Assert.assertTrue(interestedVertex);
boolean interestedEdge = false;
for (Edge edge : edges) {
Assert.assertEquals(String.class, edge.sourceId().getClass());
Assert.assertEquals(String.class, edge.targetId().getClass());
if (((String) edge.sourceId()).contains("marko") && ((String) edge.targetId()).contains("vadas")) {
interestedEdge = true;
Assert.assertEquals("20160110", edge.property("date"));
Assert.assertEquals(0.5, edge.property("weight"));
}
}
Assert.assertTrue(interestedEdge);
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class FileLoadTest method testSkipStruct.
@Test
public void testSkipStruct() {
ioUtil.write("vertex_person.csv", "name,age,city", "marko,29,Beijing", "vadas,27,Hongkong", "josh,32,Beijing", "peter,35,Shanghai", "\"li,nary\",26,\"Wu,han\"");
ioUtil.write("vertex_software.csv", GBK, "name,lang,price", "lop,java,328", "ripple,java,199");
ioUtil.write("edge_knows.csv", "source_name,target_name,date,weight", "marko,vadas,20160110,0.5", "marko,josh,20130220,1.0");
ioUtil.write("edge_created.csv", "source_name,target_name,date,weight", "marko,lop,20171210,0.4", "josh,lop,20091111,0.4", "josh,ripple,20171210,1.0", "peter,lop,20170324,0.2");
String[] args = new String[] { "-f", structPath("skip_struct/struct.json"), "-s", configPath("skip_struct/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(7, vertices.size());
Assert.assertEquals(4, edges.size());
for (Edge edge : edges) {
Assert.assertEquals("created", edge.label());
}
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class InsertTask method insertBatch.
@SuppressWarnings("unchecked")
protected void insertBatch(List<Record> batch, boolean checkVertex) {
HugeClient client = this.context.client();
List<GraphElement> elements = new ArrayList<>(batch.size());
batch.forEach(r -> elements.add(r.element()));
if (this.type().isVertex()) {
client.graph().addVertices((List<Vertex>) (Object) elements);
} else {
client.graph().addEdges((List<Edge>) (Object) elements, checkVertex);
}
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadGremlinPathWithVertexAndEdge.
@Test
public void testReadGremlinPathWithVertexAndEdge() {
String json = "{" + "\"requestId\": \"238c74ca-18f7-4377-b8e1-2bb3b165e5d6\"," + "\"status\":{" + "\"message\": \"\"," + "\"code\": 200," + "\"attributes\":{}" + "}," + "\"result\":{" + "\"data\":[" + "{" + "\"labels\":[[], []]," + "\"objects\":[" + "{" + "\"id\": \"person:marko\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\":{" + "\"city\":\"Beijing\"," + "\"name\":\"marko\"," + "\"age\":29" + "}" + "}," + "{" + "\"id\": \"person:marko>knows>>person:vadas\"," + "\"label\": \"knows\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"person\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"person:vadas\"," + "\"outV\": \"person:marko\"," + "\"properties\":{" + "\"date\": 1452355200000," + "\"weight\": 0.5" + "}" + "}" + "]" + "}" + "]," + "\"meta\":{" + "}" + "}" + "}";
Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
RestResult restResult = new RestResult(this.mockResponse);
Assert.assertEquals(200, restResult.status());
Assert.assertNull(restResult.headers());
Response response = restResult.readObject(Response.class);
response.graphManager(graph());
Assert.assertEquals(200, response.status().code());
Iterator<Result> results = response.result().iterator();
Assert.assertTrue(results.hasNext());
Result result = results.next();
Object object = result.getObject();
Assert.assertEquals(Path.class, object.getClass());
Path path = (Path) object;
Assert.assertEquals(2, path.labels().size());
Assert.assertEquals(ImmutableList.of(), path.labels().get(0));
Assert.assertEquals(ImmutableList.of(), path.labels().get(1));
Vertex vertex = new Vertex("person");
vertex.id("person:marko");
vertex.property("name", "marko");
vertex.property("age", 29);
vertex.property("city", "Beijing");
Edge edge = new Edge("knows");
edge.id("person:marko>knows>>person:vadas");
edge.sourceId("person:marko");
edge.sourceLabel("person");
edge.targetId("person:vadas");
edge.targetLabel("person");
edge.property("date", 1452355200000L);
edge.property("weight", 0.5);
Assert.assertEquals(2, path.objects().size());
Utils.assertGraphEqual(ImmutableList.of(vertex), ImmutableList.of(edge), path.objects());
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadGremlinEdges.
@Test
public void testReadGremlinEdges() {
String json = "{" + "\"requestId\": \"cd4cfc17-1ee4-4e9e-af40-cb18b115a8dc\"," + "\"status\": {" + "\"message\": \"\"," + "\"code\": 200," + "\"attributes\": {}" + "}," + "\"result\": {" + "\"data\": [" + "{" + "\"id\": \"person:peter>created>>software:lop\"," + "\"label\": \"created\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"software\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"software:lop\"," + "\"outV\": \"person:peter\"," + "\"properties\": {" + "\"date\": 1490284800000," + "\"weight\": 0.2" + "}" + "}," + "{" + "\"id\": \"person:peter>knows>>person:marko\"," + "\"label\": \"knows\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"person\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"person:marko\"," + "\"outV\": \"person:peter\"," + "\"properties\": {" + "\"date\": 1452355200000," + "\"weight\": 0.5" + "}" + "}" + "]," + "\"meta\": {}" + "}" + "}";
Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
RestResult restResult = new RestResult(this.mockResponse);
Assert.assertEquals(200, restResult.status());
Assert.assertNull(restResult.headers());
Response response = restResult.readObject(Response.class);
response.graphManager(graph());
Assert.assertEquals(200, response.status().code());
Edge created = new Edge("created");
created.id("person:peter>created>>software:lop");
created.sourceId("person:peter");
created.targetId("software:lop");
created.sourceLabel("person");
created.targetLabel("software");
created.property("date", 1490284800000L);
created.property("weight", 0.2);
Edge knows = new Edge("knows");
knows.id("person:peter>knows>>person:marko");
knows.sourceId("person:peter");
knows.targetId("person:marko");
knows.sourceLabel("person");
knows.targetLabel("person");
knows.property("date", 1452355200000L);
knows.property("weight", 0.5);
List<Edge> edges = new ArrayList<>(2);
edges.add(created);
edges.add(knows);
Iterator<Result> results = response.result().iterator();
while (results.hasNext()) {
Result result = results.next();
Assert.assertEquals(Edge.class, result.getObject().getClass());
Edge edge = result.getEdge();
Assert.assertTrue(Utils.contains(edges, edge));
}
}
Aggregations