Search in sources :

Example 11 with RelationTypeIndex

use of org.janusgraph.core.schema.RelationTypeIndex in project janusgraph by JanusGraph.

the class JanusGraphTest method testSchemaNameChange.

@Test
public void testSchemaNameChange() {
    PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
    EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make();
    mgmt.buildEdgeIndex(knows, "byTime", Direction.BOTH, time);
    mgmt.buildIndex("timeIndex", Vertex.class).addKey(time).buildCompositeIndex();
    mgmt.makeVertexLabel("people").make();
    finishSchema();
    // CREATE SMALL GRAPH
    JanusGraphVertex v = tx.addVertex("people");
    v.property(VertexProperty.Cardinality.single, "time", 5);
    v.addEdge("knows", v, "time", 11);
    newTx();
    v = Iterables.getOnlyElement(tx.query().has("time", 5).vertices());
    assertNotNull(v);
    assertEquals("people", v.label());
    assertEquals(5, v.<Integer>value("time").intValue());
    assertCount(1, v.query().direction(Direction.IN).labels("knows").edges());
    assertCount(1, v.query().direction(Direction.OUT).labels("knows").has("time", 11).edges());
    newTx();
    // UPDATE SCHEMA NAMES
    assertTrue(mgmt.containsRelationType("knows"));
    knows = mgmt.getEdgeLabel("knows");
    mgmt.changeName(knows, "know");
    assertEquals("know", knows.name());
    assertTrue(mgmt.containsRelationIndex(knows, "byTime"));
    RelationTypeIndex byTimeIndex = mgmt.getRelationIndex(knows, "byTime");
    assertEquals("byTime", byTimeIndex.name());
    mgmt.changeName(byTimeIndex, "overTime");
    assertEquals("overTime", byTimeIndex.name());
    assertTrue(mgmt.containsVertexLabel("people"));
    VertexLabel vl = mgmt.getVertexLabel("people");
    mgmt.changeName(vl, "person");
    assertEquals("person", vl.name());
    assertTrue(mgmt.containsGraphIndex("timeIndex"));
    JanusGraphIndex graphIndex = mgmt.getGraphIndex("timeIndex");
    mgmt.changeName(graphIndex, "byTime");
    assertEquals("byTime", graphIndex.name());
    finishSchema();
    // VERIFY UPDATES IN MANAGEMENT SYSTEM
    assertTrue(mgmt.containsRelationType("know"));
    assertFalse(mgmt.containsRelationType("knows"));
    knows = mgmt.getEdgeLabel("know");
    assertTrue(mgmt.containsRelationIndex(knows, "overTime"));
    assertFalse(mgmt.containsRelationIndex(knows, "byTime"));
    assertTrue(mgmt.containsVertexLabel("person"));
    assertFalse(mgmt.containsVertexLabel("people"));
    assertTrue(mgmt.containsGraphIndex("byTime"));
    assertFalse(mgmt.containsGraphIndex("timeIndex"));
    // VERIFY UPDATES IN TRANSACTION
    newTx();
    v = Iterables.getOnlyElement(tx.query().has("time", 5).vertices());
    assertNotNull(v);
    assertEquals("person", v.label());
    assertEquals(5, v.<Integer>value("time").intValue());
    assertCount(1, v.query().direction(Direction.IN).labels("know").edges());
    assertCount(0, v.query().direction(Direction.IN).labels("knows").edges());
    assertCount(1, v.query().direction(Direction.OUT).labels("know").has("time", 11).edges());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.Test)

Aggregations

RelationTypeIndex (org.janusgraph.core.schema.RelationTypeIndex)11 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)7 PropertyKey (org.janusgraph.core.PropertyKey)6 Test (org.junit.Test)5 EdgeLabel (org.janusgraph.core.EdgeLabel)4 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)4 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)3 RelationType (org.janusgraph.core.RelationType)3 ScanMetrics (org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics)3 JanusGraphSchemaVertex (org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 JanusGraphException (org.janusgraph.core.JanusGraphException)2 VertexLabel (org.janusgraph.core.VertexLabel)2 SchemaStatus (org.janusgraph.core.schema.SchemaStatus)2 BackendException (org.janusgraph.diskstorage.BackendException)2 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)2 IndexRemoveJob (org.janusgraph.graphdb.olap.job.IndexRemoveJob)2 CompositeIndexType (org.janusgraph.graphdb.types.CompositeIndexType)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Instant (java.time.Instant)1