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));
@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(); }
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();
EdgeLabel bought = makeLabel("bought"); PropertyKey time = makeKey("time", Long.class); mgmt.buildEdgeIndex(bought, "byTimeDesc", BOTH, decr, time); mgmt.buildEdgeIndex(bought, "byTimeIncr", BOTH, incr, time); finishSchema();
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); mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time); fail(); } catch (SchemaViolationException ignored) { mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time); fail(); } catch (IllegalArgumentException ignored) { mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time); fail(); } catch (IllegalArgumentException ignored) { mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time); fail(); } catch (SchemaViolationException ignored) { mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time); fail(); } catch (IllegalArgumentException ignored) { mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time);
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();
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();
mgmt.buildEdgeIndex(knows, "byWeightDecr", Direction.OUT, decr, weight); mgmt.buildEdgeIndex(knows, "byWeightIncr", Direction.OUT, incr, weight);
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); } }