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));
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();
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();
PropertyKey reason = m.getPropertyKey("reason"); EdgeLabel lives = m.getEdgeLabel("lives"); m.buildEdgeIndex(lives, "livesByReason", Direction.BOTH, Order.decr, reason); m.commit(); graph.tx().commit();
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 e) { mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time); fail(); } catch (IllegalArgumentException e) { mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time); fail(); } catch (IllegalArgumentException e) { mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time); fail(); } catch (SchemaViolationException e) { mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time); fail(); } catch (IllegalArgumentException e) { mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time);
mgmt.buildEdgeIndex(knows, "byWeightDecr", Direction.OUT, decr, weight); mgmt.buildEdgeIndex(knows, "byWeightIncr", Direction.OUT, incr, weight);
mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make(); mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time); mgmt.makeEdgeLabel("lives").signature(reason).make(); mgmt.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();
private static void makeIndicesVertexCentric(TitanManagement management){ ResourceBundle keys = ResourceBundle.getBundle("indices-edges"); Set<String> edgeLabels = keys.keySet(); for(String edgeLabel : edgeLabels){ String properties = keys.getString(edgeLabel); if(properties.length() > 0){ String[] propertyKey = keys.getString(edgeLabel).split(","); for (String aPropertyKey : propertyKey) { PropertyKey key = management.getPropertyKey(aPropertyKey); if (key == null) throw new RuntimeException("Trying to create edge index on label [" + edgeLabel + "] but the property [" + aPropertyKey + "] does not exist"); RelationType relationType = management.getRelationType(edgeLabel); if (management.getRelationIndex(relationType, edgeLabel + "by" + aPropertyKey) == null) { EdgeLabel label = management.getEdgeLabel(edgeLabel); management.buildEdgeIndex(label, edgeLabel + "by" + aPropertyKey, Direction.OUT, Order.decr, key); } } } } }
private static void makeIndicesVertexCentric(TitanManagement management){ ResourceBundle keys = ResourceBundle.getBundle("indices-edges"); Set<String> edgeLabels = keys.keySet(); for(String edgeLabel : edgeLabels){ String properties = keys.getString(edgeLabel); if(properties.length() > 0){ String[] propertyKey = keys.getString(edgeLabel).split(","); for (String aPropertyKey : propertyKey) { PropertyKey key = management.getPropertyKey(aPropertyKey); if (key == null) throw new RuntimeException("Trying to create edge index on label [" + edgeLabel + "] but the property [" + aPropertyKey + "] does not exist"); RelationType relationType = management.getRelationType(edgeLabel); if (management.getRelationIndex(relationType, edgeLabel + "by" + aPropertyKey) == null) { EdgeLabel label = management.getEdgeLabel(edgeLabel); management.buildEdgeIndex(label, edgeLabel + "by" + aPropertyKey, Direction.OUT, Order.decr, key); } } } } }
@Category({ BrittleTests.class }) @Test public void testEdgeTTLWithVertexCentricIndex() throws Exception { if (!features.hasCellTTL()) { return; } int ttl = 1; // artificially low TTL for test final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make(); EdgeLabel wavedAt = mgmt.makeEdgeLabel("wavedAt").signature(time).make(); mgmt.buildEdgeIndex(wavedAt, "timeindex", Direction.BOTH, Order.DESC, time); mgmt.setTTL(wavedAt, ttl, TimeUnit.SECONDS); assertEquals(0, mgmt.getTTL(time).getLength(TimeUnit.SECONDS)); assertEquals(ttl, mgmt.getTTL(wavedAt).getLength(TimeUnit.SECONDS)); mgmt.commit(); Vertex v1 = graph.addVertex(null), v2 = graph.addVertex(null); Edge e1 = graph.addEdge(null, v1, v2, "wavedAt"); e1.setProperty("time", 42); assertTrue(v1.getEdges(Direction.OUT).iterator().hasNext()); assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext()); graph.commit(); long commitTime = System.currentTimeMillis(); assertTrue(v1.getEdges(Direction.OUT).iterator().hasNext()); assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext()); Thread.sleep(commitTime + (ttl * 1000L + 100) - System.currentTimeMillis()); graph.rollback(); assertFalse(v1.getEdges(Direction.OUT).iterator().hasNext()); assertFalse(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext()); }
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,Order.DESC,time); mgmt.buildEdgeIndex(bought,"byTimeIncr",BOTH,Order.ASC,time); finishSchema();
RelationTypeIndex connect1 = mgmt.buildEdgeIndex(connect, "weightAsc", Direction.BOTH, Order.ASC, weight); RelationTypeIndex connect2 = mgmt.buildEdgeIndex(connect, "weightDesc", Direction.OUT, Order.DESC, weight); RelationTypeIndex connect3 = mgmt.buildEdgeIndex(connect, "time+weight", Direction.OUT, Order.DESC, 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 e) {} mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time); fail(); } catch (IllegalArgumentException e) {} try { mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time); fail(); } catch (IllegalArgumentException e) {} mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time); fail(); } catch (SchemaViolationException e) {} mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time); fail(); } catch (IllegalArgumentException e) {} try {
mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make(); mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time); mgmt.makeEdgeLabel("lives").signature(reason).make(); mgmt.makeEdgeLabel("pet").make();
mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make(); mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.DESC, time); mgmt.makeEdgeLabel("lives").signature(reason).make(); mgmt.makeEdgeLabel("pet").make();
friend = mgmt.getEdgeLabel("friend"); mgmt.buildPropertyIndex(sensor, "byTime", Order.DESC, time); mgmt.buildEdgeIndex(friend, "byTime", Direction.OUT, Order.DESC, time); mgmt.buildIndex("bySensorReading",Vertex.class).addKey(name).buildCompositeIndex(); finishSchema();