@Test public void testIndexShouldNotBeEnabledForExistingPropertyKeyAndConstrainedToExistingEdgeLabel() { mgmt.makePropertyKey("alreadyExistingProperty").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("alreadyExistingLabel").make(); finishSchema(); PropertyKey existingPropertyKey = mgmt.getPropertyKey("alreadyExistingProperty"); EdgeLabel existingLabel = mgmt.getEdgeLabel("alreadyExistingLabel"); mgmt.buildIndex("newIndex", Edge.class).addKey(existingPropertyKey).indexOnly(existingLabel).buildCompositeIndex(); finishSchema(); assertNotEquals(SchemaStatus.ENABLED, mgmt.getGraphIndex("newIndex").getIndexStatus(existingPropertyKey)); }
@Test public void testIndexQueryWithScore() throws InterruptedException { final PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make(); mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX); mgmt.commit(); final JanusGraphVertex v1 = tx.addVertex(); final JanusGraphVertex v2 = tx.addVertex(); final JanusGraphVertex v3 = tx.addVertex(); v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello world"); v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf"); v3.property("text", "Hello Hello world world"); tx.commit(); final Set<Double> scores = graph.indexQuery("store1", "v.text:(Hello)").vertexStream() .map(JanusGraphIndexQuery.Result::getScore) .collect(Collectors.toSet()); Assert.assertEquals(3, scores.size()); }
@Test public void testVertexTTLWithCompositeIndex() throws Exception { if (!features.hasCellTTL()) { return; } PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make(); final JanusGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name) .buildCompositeIndex(); final JanusGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time) .buildCompositeIndex(); VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(1)); assertEquals(Duration.ZERO, mgmt.getTTL(name)); assertEquals(Duration.ZERO, mgmt.getTTL(time)); assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1)); mgmt.commit(); JanusGraphVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis()); tx.commit(); Object id = v1.id(); v1 = getV(graph, id); assertNotNull(v1); assertNotEmpty(graph.query().has("name", "some event").vertices()); Thread.sleep(1001); graph.tx().rollback(); v1 = getV(graph, id); assertNull(v1); assertEmpty(graph.query().has("name", "some event").vertices()); }
public JanusGraphIndex getExternalIndex(Class<? extends Element> clazz, String backingIndex) { String prefix; if (Vertex.class.isAssignableFrom(clazz)) prefix = "v"; else if (Edge.class.isAssignableFrom(clazz)) prefix = "e"; else if (JanusGraphVertexProperty.class.isAssignableFrom(clazz)) prefix = "p"; else throw new AssertionError(clazz.toString()); final String indexName = prefix+backingIndex; JanusGraphIndex index = mgmt.getGraphIndex(indexName); if (index==null) { index = mgmt.buildIndex(indexName,clazz).buildMixedIndex(backingIndex); } return index; }
private void createStrictSchemaForComplexConnections() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); VertexLabel v1 = mgmt.makeVertexLabel("V1").make(); VertexLabel v2 = mgmt.makeVertexLabel("V2").make(); VertexLabel v3 = mgmt.makeVertexLabel("V3").make(); VertexLabel v4 = mgmt.makeVertexLabel("V4").make(); EdgeLabel e1 = mgmt.makeEdgeLabel("E1").make(); EdgeLabel e2 = mgmt.makeEdgeLabel("E2").make(); mgmt.addConnection(e1, v1, v2); mgmt.addConnection(e1, v3, v4); mgmt.addConnection(e2, v1, v4); mgmt.addConnection(e2, v3, v2); finishSchema(); }
@Test(expected = IllegalArgumentException.class) public void testSettingTTLOnNonStaticVertexLabel() { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } VertexLabel label1 = mgmt.makeVertexLabel("event").make(); mgmt.setTTL(label1, Duration.ofSeconds(42)); }
PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make(); PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SET).make(); EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make(); PropertyKey sensor = mgmt.makePropertyKey("sensor").dataType(Double.class).cardinality(Cardinality.LIST).make(); finishSchema(); sensor = mgmt.getPropertyKey("sensor"); time = mgmt.getPropertyKey("time"); name = mgmt.getPropertyKey("name"); friend = mgmt.getEdgeLabel("friend"); mgmt.buildPropertyIndex(sensor, "byTime", decr, time); mgmt.buildEdgeIndex(friend, "byTime", Direction.OUT, decr, time); mgmt.buildIndex("bySensorReading", Vertex.class).addKey(name).buildCompositeIndex(); finishSchema(); newTx(); pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime"); eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime"); graphIndex = mgmt.getGraphIndex("bySensorReading"); try { mgmt.updateIndex(pindex, SchemaAction.ENABLE_INDEX); fail(); } catch (IllegalArgumentException ignored) { mgmt.updateIndex(eindex, SchemaAction.ENABLE_INDEX); fail(); } catch (IllegalArgumentException ignored) { mgmt.updateIndex(graphIndex, SchemaAction.ENABLE_INDEX);
@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(); 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());
JanusGraphTransaction tx2; mgmt.makePropertyKey("name").dataType(String.class).make(); finishSchema(); mgmt.buildIndex("theIndex", Vertex.class).addKey(mgmt.getPropertyKey("name")).buildCompositeIndex(); mgmt.commit(); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX); Set<String> openInstances = mgmt.getOpenInstances(); assertEquals(2, openInstances.size()); assertTrue(openInstances.contains(graph.getConfiguration().getUniqueGraphId() + "(current)")); assertTrue(openInstances.contains(graph2.getConfiguration().getUniqueGraphId())); try { mgmt.forceCloseInstance(graph.getConfiguration().getUniqueGraphId()); mgmt.forceCloseInstance(graph2.getConfiguration().getUniqueGraphId()); mgmt.commit(); assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "theIndex").status(SchemaStatus.REGISTERED) .timeout(TestGraphConfigs.getSchemaConvergenceTime(ChronoUnit.SECONDS), ChronoUnit.SECONDS) .call().getSucceeded()); finishSchema(); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX); finishSchema();
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SET).make(); PropertyKey value = mgmt.makePropertyKey("value").dataType(Double.class).signature(weight).cardinality(Cardinality.LIST).make(); EdgeLabel friend = mgmt.makeEdgeLabel("friend").make(); EdgeLabel link = mgmt.makeEdgeLabel("link").unidirected().multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(uid).multiplicity(Multiplicity.SIMPLE).make(); EdgeLabel parent = mgmt.makeEdgeLabel("parent").multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel child = mgmt.makeEdgeLabel("child").multiplicity(Multiplicity.ONE2MANY).make(); EdgeLabel spouse = mgmt.makeEdgeLabel("spouse").multiplicity(Multiplicity.ONE2ONE).make(); VertexLabel person = mgmt.makeVertexLabel("person").make(); VertexLabel tag = mgmt.makeVertexLabel("tag").make(); VertexLabel tweet = mgmt.makeVertexLabel("tweet").setStatic().make(); assertTrue(mgmt.isOpen()); assertEquals("weight", weight.toString()); assertTrue(mgmt.containsRelationType("weight")); assertTrue(mgmt.containsPropertyKey("weight")); assertFalse(mgmt.containsEdgeLabel("weight")); assertTrue(mgmt.containsEdgeLabel("connect")); assertFalse(mgmt.containsPropertyKey("connect")); assertFalse(mgmt.containsRelationType("bla")); assertNull(mgmt.getPropertyKey("bla")); assertNull(mgmt.getEdgeLabel("bla")); assertNotNull(mgmt.getPropertyKey("weight"));
private void createIndexIfDoesNotExist(String indexName, String propertyKeyName, Class dataType,boolean unique) { graph.tx().rollback(); JanusGraphManagement management = graph.openManagement(); if (null == management.getGraphIndex(indexName)) { final PropertyKey key; boolean propertyKeyAlreadyExisted = false; if (null == management.getPropertyKey(propertyKeyName)) { key = management.makePropertyKey(propertyKeyName).dataType(dataType).make(); key = management.getPropertyKey(propertyKeyName); propertyKeyAlreadyExisted = true; if (unique) index = management.buildIndex(indexName, Vertex.class).addKey(key).unique().buildCompositeIndex(); else index = management.buildIndex(indexName, Vertex.class).addKey(key).buildCompositeIndex(); try { if (index.getIndexStatus(key) == INSTALLED) { management.commit(); ManagementSystem.awaitGraphIndexStatus(graph, indexName).call(); management = graph.openManagement(); if (propertyKeyAlreadyExisted) { management.updateIndex(management.getGraphIndex(indexName), REINDEX).get(); } else { management.updateIndex(management.getGraphIndex(indexName), ENABLE_INDEX).get(); management.updateIndex(management.getGraphIndex(indexName), REINDEX).get(); } else { management.updateIndex(management.getGraphIndex(indexName), ENABLE_INDEX).get(); e.toString() );
final PropertyKey name = management.makePropertyKey("name").dataType(String.class).make(); JanusGraphManagement.IndexBuilder nameIndexBuilder = management.buildIndex("name", Vertex.class).addKey(name); if (uniqueNameCompositeIndex) nameIndexBuilder.unique(); JanusGraphIndex nameIndex = nameIndexBuilder.buildCompositeIndex(); management.setConsistency(nameIndex, ConsistencyModifier.LOCK); final PropertyKey age = management.makePropertyKey("age").dataType(Integer.class).make(); if (null != mixedIndexName) management.buildIndex("vertices", Vertex.class).addKey(age).buildMixedIndex(mixedIndexName); final PropertyKey time = management.makePropertyKey("time").dataType(Integer.class).make(); final PropertyKey reason = management.makePropertyKey("reason").dataType(String.class).make(); final PropertyKey place = management.makePropertyKey("place").dataType(Geoshape.class).make(); if (null != mixedIndexName) management.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName); management.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); management.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel battled = management.makeEdgeLabel("battled").signature(time).make(); management.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time); management.makeEdgeLabel("lives").signature(reason).make(); management.makeEdgeLabel("pet").make(); management.makeEdgeLabel("brother").make(); management.makeVertexLabel("titan").make(); management.makeVertexLabel("location").make(); management.makeVertexLabel("god").make(); management.makeVertexLabel("demigod").make(); management.makeVertexLabel("human").make();
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.LIST).make(); EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(weight).make(); EdgeLabel related = mgmt.makeEdgeLabel("related").signature(time).make(); VertexLabel person = mgmt.makeVertexLabel("person").make(); VertexLabel organization = mgmt.makeVertexLabel("organization").make(); JanusGraphIndex edge1 = mgmt.buildIndex("edge1", Edge.class).addKey(time).addKey(weight).buildCompositeIndex(); JanusGraphIndex edge2 = mgmt.buildIndex("edge2", Edge.class) .indexOnly(connect).addKey(text).buildCompositeIndex(); JanusGraphIndex prop1 = mgmt.buildIndex("prop1", JanusGraphVertexProperty.class) .addKey(time).buildCompositeIndex(); JanusGraphIndex prop2 = mgmt.buildIndex("prop2", JanusGraphVertexProperty.class) .addKey(weight).addKey(text).buildCompositeIndex(); JanusGraphIndex vertex1 = mgmt.buildIndex("vertex1", Vertex.class).addKey(time) .indexOnly(person).unique().buildCompositeIndex(); JanusGraphIndex vertex12 = mgmt.buildIndex("vertex12", Vertex.class).addKey(text) .indexOnly(person).buildCompositeIndex(); JanusGraphIndex vertex2 = mgmt.buildIndex("vertex2", Vertex.class).addKey(time).addKey(name) .indexOnly(organization).buildCompositeIndex(); JanusGraphIndex vertex3 = mgmt.buildIndex("vertex3", Vertex.class).addKey(name).buildCompositeIndex(); assertTrue(mgmt.containsRelationType("name")); assertTrue(mgmt.containsGraphIndex("prop1")); assertFalse(mgmt.containsGraphIndex("prop3")); assertEquals(2, Iterables.size(mgmt.getGraphIndexes(Edge.class))); assertEquals(2, Iterables.size(mgmt.getGraphIndexes(JanusGraphVertexProperty.class)));
private GraphTraversalSource prepareGraphForDirectCommitTests() { clopen(option(AUTO_TYPE), "none", option(SCHEMA_CONSTRAINTS), true); GraphTraversalSource g = graph.traversal(); VertexLabel user = mgmt.makeVertexLabel("user").make(); EdgeLabel edge = mgmt.makeEdgeLabel("knows").make(); PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.addProperties(edge, id); mgmt.addConnection(edge, user, user); mgmt.commit(); return g; }
mgmt.makePropertyKey("time").dataType(Integer.class).make(); final PropertyKey text = mgmt.makePropertyKey("text").dataType(String.class).make(); mgmt.makePropertyKey("height").dataType(Double.class).make(); if (indexFeatures.supportsCardinality(Cardinality.LIST)) { mgmt.makePropertyKey("phone").dataType(String.class).cardinality(Cardinality.LIST).make(); mgmt.buildIndex("theIndex", Vertex.class).addKey(text, getTextMapping(), getFieldMap(text)).buildMixedIndex(INDEX); finishSchema(); final PropertyKey time = mgmt.getPropertyKey("time"); mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), time, getFieldMap(time)); finishSchema(); newTx(); assertNull(mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX)); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.REGISTER_INDEX).get(); mgmt.commit(); mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX).get(); finishSchema(); final PropertyKey height = mgmt.getPropertyKey("height"); mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), height); if (indexFeatures.supportsCardinality(Cardinality.LIST)) { final PropertyKey phone = mgmt.getPropertyKey("phone"); mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), phone, new Parameter("mapping", Mapping.STRING));
final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make(); EdgeLabel wavedAt = mgmt.makeEdgeLabel("wavedAt").signature(time).make(); mgmt.buildEdgeIndex(wavedAt, "timeindex", Direction.BOTH, decr, time); mgmt.buildIndex("edge-time", Edge.class).addKey(time).buildCompositeIndex(); mgmt.setTTL(wavedAt, Duration.ofSeconds(ttl)); assertEquals(Duration.ZERO, mgmt.getTTL(time)); assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(wavedAt)); mgmt.commit();
public PropertyKey makeVertexIndexedKey(String name, Class dataType) { final PropertyKey key = mgmt.makePropertyKey(name).dataType(dataType).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex(name,Vertex.class).addKey(key).buildCompositeIndex(); return key; }
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.LIST).make(); EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(time).make(); EdgeLabel child = mgmt.makeEdgeLabel("child").multiplicity(Multiplicity.ONE2MANY).make(); EdgeLabel link = mgmt.makeEdgeLabel("link").unidirected().make(); RelationTypeIndex name1 = mgmt.buildPropertyIndex(name, "weightDesc", weight); RelationTypeIndex connect1 = mgmt.buildEdgeIndex(connect, "weightAsc", Direction.BOTH, incr, weight); RelationTypeIndex connect2 = mgmt.buildEdgeIndex(connect, "weightDesc", Direction.OUT, decr, weight); RelationTypeIndex connect3 = mgmt.buildEdgeIndex(connect, "time+weight", Direction.OUT, decr, time, weight); RelationTypeIndex child1 = mgmt.buildEdgeIndex(child, "time", Direction.OUT, time); RelationTypeIndex link1 = mgmt.buildEdgeIndex(link, "time", Direction.OUT, time); assertTrue(mgmt.containsRelationIndex(name, "weightDesc")); assertTrue(mgmt.containsRelationIndex(connect, "weightDesc")); assertFalse(mgmt.containsRelationIndex(child, "weightDesc")); assertEquals("time+weight", mgmt.getRelationIndex(connect, "time+weight").name()); assertNotNull(mgmt.getRelationIndex(link, "time")); assertNull(mgmt.getRelationIndex(name, "time")); assertEquals(1, Iterables.size(mgmt.getRelationIndexes(child))); assertEquals(3, Iterables.size(mgmt.getRelationIndexes(connect))); assertEquals(0, Iterables.size(mgmt.getRelationIndexes(weight))); try { mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time); fail(); } catch (SchemaViolationException ignored) {
@Test public void testVertexCentricIndexOrderingOnEdgePropertyWithCardinalityList() { clopen(option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250) ); PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.LIST).make(); EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make(); mgmt.buildEdgeIndex(friend, "byTime", Direction.OUT, decr, time); finishSchema(); JanusGraphVertex v = tx.addVertex(); for (int i = 200; i < 210; i++) { JanusGraphVertex o = tx.addVertex(); v.addEdge("friend", o, "time", i); } assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime").getIndexStatus()); evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 201, 205).orderBy("time", decr), EDGE, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); tx.commit(); finishSchema(); }
VertexLabel person = mgmt.makeVertexLabel("person").make(); VertexLabel org = mgmt.makeVertexLabel("org").make(); JanusGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class). addKey(name, getStringMapping()).buildMixedIndex(INDEX); JanusGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).indexOnly(person). addKey(text, getTextMapping()).addKey(weight).buildMixedIndex(INDEX); JanusGraphIndex index3 = mgmt.buildIndex("index3", Vertex.class).indexOnly(org). addKey(text, getTextMapping()).addKey(weight).buildMixedIndex(INDEX); assertTrue(mgmt.containsGraphIndex("index1")); assertFalse(mgmt.containsGraphIndex("index")); assertCount(3, mgmt.getGraphIndexes(Vertex.class)); assertNull(mgmt.getGraphIndex("indexx")); name = mgmt.getPropertyKey("name"); weight = mgmt.getPropertyKey("weight"); text = mgmt.getPropertyKey("text"); person = mgmt.getVertexLabel("person"); org = mgmt.getVertexLabel("org"); index1 = mgmt.getGraphIndex("index1"); index2 = mgmt.getGraphIndex("index2"); index3 = mgmt.getGraphIndex("index3"); mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildMixedIndex(INDEX); fail(); } catch (final IllegalArgumentException ignored) { mgmt.buildIndex("index2", Vertex.class).addKey(weight).buildCompositeIndex();