public PropertyKey makeKey(String name, Class datatype) { PropertyKey key = mgmt.makePropertyKey(name).dataType(datatype).cardinality(Cardinality.SINGLE).make(); return key; }
/** * Creates a new property key with default settings against the provided {@link PropertyKeyMaker}. * * @param factory PropertyKeyMaker through which the property key is created * @return A new property key * @throws IllegalArgumentException if the name is already in use or if other configured values are invalid. */ public default PropertyKey makePropertyKey(PropertyKeyMaker factory) { return factory.cardinality(defaultPropertyCardinality(factory.getName())).dataType(Object.class).make(); }
clopen(option(GraphDatabaseConfiguration.ADJUST_LIMIT),false); PropertyKey k = mgmt.makePropertyKey("k").dataType(Integer.class).cardinality(Cardinality.SINGLE).make(); PropertyKey q = mgmt.makePropertyKey("q").dataType(Long.class).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex("byK",Vertex.class).addKey(k).buildCompositeIndex(); finishSchema();
public PropertyKey makeVertexIndexedKey(String name, Class datatype) { PropertyKey key = mgmt.makePropertyKey(name).dataType(datatype).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex(name,Vertex.class).addKey(key).buildCompositeIndex(); return key; }
public PropertyKey makeVertexIndexedUniqueKey(String name, Class datatype) { PropertyKey key = mgmt.makePropertyKey(name).dataType(datatype).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex(name,Vertex.class).addKey(key).unique().buildCompositeIndex(); return key; }
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; }
private void testIndexing(Cardinality cardinality) { if (supportsCollections()) { PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make(); PropertyKey intProperty = mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(cardinality).make(); PropertyKey longProperty = mgmt.makePropertyKey("long").dataType(Long.class).cardinality(cardinality).make(); PropertyKey uuidProperty = mgmt.makePropertyKey("uuid").dataType(UUID.class).cardinality(cardinality).make(); PropertyKey geoProperty = mgmt.makePropertyKey("geo").dataType(Geoshape.class).cardinality(cardinality).make(); mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).addKey(intProperty).addKey(longProperty).addKey(uuidProperty).addKey(geoProperty).buildMixedIndex(INDEX); finishSchema(); testCollection(cardinality, "name", "Totoro", "Hiro"); testCollection(cardinality, "age", 1, 2); testCollection(cardinality, "long", 1L, 2L); testCollection(cardinality, "uuid", UUID.randomUUID(), UUID.randomUUID()); testCollection(cardinality, "geo", Geoshape.point(1.0, 1.0), Geoshape.point(2.0, 2.0)); } else { try { PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make(); //This should throw an exception mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX); Assert.fail("Should have thrown an exception"); } catch (TitanException e) { } } }
@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();
VertexLabel song = mgmt.makeVertexLabel("song").make(); PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make(); PropertyKey songType = mgmt.makePropertyKey("songType").cardinality(Cardinality.LIST).dataType(String.class).make(); PropertyKey performances = mgmt.makePropertyKey("performances").cardinality(Cardinality.LIST).dataType(Integer.class).make(); VertexLabel software = mgmt.makeVertexLabel("software").make(); PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make(); PropertyKey lang = mgmt.makePropertyKey("lang").cardinality(Cardinality.LIST).dataType(String.class).make(); PropertyKey age = mgmt.makePropertyKey("age").cardinality(Cardinality.LIST).dataType(Integer.class).make(); PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.LIST).dataType(String.class).make(); PropertyKey lang = mgmt.makePropertyKey("lang").cardinality(Cardinality.LIST).dataType(String.class).make(); PropertyKey age = mgmt.makePropertyKey("age").cardinality(Cardinality.LIST).dataType(Integer.class).make();
@Test public void testTinkerPopCardinality() { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.SINGLE).dataType(String.class).make(); PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make(); mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex(); finishSchema(); GraphTraversalSource gts; Vertex v; v = graph.addVertex("id", 1); v.property(single, "name", "t1"); graph.addVertex("id", 2, "names", "n1", "names", "n2"); graph.tx().commit(); gts = graph.traversal(); v = gts.V().has("id", 1).next(); v.property(single, "name", "t2"); v = gts.V().has("id", 1).next(); v.property(single, "name", "t3"); assertCount(1, gts.V(v).properties("name")); assertCount(2, gts.V().has("id", 2).properties("names")); assertCount(2, gts.V().hasLabel("vertex")); }
PropertyKey f = ((StandardPropertyKeyMaker) mgmt.makePropertyKey(foo)).dataType(String.class).cardinality(Cardinality.LIST).sortKey(w).sortOrder(Order.DESC).make(); mgmt.buildIndex(foo, Vertex.class).addKey(f).buildCompositeIndex(); PropertyKey b = mgmt.makePropertyKey(bar).dataType(String.class).cardinality(Cardinality.LIST).make(); mgmt.buildIndex(bar, Vertex.class).addKey(b).buildCompositeIndex(); 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();
@Test public void testReadWideVertexWithManyProperties() { int numProps = 1 << 16; long numV = 1; mgmt.makePropertyKey("p").cardinality(Cardinality.LIST).dataType(Integer.class).make(); mgmt.commit(); finishSchema(); for (int j = 0; j < numV; j++) { Vertex v = graph.addVertex(); for (int i = 0; i < numProps; i++) { v.property("p", i); } } graph.tx().commit(); assertEquals(numV, (long) graph.traversal().V().count().next()); Map<String, Object> propertiesOnVertex = graph.traversal().V().valueMap().next(); List<?> valuesOnP = (List)propertiesOnVertex.values().iterator().next(); assertEquals(numProps, valuesOnP.size()); Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties"); GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)); assertEquals(numV, (long) t.V().count().next()); propertiesOnVertex = t.V().valueMap().next(); valuesOnP = (List)propertiesOnVertex.values().iterator().next(); assertEquals(numProps, valuesOnP.size()); }
@Test public void testConcurrentConsistencyEnforcement() throws Exception { PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); TitanGraphIndex nameIndex = mgmt.buildIndex("name", Vertex.class) .addKey(name).unique().buildCompositeIndex();
metricsPrefix = "testSettingProperty"; mgmt.makePropertyKey("foo").dataType(String.class).cardinality(Cardinality.SINGLE).make(); finishSchema();
/** * This test exercises different types of updates against cardinality restricted properties * to ensure that the resulting behavior is fully consistent. */ @Test public void testPropertyCardinality() { PropertyKey uid = mgmt.makePropertyKey("uid").dataType(Long.class).cardinality(Cardinality.SINGLE).make(); PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SINGLE).make(); mgmt.buildIndex("byUid", Vertex.class).addKey(uid).unique().buildCompositeIndex(); mgmt.buildIndex("byName", Vertex.class).addKey(name).buildCompositeIndex(); finishSchema(); TitanVertex v1 = tx.addVertex(); v1.property("name", "name1"); TitanVertex v2 = tx.addVertex(); v2.property("uid", 512); newTx(); v1 = tx.getVertex(v1.longId()); v1.property("name", "name2"); //Ensure that the old index record gets removed v2 = tx.getVertex(v2.longId()); v2.property("uid", 512); //Ensure that replacement is allowed newTx(); assertCount(0, tx.query().has("name", "name1").vertices()); assertCount(1, tx.query().has("name", "name2").vertices()); assertCount(1, tx.query().has("uid", 512).vertices()); }
PropertyKey sig = makeKey("sig",Integer.class); PropertyKey weight = makeKey("weight",Double.class); PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SET).make(); PropertyKey value = mgmt.makePropertyKey("value").dataType(Integer.class).cardinality(Cardinality.LIST).make(); PropertyKey valuef = mgmt.makePropertyKey("valuef").dataType(Integer.class).cardinality(Cardinality.LIST).make(); mgmt.setConsistency(valuef,ConsistencyModifier.FORK);
PropertyKey any = mgmt.makePropertyKey("any").cardinality(Cardinality.LIST).dataType(Object.class).make();
@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);
@Test public void testTinkerPopOptimizationStrategies() { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); PropertyKey weight = mgmt.makePropertyKey("weight").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); mgmt.buildEdgeIndex(knows, "byWeightIncr", Direction.OUT, incr, weight); PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make(); mgmt.buildPropertyIndex(names, "namesByWeight", decr, weight);