try { management = g.openManagement(); idx = management.getRelationIndex(management.getRelationType(relationTypeName), relationIndexName); actualStatus = idx.getIndexStatus(); LOGGER.info("Index {} (relation type {}) has status {}", relationIndexName, relationTypeName, actualStatus);
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))); 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)));
try { if (StringUtils.isNotBlank(relationTypeName)) { RelationTypeIndex idx = management.getRelationIndex(management.getRelationType(relationTypeName) ,indexName); Preconditions.checkArgument(idx!=null,"Index could not be found: %s @ %s",indexName,relationTypeName);
@Test public void testVertexCentricPropertyIndexOnSetCardinalityShouldWork() { 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.SINGLE).make(); PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SET).make(); mgmt.buildPropertyIndex(name, "byTime", decr, time); finishSchema(); assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("name"), "byTime").getIndexStatus()); JanusGraphVertex v = tx.addVertex(); v = getV(tx, v); for (int i = 200; i < 210; i++) { v.property("name", String.valueOf(i), "time", i); } evaluateQuery(v.query().keys("name").interval("time", 199, 210).orderBy("time", decr), PROPERTY, 10, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); tx.commit(); finishSchema(); }
@Test public void testVertexCentricIndexOrderingOnMetaPropertyWithCardinalityList() { 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(); PropertyKey sensor = mgmt.makePropertyKey("sensor").dataType(Integer.class).cardinality(Cardinality.LIST).make(); mgmt.buildPropertyIndex(sensor, "byTime", decr, time); finishSchema(); JanusGraphVertex v = tx.addVertex(); for (int i = 200; i < 210; i++) { v.property("sensor", i, "time", i); } assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime").getIndexStatus()); evaluateQuery(v.query().keys("sensor").interval("time", 201, 205).orderBy("time", decr), PROPERTY, 4, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); tx.commit(); finishSchema(); }
@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(); }
@Test public void testVertexCentricEdgeIndexOnSimpleMultiplicityShouldWork() { 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.SINGLE).make(); EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.SIMPLE).make(); mgmt.buildEdgeIndex(friend, "byTime", Direction.OUT, decr, time); finishSchema(); assertEquals(SchemaStatus.ENABLED, mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime").getIndexStatus()); JanusGraphVertex v = tx.addVertex(); v = getV(tx, v); for (int i = 200; i < 210; i++) { JanusGraphVertex o = tx.addVertex(); v.addEdge("friend", o, "time", i); } evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 199, 210).orderBy("time", decr), EDGE, 10, 1, new boolean[]{true, true}, tx.getPropertyKey("time"), Order.DESC); tx.commit(); finishSchema(); }
pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime"); eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime"); graphIndex = mgmt.getGraphIndex("bySensorReading"); try { pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime"); eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime"); graphIndex = mgmt.getGraphIndex("bySensorReading"); assertEquals(SchemaStatus.REGISTERED, pindex.getIndexStatus()); eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime"); mgmt.updateIndex(eindex, SchemaAction.ENABLE_INDEX); finishSchema(); pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime"); ScanMetrics reindexSensorByTime = mgmt.updateIndex(pindex, SchemaAction.REINDEX).get(); finishSchema(); pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime"); eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime"); graphIndex = mgmt.getGraphIndex("bySensorReading"); assertEquals(SchemaStatus.ENABLED, eindex.getIndexStatus()); eindex = mgmt.getRelationIndex(mgmt.getRelationType("friend"), "byTime"); ScanMetrics reindexFriendByTime = mgmt.updateIndex(eindex, SchemaAction.REINDEX).get(); finishSchema(); pindex = mgmt.getRelationIndex(mgmt.getRelationType("sensor"), "byTime"); graphIndex = mgmt.getGraphIndex("bySensorReading");
RelationTypeIndex byTimeIndex = mgmt.getRelationIndex(knows, "byTime"); assertEquals("byTime", byTimeIndex.name()); mgmt.changeName(byTimeIndex, "overTime");
@Override public boolean edgeIndexExist(String label, String indexName) { EdgeLabel edgeLabel = management.getEdgeLabel(label); return edgeLabel != null && management.getRelationIndex(edgeLabel, indexName) != null; }
private static void makeIndicesVertexCentric(JanusGraphManagement management){ ResourceBundle keys = ResourceBundle.getBundle("indices-edges"); Set<String> edgeLabels = keys.keySet(); for(String edgeLabel : edgeLabels){ String[] propertyKeyStrings = keys.getString(edgeLabel).split(","); //Get all the property keys we need Set<PropertyKey> propertyKeys = stream(propertyKeyStrings).map(keyId ->{ PropertyKey key = management.getPropertyKey(keyId); if (key == null) { throw new RuntimeException("Trying to create edge index on label [" + edgeLabel + "] but the property [" + keyId + "] does not exist"); } return key; }).collect(Collectors.toSet()); //Get the edge and indexing information RelationType relationType = management.getRelationType(edgeLabel); EdgeLabel label = management.getEdgeLabel(edgeLabel); //Create index on each property key for (PropertyKey key : propertyKeys) { if (management.getRelationIndex(relationType, edgeLabel + "by" + key.name()) == null) { management.buildEdgeIndex(label, edgeLabel + "by" + key.name(), Direction.BOTH, Order.decr, key); } } //Create index on all property keys String propertyKeyId = propertyKeys.stream().map(Namifiable::name).collect(Collectors.joining("_")); if (management.getRelationIndex(relationType, edgeLabel + "by" + propertyKeyId) == null) { PropertyKey [] allKeys = propertyKeys.toArray(new PropertyKey[propertyKeys.size()]); management.buildEdgeIndex(label, edgeLabel + "by" + propertyKeyId, Direction.BOTH, Order.decr, allKeys); } } }
@Override public void createEdgeIndex(String label, String indexName, AtlasEdgeDirection edgeDirection, List<AtlasPropertyKey> propertyKeys) { EdgeLabel edgeLabel = management.getEdgeLabel(label); if (edgeLabel == null) { edgeLabel = management.makeEdgeLabel(label).make(); } Direction direction = AtlasJanusObjectFactory.createDirection(edgeDirection); PropertyKey[] keys = AtlasJanusObjectFactory.createPropertyKeys(propertyKeys); if (management.getRelationIndex(edgeLabel, indexName) == null) { management.buildEdgeIndex(edgeLabel, indexName, direction, keys); } }