Search in sources :

Example 61 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class TestGraph method initBasicVertexLabelV.

@Watched
private void initBasicVertexLabelV(IdStrategy idStrategy, String defaultVL) {
    SchemaManager schema = this.graph.schema();
    switch(idStrategy) {
        case CUSTOMIZE_STRING:
            this.isLastIdCustomized = true;
            schema.vertexLabel(defaultVL).properties("__id", "oid", "name", "state", "status", "some", "that", "any", "this", "lang", "b", "communityIndex", "test", "testing", "acl", "favoriteColor", "aKey", "age", "boolean", "float", "double", "string", "integer", "long", "myId", "location", "x", "y", "s", "n", "d", "f", "i", "l", "to-change", "to-remove", "to-keep", "old", "new", "gremlin.partitionGraphStrategy.partition", "color", "blah").nullableKeys("__id", "oid", "name", "state", "status", "some", "that", "any", "this", "lang", "b", "communityIndex", "test", "testing", "acl", "favoriteColor", "aKey", "age", "boolean", "float", "double", "string", "integer", "long", "myId", "location", "x", "y", "s", "n", "d", "f", "i", "l", "to-change", "to-remove", "to-keep", "old", "new", "gremlin.partitionGraphStrategy.partition", "color", "blah").useCustomizeStringId().ifNotExist().create();
            break;
        case AUTOMATIC:
            this.isLastIdCustomized = false;
            schema.vertexLabel(defaultVL).properties("__id", "oid", "name", "state", "status", "some", "that", "any", "this", "lang", "b", "communityIndex", "test", "testing", "acl", "favoriteColor", "aKey", "age", "boolean", "float", "double", "string", "integer", "long", "myId", "location", "x", "y", "s", "n", "d", "f", "i", "l", "to-change", "to-remove", "to-keep", "old", "new", "gremlin.partitionGraphStrategy.partition", "color", "blah").nullableKeys("__id", "oid", "name", "state", "status", "some", "that", "any", "this", "lang", "b", "communityIndex", "test", "testing", "acl", "favoriteColor", "aKey", "age", "boolean", "float", "double", "string", "integer", "long", "myId", "location", "x", "y", "s", "n", "d", "f", "i", "l", "to-change", "to-remove", "to-keep", "old", "new", "gremlin.partitionGraphStrategy.partition", "color", "blah").ifNotExist().create();
            break;
        default:
            throw new AssertionError("Only customize and automatic " + "is legal in tinkerpop tests");
    }
    schema.indexLabel("defaultVLBy__id").onV(defaultVL).by("__id").ifNotExist().create();
    schema.indexLabel("defaultVLByName").onV(defaultVL).by("name").ifNotExist().create();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 62 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class TestGraph method addVertex.

@Watched
@Override
public Vertex addVertex(Object... keyValues) {
    boolean needRedefineSchema = false;
    boolean hasId = false;
    IdStrategy idStrategy = IdStrategy.AUTOMATIC;
    String defaultVL = DEFAULT_VL;
    for (int i = 0; i < keyValues.length; i += 2) {
        if (keyValues[i] == null) {
            continue;
        }
        if (keyValues[i].equals(T.id)) {
            hasId = true;
        }
        if (keyValues[i].equals(T.label) && i + 1 < keyValues.length && "person".equals(keyValues[i + 1]) && this.loadedGraph == null && !this.autoPerson) {
            needRedefineSchema = true;
            defaultVL = "person";
        }
    }
    if (needRedefineSchema && this.loadedGraph == null) {
        this.clearSchema();
        this.tx().commit();
        this.initBasicSchema(idStrategy, defaultVL);
        this.tx().commit();
        if (!this.autoPerson && "person".equals(defaultVL) && idStrategy == IdStrategy.AUTOMATIC) {
            this.autoPerson = true;
        }
        this.isLastIdCustomized = idStrategy == IdStrategy.CUSTOMIZE_STRING;
    }
    if (!hasId && (this.isLastIdCustomized || needAddIdToLoadGraph())) {
        List<Object> kvs = new ArrayList<>(Arrays.asList(keyValues));
        kvs.add(T.id);
        kvs.add(String.valueOf(id++));
        keyValues = kvs.toArray();
    }
    return this.graph.addVertex(keyValues);
}
Also used : IdStrategy(com.baidu.hugegraph.type.define.IdStrategy) ArrayList(java.util.ArrayList) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 63 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class TestGraph method initBasicPropertyKey.

@Watched
private void initBasicPropertyKey() {
    SchemaManager schema = this.graph.schema();
    schema.propertyKey("__id").ifNotExist().create();
    schema.propertyKey("oid").asInt().ifNotExist().create();
    schema.propertyKey("communityIndex").asInt().ifNotExist().create();
    schema.propertyKey("test").ifNotExist().create();
    schema.propertyKey("testing").ifNotExist().create();
    schema.propertyKey("data").ifNotExist().create();
    schema.propertyKey("name").ifNotExist().create();
    schema.propertyKey("location").ifNotExist().create();
    schema.propertyKey("status").ifNotExist().create();
    schema.propertyKey("boolean").asBoolean().ifNotExist().create();
    schema.propertyKey("float").asFloat().ifNotExist().create();
    schema.propertyKey("since").asInt().ifNotExist().create();
    schema.propertyKey("double").asDouble().ifNotExist().create();
    schema.propertyKey("string").ifNotExist().create();
    schema.propertyKey("integer").asInt().ifNotExist().create();
    /*
         * The method shouldHaveStandardStringRepresentationForEdgeProperty()
         * in PropertyTest$BasicPropertyTest need 'short' property with
         * datatype String
         */
    schema.propertyKey("short").asText().ifNotExist().create();
    schema.propertyKey("x").asInt().ifNotExist().create();
    schema.propertyKey("y").asInt().ifNotExist().create();
    schema.propertyKey("age").asInt().ifNotExist().create();
    schema.propertyKey("lang").ifNotExist().create();
    schema.propertyKey("some").ifNotExist().create();
    schema.propertyKey("that").ifNotExist().create();
    schema.propertyKey("any").ifNotExist().create();
    schema.propertyKey("this").ifNotExist().create();
    schema.propertyKey("year").asInt().ifNotExist().create();
    schema.propertyKey("xxx").ifNotExist().create();
    schema.propertyKey("yyy").ifNotExist().create();
    schema.propertyKey("favoriteColor").ifNotExist().create();
    schema.propertyKey("uuid").asUUID().ifNotExist().create();
    schema.propertyKey("myId").asInt().ifNotExist().create();
    schema.propertyKey("myEdgeId").asInt().ifNotExist().create();
    schema.propertyKey("state").ifNotExist().create();
    schema.propertyKey("acl").ifNotExist().create();
    schema.propertyKey("stars").asInt().ifNotExist().create();
    schema.propertyKey("b").asBoolean().ifNotExist().create();
    schema.propertyKey("s").ifNotExist().create();
    schema.propertyKey("n").ifNotExist().create();
    schema.propertyKey("d").asDouble().ifNotExist().create();
    schema.propertyKey("f").asFloat().ifNotExist().create();
    schema.propertyKey("i").asInt().ifNotExist().create();
    schema.propertyKey("l").asLong().ifNotExist().create();
    schema.propertyKey("here").ifNotExist().create();
    schema.propertyKey("to-change").ifNotExist().create();
    schema.propertyKey("to-remove").ifNotExist().create();
    schema.propertyKey("to-keep").ifNotExist().create();
    schema.propertyKey("to-drop").ifNotExist().create();
    schema.propertyKey("dropped").ifNotExist().create();
    schema.propertyKey("not-dropped").ifNotExist().create();
    schema.propertyKey("old").ifNotExist().create();
    schema.propertyKey("new").ifNotExist().create();
    schema.propertyKey("color").ifNotExist().create();
    schema.propertyKey("every").ifNotExist().create();
    schema.propertyKey("gremlin.partitionGraphStrategy.partition").ifNotExist().create();
    schema.propertyKey("blah").asDouble().ifNotExist().create();
    schema.propertyKey("bloop").asInt().ifNotExist().create();
    if (!this.graph.existsPropertyKey("long")) {
        schema.propertyKey("long").asLong().ifNotExist().create();
    }
    if (!this.graph.existsPropertyKey("aKey")) {
        schema.propertyKey("aKey").asDouble().ifNotExist().create();
    }
    if (this.ioTest) {
        schema.propertyKey("weight").asFloat().ifNotExist().create();
    } else {
        schema.propertyKey("weight").asDouble().ifNotExist().create();
    }
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 64 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class TestGraph method initModernSchema.

@Watched
public void initModernSchema(IdStrategy idStrategy) {
    SchemaManager schema = this.graph.schema();
    schema.propertyKey("weight").asDouble().ifNotExist().create();
    schema.propertyKey("name").ifNotExist().create();
    schema.propertyKey("lang").ifNotExist().create();
    schema.propertyKey("age").asInt().ifNotExist().create();
    schema.propertyKey("year").asInt().ifNotExist().create();
    schema.propertyKey("acl").ifNotExist().create();
    schema.propertyKey("temp").ifNotExist().create();
    schema.propertyKey("peter").ifNotExist().create();
    schema.propertyKey("vadas").ifNotExist().create();
    schema.propertyKey("josh").ifNotExist().create();
    schema.propertyKey("marko").ifNotExist().create();
    schema.propertyKey("ripple").ifNotExist().create();
    schema.propertyKey("lop").ifNotExist().create();
    schema.propertyKey("test").ifNotExist().create();
    switch(idStrategy) {
        case AUTOMATIC:
            schema.vertexLabel("name").ifNotExist().create();
            schema.vertexLabel("person").properties("name", "age", "test").nullableKeys("name", "age", "test").ifNotExist().create();
            schema.vertexLabel("software").properties("name", "lang", "temp").nullableKeys("name", "lang", "temp").ifNotExist().create();
            schema.vertexLabel("dog").properties("name").nullableKeys("name").ifNotExist().create();
            schema.vertexLabel(DEFAULT_VL).properties("name", "age").nullableKeys("name", "age").ifNotExist().create();
            schema.vertexLabel("animal").properties("name", "age", "peter", "josh", "marko", "vadas", "ripple", "lop").nullableKeys("name", "age", "peter", "josh", "marko", "vadas", "ripple", "lop").ifNotExist().create();
            break;
        case CUSTOMIZE_STRING:
            schema.vertexLabel("person").properties("name", "age").nullableKeys("name", "age").useCustomizeStringId().ifNotExist().create();
            schema.vertexLabel("software").properties("name", "lang").nullableKeys("name", "lang").useCustomizeStringId().ifNotExist().create();
            schema.vertexLabel("dog").properties("name").nullableKeys("name").useCustomizeStringId().ifNotExist().create();
            schema.vertexLabel(DEFAULT_VL).properties("name", "age").nullableKeys("name", "age").useCustomizeStringId().ifNotExist().create();
            schema.vertexLabel("animal").properties("name", "age").nullableKeys("name", "age").useCustomizeStringId().ifNotExist().create();
            break;
        default:
            throw new AssertionError(String.format("Id strategy must be customize or automatic"));
    }
    schema.edgeLabel("knows").link("person", "person").properties("weight", "year").nullableKeys("weight", "year").ifNotExist().create();
    schema.edgeLabel("created").link("person", "software").properties("weight").nullableKeys("weight").ifNotExist().create();
    schema.edgeLabel("codeveloper").link("person", "person").properties("year").nullableKeys("year").ifNotExist().create();
    schema.edgeLabel("createdBy").link("software", "person").properties("weight", "year", "acl").nullableKeys("weight", "year", "acl").ifNotExist().create();
    schema.edgeLabel("uses").link("person", "software").ifNotExist().create();
    schema.edgeLabel("likes").link("person", "software").ifNotExist().create();
    schema.edgeLabel("foo").link("person", "software").ifNotExist().create();
    schema.edgeLabel("bar").link("person", "software").ifNotExist().create();
    schema.indexLabel("personByName").onV("person").by("name").ifNotExist().create();
    schema.indexLabel("personByAge").onV("person").by("age").range().ifNotExist().create();
    schema.indexLabel("softwareByName").onV("software").by("name").ifNotExist().create();
    schema.indexLabel("softwareByLang").onV("software").by("lang").ifNotExist().create();
    schema.indexLabel("dogByName").onV("dog").by("name").ifNotExist().create();
    schema.indexLabel("vertexByName").onV("vertex").by("name").ifNotExist().create();
    schema.indexLabel("vertexByAge").onV("vertex").by("age").range().ifNotExist().create();
    schema.indexLabel("knowsByWeight").onE("knows").by("weight").range().ifNotExist().create();
    schema.indexLabel("createdByWeight").onE("created").by("weight").range().ifNotExist().create();
    schema.indexLabel("personByNameAge").onV("person").by("name", "age").ifNotExist().create();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 65 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class TestGraphProvider method loadGraphData.

@Watched
public void loadGraphData(final Graph graph, final LoadGraphWith.GraphData loadGraphWith) {
    TestGraph testGraph = (TestGraph) graph;
    // Clear basic schema initiated in openTestGraph
    testGraph.clearAll("");
    if (testGraph.loadedGraph() == null) {
        testGraph.loadedGraph(REGULAR_LOAD);
    }
    boolean standard = testGraph.hugegraph().name().endsWith(STANDARD);
    IdStrategy idStrategy = standard && !testGraph.ioTest() ? IdStrategy.AUTOMATIC : IdStrategy.CUSTOMIZE_STRING;
    switch(loadGraphWith) {
        case GRATEFUL:
            testGraph.initGratefulSchema(idStrategy);
            break;
        case MODERN:
            testGraph.initModernSchema(idStrategy);
            break;
        case CLASSIC:
            testGraph.initClassicSchema(idStrategy);
            break;
        case CREW:
            break;
        case SINK:
            testGraph.initSinkSchema();
            break;
        default:
            throw new AssertionError(String.format("Only support GRATEFUL, MODERN and CLASSIC " + "for @LoadGraphWith(), but '%s' is used ", loadGraphWith));
    }
    LOG.debug("Load graph with {} schema", loadGraphWith);
    testGraph.tx().commit();
}
Also used : IdStrategy(com.baidu.hugegraph.type.define.IdStrategy) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)65 Id (com.baidu.hugegraph.backend.id.Id)30 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)9 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)8 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)7 ArrayList (java.util.ArrayList)7 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)5 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)5 IdHolder (com.baidu.hugegraph.backend.page.IdHolder)4 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)4 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)4 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)4 Query (com.baidu.hugegraph.backend.query.Query)4 SchemaJob (com.baidu.hugegraph.job.schema.SchemaJob)4 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)4 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4