Search in sources :

Example 41 with SchemaManager

use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.

the class VertexCoreTest method testQueryByUnionIndexInPageWithSomeIndexNoData.

@Test
public void testQueryByUnionIndexInPageWithSomeIndexNoData() {
    Assume.assumeTrue("Not support paging", storeFeatures().supportsQueryByPage());
    HugeGraph graph = graph();
    SchemaManager schema = graph.schema();
    GraphTraversalSource g = graph.traversal();
    initPageTestData();
    // Author has index by name but no data
    schema.indexLabel("authorByName").onV("author").by("name").secondary().ifNotExist().create();
    GraphTraversal<Vertex, Vertex> iter = g.V().has("name", "marko").has("~page", "").limit(1);
    Assert.assertEquals(1, IteratorUtils.count(iter));
    String page = TraversalUtil.page(iter);
    List<Vertex> vertices;
    vertices = g.V().has("name", "marko").has("~page", page).limit(1).toList();
    Assert.assertEquals(1, vertices.size());
    Vertex vertex1 = vertices.get(0);
    vertices = g.V().has("name", "marko").has("~page", page).limit(9).toList();
    Assert.assertEquals(9, vertices.size());
    Assert.assertTrue(vertices.contains(vertex1));
    vertices = g.V().has("name", "marko").has("~page", page).limit(18).toList();
    Assert.assertEquals(18, vertices.size());
    Vertex vertex3 = vertices.get(17);
    vertices = g.V().has("name", "marko").has("~page", page).limit(40).toList();
    Assert.assertEquals(33, vertices.size());
    Assert.assertTrue(vertices.contains(vertex3));
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) FakeVertex(com.baidu.hugegraph.testutil.FakeObjects.FakeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 42 with SchemaManager

use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.

the class VertexCoreTest method testAddVertexWithAutomaticIdStrategy.

@Test
public void testAddVertexWithAutomaticIdStrategy() {
    HugeGraph graph = graph();
    SchemaManager schema = graph.schema();
    // May be set forceString=true by config
    Whitebox.setInternalState(SnowflakeIdGenerator.instance(graph), "forceString", false);
    schema.vertexLabel("programmer").useAutomaticId().properties("name", "age", "city").create();
    Vertex v1 = graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
    this.mayCommitTx();
    List<Vertex> vertices = graph.traversal().V().toList();
    Assert.assertEquals(1, vertices.size());
    assertContains(vertices, T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
    Vertex v2 = graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
    this.mayCommitTx();
    Assert.assertNotEquals(v1.id(), v2.id());
    vertices = graph.traversal().V().toList();
    Assert.assertEquals(2, vertices.size());
    vertices = graph.traversal().V(v2.id()).toList();
    Assert.assertEquals(1, vertices.size());
    assertContains(vertices, T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing");
}
Also used : FakeVertex(com.baidu.hugegraph.testutil.FakeObjects.FakeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 43 with SchemaManager

use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.

the class HugeGraphAuthProxy method schema.

@Override
public SchemaManager schema() {
    SchemaManager schema = this.hugegraph.schema();
    schema.proxy(this);
    return schema;
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager)

Example 44 with SchemaManager

use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.

the class TestGraph method initClassicSchema.

@Watched
public void initClassicSchema(IdStrategy idStrategy) {
    SchemaManager schema = this.graph.schema();
    schema.propertyKey("id").asInt().ifNotExist().create();
    schema.propertyKey("weight").asFloat().ifNotExist().create();
    schema.propertyKey("name").ifNotExist().create();
    schema.propertyKey("lang").ifNotExist().create();
    schema.propertyKey("age").asInt().ifNotExist().create();
    switch(idStrategy) {
        case AUTOMATIC:
            schema.vertexLabel("vertex").properties("id", "name", "age", "lang").nullableKeys("id", "name", "age", "lang").ifNotExist().create();
            break;
        case CUSTOMIZE_STRING:
            schema.vertexLabel("vertex").properties("id", "name", "age", "lang").nullableKeys("id", "name", "age", "lang").useCustomizeStringId().ifNotExist().create();
            break;
        default:
            throw new AssertionError(String.format("Id strategy must be customize or automatic"));
    }
    schema.edgeLabel("knows").link("vertex", "vertex").properties("weight").nullableKeys("weight").ifNotExist().create();
    schema.edgeLabel("created").link("vertex", "vertex").properties("weight").nullableKeys("weight").ifNotExist().create();
    schema.indexLabel("vertexByName").onV("vertex").by("name").secondary().ifNotExist().create();
    schema.indexLabel("vertexByAge").onV("vertex").by("age").range().ifNotExist().create();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 45 with SchemaManager

use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.

the class TestGraph method initEdgeLabelPersonKnowsPerson.

public void initEdgeLabelPersonKnowsPerson() {
    SchemaManager schema = this.graph.schema();
    schema.edgeLabel("knows").link("person", "person").properties("weight").nullableKeys("weight").ifNotExist().create();
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager)

Aggregations

SchemaManager (com.baidu.hugegraph.schema.SchemaManager)261 Test (org.junit.Test)227 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)90 HugeGraph (com.baidu.hugegraph.HugeGraph)76 FakeVertex (com.baidu.hugegraph.testutil.FakeObjects.FakeVertex)40 Edge (org.apache.tinkerpop.gremlin.structure.Edge)30 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)27 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)22 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)20 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)19 FakeEdge (com.baidu.hugegraph.testutil.FakeObjects.FakeEdge)19 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)15 Id (com.baidu.hugegraph.backend.id.Id)12 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)7 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)7 Date (java.util.Date)6 Before (org.junit.Before)6 HashSet (java.util.HashSet)3 HugeException (com.baidu.hugegraph.HugeException)2