@Test public void testPageRank() throws ExecutionException, InterruptedException { mgmt.makePropertyKey("distance").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make(); mgmt.makeEdgeLabel("likes").multiplicity(Multiplicity.MULTI).make(); finishSchema(); final int branch = 6;
private int generateRandomGraph(int numV) { mgmt.makePropertyKey("uid").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make(); mgmt.makePropertyKey("values").cardinality(Cardinality.LIST).dataType(Integer.class).make(); mgmt.makePropertyKey("numvals").dataType(Integer.class).make(); finishSchema(); int numE = 0; TitanVertex[] vs = new TitanVertex[numV]; for (int i=0;i<numV;i++) { vs[i] = tx.addVertex("uid",i+1); int numVals = random.nextInt(5)+1; vs[i].property(VertexProperty.Cardinality.single, "numvals", numVals); for (int j=0;j<numVals;j++) { vs[i].property("values",random.nextInt(100)); } } for (int i=0;i<numV;i++) { int edges = i+1; TitanVertex v = vs[i]; for (int j=0;j<edges;j++) { TitanVertex u = vs[random.nextInt(numV)]; v.addEdge("knows", u); numE++; } } assertEquals(numV*(numV+1),numE*2); return numE; }
public void testBatchLoadingLocking(boolean batchloading) { PropertyKey uid = makeKey("uid",Long.class); TitanGraphIndex uidIndex = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex(); mgmt.setConsistency(uid, ConsistencyModifier.LOCK); mgmt.setConsistency(uidIndex,ConsistencyModifier.LOCK); EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.ONE2ONE).make(); mgmt.setConsistency(knows,ConsistencyModifier.LOCK); finishSchema(); TestLockerManager.ERROR_ON_LOCKING=true; clopen(option(GraphDatabaseConfiguration.STORAGE_BATCH),batchloading, option(GraphDatabaseConfiguration.LOCK_BACKEND),"test"); int numV = 10000; long start = System.currentTimeMillis(); for (int i=0;i<numV;i++) { TitanVertex v = tx.addVertex("uid",i+1); v.addEdge("knows",v); } clopen(); // System.out.println("Time: " + (System.currentTimeMillis()-start)); for (int i=0;i<Math.min(numV,300);i++) { assertEquals(1, Iterables.size(graph.query().has("uid", i + 1).vertices())); TitanVertex v = Iterables.<TitanVertex>getOnlyElement(graph.query().has("uid", i + 1).vertices()); assertEquals(1, Iterables.size(v.query().direction(OUT).labels("knows").edges())); } }
.addKey(name).unique().buildCompositeIndex(); mgmt.setConsistency(nameIndex, ConsistencyModifier.LOCK); EdgeLabel married = mgmt.makeEdgeLabel("married").multiplicity(Multiplicity.ONE2ONE).make(); mgmt.setConsistency(married, ConsistencyModifier.LOCK); EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make(); finishSchema();
@Test public void testShortestDistance() throws Exception { PropertyKey distance = mgmt.makePropertyKey("distance").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("connect").signature(distance).multiplicity(Multiplicity.MULTI).make(); finishSchema();
PropertyKey uid = makeVertexIndexedUniqueKey("uid", Integer.class); ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("knows")).sortKey(uid).sortOrder(Order.DESC).directed().make(); mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); finishSchema();
mgmt.setConsistency(valuef,ConsistencyModifier.FORK); EdgeLabel em = mgmt.makeEdgeLabel("em").multiplicity(Multiplicity.MULTI).make(); EdgeLabel emf = mgmt.makeEdgeLabel("emf").multiplicity(Multiplicity.MULTI).make(); mgmt.setConsistency(emf,ConsistencyModifier.FORK); EdgeLabel es = mgmt.makeEdgeLabel("es").multiplicity(Multiplicity.SIMPLE).make(); EdgeLabel o2o = mgmt.makeEdgeLabel("o2o").multiplicity(Multiplicity.ONE2ONE).make(); EdgeLabel o2m = mgmt.makeEdgeLabel("o2m").multiplicity(Multiplicity.ONE2MANY).make();
mgmt.setConsistency(name, ConsistencyModifier.LOCK); mgmt.setConsistency(mgmt.getGraphIndex("uid"), ConsistencyModifier.LOCK); EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.SIMPLE).make(); EdgeLabel spouse = mgmt.makeEdgeLabel("spouse").multiplicity(Multiplicity.ONE2ONE).make(); EdgeLabel connect = mgmt.makeEdgeLabel("connect").multiplicity(Multiplicity.MULTI).make(); EdgeLabel related = mgmt.makeEdgeLabel("related").multiplicity(Multiplicity.MULTI).make(); mgmt.setConsistency(knows, ConsistencyModifier.LOCK); mgmt.setConsistency(spouse, ConsistencyModifier.LOCK);
EdgeLabel knows = makeLabel("knows"); EdgeLabel base = makeLabel("base"); EdgeLabel one = mgmt.makeEdgeLabel("one").multiplicity(Multiplicity.ONE2ONE).make();
mgmt.buildIndex("edges", Edge.class).addKey(reason).addKey(place).buildMixedIndex(mixedIndexName); mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); mgmt.makeEdgeLabel("mother").multiplicity(Multiplicity.MANY2ONE).make(); EdgeLabel battled = mgmt.makeEdgeLabel("battled").signature(time).make(); mgmt.buildEdgeIndex(battled, "battlesByTime", Direction.BOTH, Order.decr, time);
@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();
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();
mgmt.makeVertexLabel("user").make(); mgmt.makeEdgeLabel("visit").multiplicity(Multiplicity.MULTI).make(); mgmt.makePropertyKey(PROP_VISIT_RATING).dataType(Integer.class).make(); mgmt.makePropertyKey(PROP_VISIT_FOOD).dataType(Integer.class).make(); mgmt.makePropertyKey(PROP_VISIT_SERVICE).dataType(Integer.class).make(); mgmt.makeEdgeLabel("restaurant_genre").multiplicity(Multiplicity.MULTI).make(); mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make();
EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make(); PropertyKey sensor = mgmt.makePropertyKey("sensor").dataType(Double.class).cardinality(Cardinality.LIST).make(); finishSchema();
EdgeLabel child = mgmt.makeEdgeLabel("child").multiplicity(Multiplicity.ONE2MANY).make(); EdgeLabel link = mgmt.makeEdgeLabel("link").unidirected().make();
@Test public void pageRank() { mgmt.makePropertyKey("distance").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make(); mgmt.makeEdgeLabel("likes").multiplicity(Multiplicity.MULTI).make(); finishSchema(); final int branch = 5;
public void testBatchLoadingLocking(boolean batchloading) { PropertyKey uid = makeKey("uid",Long.class); TitanGraphIndex uidIndex = mgmt.buildIndex("uid",Vertex.class).unique().addKey(uid).buildCompositeIndex(); mgmt.setConsistency(uid, ConsistencyModifier.LOCK); mgmt.setConsistency(uidIndex,ConsistencyModifier.LOCK); EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.ONE2ONE).make(); mgmt.setConsistency(knows,ConsistencyModifier.LOCK); finishSchema(); TestLockerManager.ERROR_ON_LOCKING=true; clopen(option(GraphDatabaseConfiguration.STORAGE_BATCH),batchloading, option(GraphDatabaseConfiguration.LOCK_BACKEND),"test"); int numV = 10000; long start = System.currentTimeMillis(); for (int i=0;i<numV;i++) { TitanVertex v = tx.addVertex(); v.setProperty("uid",i+1); v.addEdge("knows",v); } clopen(); // System.out.println("Time: " + (System.currentTimeMillis()-start)); for (int i=0;i<Math.min(numV,300);i++) { assertEquals(1, Iterables.size(graph.query().has("uid", i + 1).vertices())); assertEquals(1, Iterables.size(graph.query().has("uid", i + 1).vertices().iterator().next().getEdges(Direction.OUT, "knows"))); } }
private void createSchema() { final TitanManagement mgmt = titanGraph.getManagementSystem(); if (!titanGraph.getIndexedKeys(Vertex.class).contains(NODE_ID)) { final PropertyKey key = mgmt.makePropertyKey(NODE_ID).dataType(Integer.class).make(); mgmt.buildIndex(NODE_ID, Vertex.class).addKey(key).unique().buildCompositeIndex(); } if (!titanGraph.getIndexedKeys(Vertex.class).contains(COMMUNITY)) { final PropertyKey key = mgmt.makePropertyKey(COMMUNITY).dataType(Integer.class).make(); mgmt.buildIndex(COMMUNITY, Vertex.class).addKey(key).buildCompositeIndex(); } if (!titanGraph.getIndexedKeys(Vertex.class).contains(NODE_COMMUNITY)) { final PropertyKey key = mgmt.makePropertyKey(NODE_COMMUNITY).dataType(Integer.class).make(); mgmt.buildIndex(NODE_COMMUNITY, Vertex.class).addKey(key).buildCompositeIndex(); } if (mgmt.getEdgeLabel(SIMILAR) == null) { mgmt.makeEdgeLabel(SIMILAR).multiplicity(Multiplicity.MULTI).directed().make(); } mgmt.commit(); }
.addKey(name).unique().buildCompositeIndex(); mgmt.setConsistency(nameIndex, ConsistencyModifier.LOCK); EdgeLabel married = mgmt.makeEdgeLabel("married").multiplicity(Multiplicity.ONE2ONE).make(); mgmt.setConsistency(married,ConsistencyModifier.LOCK); EdgeLabel friend = mgmt.makeEdgeLabel("friend").multiplicity(Multiplicity.MULTI).make(); finishSchema();
PropertyKey id = makeVertexIndexedUniqueKey("uid",Integer.class); ((StandardEdgeLabelMaker)mgmt.makeEdgeLabel("knows")).sortKey(id).sortOrder(Order.DESC).directed().make(); mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); finishSchema();