use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class FileLoadTest method testMatchedEncodingCharset.
@Test
public void testMatchedEncodingCharset() {
ioUtil.write("vertex_software.csv", GBK, "name,lang,price", "lop,中文,328");
String[] args = new String[] { "-f", structPath("matched_encoding_charset/struct.json"), "-s", configPath("matched_encoding_charset/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2", "--test-mode", "true" };
HugeGraphLoader.main(args);
List<Vertex> vertices = CLIENT.graph().listVertices();
Assert.assertEquals(1, vertices.size());
Vertex vertex = vertices.get(0);
Assert.assertEquals("lop", vertex.property("name"));
Assert.assertEquals("中文", vertex.property("lang"));
Assert.assertEquals(328.0, vertex.property("price"));
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class FileLoadTest method testIgnoredFields.
@Test
public void testIgnoredFields() {
ioUtil.write("vertex_person.csv", "name,age,city,redundant", "marko,29,Beijing,value1", "vadas,27,Hongkong,value2");
String[] args = new String[] { "-f", structPath("ignored_fields/struct.json"), "-s", configPath("ignored_fields/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--test-mode", "true" };
HugeGraphLoader.main(args);
List<Vertex> vertices = CLIENT.graph().listVertices();
Assert.assertEquals(2, vertices.size());
for (Vertex vertex : vertices) {
Assert.assertEquals(3, vertex.properties().size());
Assert.assertFalse(vertex.properties().containsKey("redundant"));
}
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class ParseTaskBuilder method buildTask.
private ParseTask buildTask(ElementBuilder builder, List<Line> lines) {
final LoadMetrics metrics = this.context.summary().metrics(this.struct);
final int batchSize = this.context.options().batchSize;
final ElementMapping mapping = builder.mapping();
final boolean needRemoveId = builder instanceof VertexBuilder && ((VertexLabel) builder.schemaLabel()).idStrategy().isPrimaryKey();
return new ParseTask(mapping, () -> {
List<List<Record>> batches = new ArrayList<>();
// One batch record
List<Record> records = new ArrayList<>(batchSize);
int count = 0;
for (Line line : lines) {
try {
// NOTE: don't remove entry in keyValues
@SuppressWarnings("unchecked") List<GraphElement> elements = builder.build(line.names(), line.values());
E.checkState(elements.size() <= batchSize, "The number of columns in a line cannot " + "exceed the size of a batch, but got %s > %s", elements.size(), batchSize);
// Prevent batch size from exceeding limit
if (records.size() + elements.size() > batchSize) {
LOG.debug("Create a new batch for {}", mapping);
// Add current batch and create a new batch
batches.add(records);
records = new ArrayList<>(batchSize);
}
for (GraphElement element : elements) {
if (needRemoveId) {
((Vertex) element).id(null);
}
records.add(new Record(line.rawLine(), element));
count++;
}
} catch (IllegalArgumentException e) {
metrics.increaseParseFailure(mapping);
ParseException pe = new ParseException(line.rawLine(), e);
this.handleParseFailure(mapping, pe);
}
}
if (!records.isEmpty()) {
batches.add(records);
}
metrics.plusParseSuccess(mapping, count);
return batches;
});
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class FileLoadTest method testSingleInsertEdgeWithCheckVertexFalse.
@Test
public void testSingleInsertEdgeWithCheckVertexFalse() {
// The source and target vertex doesn't exist
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("single_insert_edge_with_check_vertex_false/struct.json"), "-s", configPath("single_insert_edge_with_check_vertex_false/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--check-vertex", "false", "--batch-insert-threads", "2", "--test-mode", "true" };
HugeGraphLoader.main(args);
List<Vertex> vertices = CLIENT.graph().listVertices();
List<Edge> edges = CLIENT.graph().listEdges();
Assert.assertEquals(0, vertices.size());
Assert.assertEquals(6, edges.size());
edges.forEach(edge -> {
Assert.assertThrows(ServerException.class, () -> {
CLIENT.graph().getVertex(edge.sourceId());
}, e -> {
ServerException se = (ServerException) e;
Assert.assertTrue(se.exception().contains("NotFoundException"));
});
Assert.assertThrows(ServerException.class, () -> {
CLIENT.graph().getVertex(edge.targetId());
}, e -> {
ServerException se = (ServerException) e;
Assert.assertTrue(se.exception().contains("NotFoundException"));
});
});
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class FileLoadTest method testUnmatchedEncodingCharset.
@Test
public void testUnmatchedEncodingCharset() {
ioUtil.write("vertex_software.csv", GBK, "name,lang,price", "lop,中文,328");
String[] args = new String[] { "-f", structPath("unmatched_encoding_charset/struct.json"), "-s", configPath("unmatched_encoding_charset/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2", "--test-mode", "true" };
HugeGraphLoader.main(args);
List<Vertex> vertices = CLIENT.graph().listVertices();
Assert.assertEquals(1, vertices.size());
Vertex vertex = vertices.get(0);
Assert.assertEquals("lop", vertex.property("name"));
Assert.assertNotEquals("中文", vertex.property("lang"));
Assert.assertEquals(328.0, vertex.property("price"));
}
Aggregations