Search in sources :

Example 26 with Vertex

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"));
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Example 27 with Vertex

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"));
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Example 28 with Vertex

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;
    });
}
Also used : ElementMapping(com.baidu.hugegraph.loader.mapping.ElementMapping) Vertex(com.baidu.hugegraph.structure.graph.Vertex) ArrayList(java.util.ArrayList) LoadMetrics(com.baidu.hugegraph.loader.metrics.LoadMetrics) Line(com.baidu.hugegraph.loader.reader.line.Line) VertexBuilder(com.baidu.hugegraph.loader.builder.VertexBuilder) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) GraphElement(com.baidu.hugegraph.structure.GraphElement) ArrayList(java.util.ArrayList) List(java.util.List) Record(com.baidu.hugegraph.loader.builder.Record) ParseException(com.baidu.hugegraph.loader.exception.ParseException)

Example 29 with Vertex

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"));
        });
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ServerException(com.baidu.hugegraph.exception.ServerException) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 30 with Vertex

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"));
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Aggregations

Vertex (com.baidu.hugegraph.structure.graph.Vertex)165 Test (org.junit.Test)110 Edge (com.baidu.hugegraph.structure.graph.Edge)33 HugeClient (com.baidu.hugegraph.driver.HugeClient)22 ArrayList (java.util.ArrayList)21 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)18 BaseClientTest (com.baidu.hugegraph.BaseClientTest)17 BeforeClass (org.junit.BeforeClass)17 GraphManager (com.baidu.hugegraph.driver.GraphManager)14 BatchVertexRequest (com.baidu.hugegraph.structure.graph.BatchVertexRequest)13 Path (com.baidu.hugegraph.structure.graph.Path)11 Result (com.baidu.hugegraph.structure.gremlin.Result)10 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)10 List (java.util.List)10 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)9 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Map (java.util.Map)6 RestResult (com.baidu.hugegraph.rest.RestResult)5 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)5