while ((nextLine = reader.readNext()) != null) { TitanVertex vertex = graph.addVertexWithLabel("restaurant"); vertex.addProperty(RESTAURANT_ID, nextLine[0]); vertex.addProperty(PROP_RESTAURANT_NAME, nextLine[1]); vertex.addProperty(PROP_RESTAURANT_LATITUDE, nextLine[2]); vertex.addProperty(PROP_RESTAURANT_LONGITUDE, nextLine[3]); vertex.addProperty(PROP_RESTAURANT_ALCOHOL, nextLine[4]); vertex.addProperty(PROP_RESTAURANT_DRESSCODE, nextLine[5]); vertex.addProperty(PROP_RESTAURANT_ACCESSIBILITY, nextLine[6]); vertex.addProperty(PROP_RESTAURANT_PRICE, nextLine[7]); vertex.addProperty(PROP_RESTAURANT_AMBIENCE, nextLine[8]); vertex.addProperty(PROP_RESTAURANT_FRANCHISE, nextLine[9]); vertex.addProperty(PROP_RESTAURANT_SERVICES, nextLine[10]); vertex.addProperty(PROP_RESTAURANT_PLACE, Geoshape.point(latitude, longitude)); while ((nextLine = reader.readNext()) != null) { TitanVertex vertex = graph.addVertexWithLabel("genre"); vertex.addProperty(GENRE, nextLine[0]); while ((nextLine = reader.readNext()) != null) { TitanVertex vertex = graph.addVertexWithLabel("user"); vertex.addProperty(USER_ID, nextLine[0]); vertex.addProperty(PROP_USER_DRESSPREFERENCE, nextLine[1]); vertex.addProperty(PROP_USER_BUDGET, nextLine[2]);
@Override public void run() { while (true) { // Set propType to a random value on a random node TitanVertex n = Iterables.getOnlyElement(tx.getVertices(idProp, RandomGenerator.randomInt(0, nodeCount))); String propVal = RandomGenerator.randomString(); n.addProperty(randomProp, propVal); if (Thread.interrupted()) break; // Is creating the same property twice an error? } } }
@Override public void run() { while (true) { // Set propType to a random value on a random node TitanVertex n = Iterables.getOnlyElement(tx.getVertices(idProp, RandomGenerator.randomInt(0, nodeCount))); String propVal = RandomGenerator.randomString(); n.addProperty(randomProp, propVal); if (Thread.interrupted()) break; // Is creating the same property twice an error? } } }
@Override public <T> void addProperty(String propertyName, T value) { try { getAsTitanVertex().addProperty(propertyName, value); } catch (SchemaViolationException e) { if (getPropertyValues(propertyName, value.getClass()).contains(value)) { // follow java set semantics, don't throw an exception if // value is already there. return; } throw new AtlasSchemaViolationException(e); } }
v.addProperty(foo, s); v.addProperty(bar, s); v.addProperty(foo, s);
v1.addProperty("domain", "unique1"); try { v2 = tx.addVertex(); v2.addProperty("domain", "unique1"); fail(); } catch (SchemaViolationException e) { v1.addProperty("domain", "unique1"); assertEquals(1, Iterables.size(tx.getVertices("domain", "unique1"))); try { v2 = tx.addVertex(); v2.addProperty("domain", "unique1"); fail(); } catch (SchemaViolationException e) {
@Override @Before public void setUp() throws Exception { super.setUp(); executor = Executors.newFixedThreadPool(THREAD_COUNT); // Generate synthetic graph TitanLabel[] rels = new TitanLabel[REL_COUNT]; for (int i = 0; i < rels.length; i++) { rels[i] = makeSimpleEdgeLabel("rel" + i); } TitanKey id = makeIntegerUIDPropertyKey("uid"); TitanVertex nodes[] = new TitanVertex[NODE_COUNT]; for (int i = 0; i < NODE_COUNT; i++) { nodes[i] = tx.addVertex(); nodes[i].addProperty(id, i); } for (int i = 0; i < NODE_COUNT; i++) { for (int r = 0; r < rels.length; r++) { for (int j = 1; j <= EDGE_COUNT; j++) { nodes[i].addEdge(rels[r], nodes[wrapAround(i + j, NODE_COUNT)]); } } } // Get a new transaction clopen(); }
for (int i = 0; i < noNodes; i++) { TitanVertex n = tx.addVertex(); n.addProperty(id, i); n.addProperty(name, "Name" + (i % mod)); TitanVertex other = tx.getVertex(id, Math.max(0, i - 1)); Preconditions.checkNotNull(other);
@Test public void testPropertyIndexPersistence() { final String propName = "favorite_color"; final String sharedValue = "blue"; makeStringPropertyKey(propName); TitanVertex alice = tx.addVertex(); TitanVertex bob = tx.addVertex(); alice.addProperty(propName, sharedValue); clopen(); alice = tx.getVertex(alice.getID()); bob = tx.getVertex(bob.getID()); assertEquals(sharedValue, alice.getProperty(propName)); assertEquals(null, bob.getProperty(propName)); alice.removeProperty(propName); bob.addProperty(propName, sharedValue); clopen(); }
private void initializeGraph() { //Create schema for (int i = 0; i < REL_COUNT; i++) { makeLabel("rel" + i); } makeVertexIndexedUniqueKey("uid",Integer.class); finishSchema(); // Generate synthetic graph TitanVertex nodes[] = new TitanVertex[NODE_COUNT]; for (int i = 0; i < NODE_COUNT; i++) { nodes[i] = tx.addVertex(); nodes[i].addProperty("uid", i); } for (int i = 0; i < NODE_COUNT; i++) { for (int r = 0; r < REL_COUNT; r++) { for (int j = 1; j <= EDGE_COUNT; j++) { nodes[i].addEdge("rel"+r, nodes[wrapAround(i + j, NODE_COUNT)]); } } } // Get a new transaction clopen(); }
@Test public void testPropertyIndexPersistence() { final String propName = "favorite_color"; final String sharedValue = "blue"; tx.makePropertyKey(propName).dataType(String.class).make(); TitanVertex alice = tx.addVertex(); TitanVertex bob = tx.addVertex(); alice.addProperty(propName, sharedValue); clopen(); alice = tx.getVertex(alice.getLongId()); bob = tx.getVertex(bob.getLongId()); assertEquals(sharedValue, alice.getProperty(propName)); assertEquals(null, bob.getProperty(propName)); alice.removeProperty(propName); bob.addProperty(propName, sharedValue); clopen(); }
for (int i = 0; i < noNodes; i++) { TitanVertex n = tx.addVertex(); n.addProperty("uid", i); n.addProperty("name", "Name" + (i % mod)); TitanVertex other = getVertex("uid", Math.max(0, i - 1)); Preconditions.checkNotNull(other);
TitanProperty p = Iterables.getOnlyElement(v.getProperties("weight")); assertEquals(1,p.getProperty("sig")); sign(v.addProperty("weight",6.0),txid); p = Iterables.getOnlyElement(v.getProperties("name")); assertEquals(1,p.getProperty("sig")); assertEquals("John",p.getValue()); p.remove(); sign(v.addProperty("name","Bob"),txid); for (String pkey : new String[]{"value","valuef"}) { p = Iterables.getOnlyElement(v.getProperties(pkey));
@Test public void testVertexDeletion() throws Exception { TitanKey name = makeUniqueStringPropertyKey("name"); newTx(); TitanVertex v = tx.addVertex(); TitanProperty p = v.addProperty("name", "oldName"); newTx(); TitanVertex v1 = tx.getVertex(v.getID()); tx.removeVertex(v1); newTx(); if (graph.getFeatures().supportsVertexIteration) { int count = 0; for (Vertex vertex : tx.getVertices()) count++; assertEquals(0, count); } }
/** * Very simple graph operation to ensure minimal functionality and cleanup */ @Test public void testBasic() { PropertyKey uid = makeVertexIndexedUniqueKey("name",String.class); finishSchema(); TitanVertex n1 = tx.addVertex(); uid = tx.getPropertyKey("name"); n1.addProperty(uid.getName(), "abcd"); clopen(); long nid = n1.getLongId(); uid = tx.getPropertyKey("name"); assertTrue(tx.containsVertex(nid)); assertTrue(tx.containsVertex(uid.getLongId())); assertFalse(tx.containsVertex(nid + 64)); uid = tx.getPropertyKey(uid.getName()); n1 = tx.getVertex(nid); assertEquals(n1,Iterables.getOnlyElement(tx.getVertices(uid, "abcd"))); assertEquals(1, Iterables.size(n1.query().relations())); assertTrue(n1.getProperty(uid).equals("abcd")); assertEquals(1,Iterables.size(tx.getVertices())); close(); TitanCleanup.clear(graph); open(config); assertTrue(Iterables.isEmpty(tx.getVertices())); }
TitanVertex v1 = tx.addVertex(); TitanVertex v2 = tx.addVertex(); TitanProperty p = v1.addProperty("name","xyz"); p.setProperty("time",15); Edge e = v1.addEdge("related",v2);
Edge e2 = n1.addEdge("friend",n3); e.setProperty(id, 111); n3.addProperty(id, 445); assertEquals(111, e.getProperty(id)); graph.commit(); TitanProperty p = Iterables.getOnlyElement(n3.getProperties("uid")); p.remove(); n3.addProperty("uid", 353);
Edge e2 = n1.addEdge("friend",n3); e.setProperty(id, 111); n3.addProperty(id, 445); assertEquals(111, e.getProperty(id)); graph.commit(); TitanProperty p = Iterables.getOnlyElement(n3.getProperties("uid")); p.remove(); n3.addProperty("uid", 353);
@Test public void testBasic() { TitanKey weight = makeWeightPropertyKey("weight"); TitanVertex n1 = tx.addVertex(); n1.addProperty(weight, 10.5); clopen(); long nid = n1.getID(); assertTrue(tx.containsVertex(nid)); assertTrue(tx.containsVertex(weight.getID())); assertFalse(tx.containsVertex(nid + 64)); assertFalse(tx.containsVertex(weight.getID() + 64)); assertTrue(tx.containsType("weight")); weight = tx.getPropertyKey("weight"); assertEquals(weight.getDataType(), Double.class); assertEquals(weight.getName(), "weight"); n1 = tx.getVertex(nid); for (TitanProperty prop : n1.getProperties()) { Object o = prop.getValue(); } n1.query().relations(); assertEquals(10.5, n1.getProperty(weight)); }
private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) { clopen(option(INDEX_NAME_MAPPING,INDEX),sameNameMapping); TitanGraphIndex vindex = getExternalIndex(Vertex.class,INDEX); TitanGraphIndex eindex = getExternalIndex(Edge.class,INDEX); TitanGraphIndex pindex = getExternalIndex(TitanProperty.class,INDEX); PropertyKey name = makeKey("name",String.class); mgmt.addIndexKey(vindex, name, getStringMapping()); mgmt.addIndexKey(eindex, name, getStringMapping()); mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr")); PropertyKey text = makeKey("text",String.class); mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name","xtext")); mgmt.addIndexKey(eindex, text, getTextMapping()); mgmt.addIndexKey(pindex, text, getTextMapping()); mgmt.makeEdgeLabel("knows").signature(name).make(); mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make(); finishSchema(); TitanVertex previous = null; for (int i=0;i<numV;i++) { TitanVertex v = graph.addVertex(null); v.setProperty("name",strs[i%strs.length]); v.setProperty("text",strs[i%strs.length]); TitanEdge e = v.addEdge("knows",previous==null?v:previous); e.setProperty("name",strs[i%strs.length]); e.setProperty("text",strs[i%strs.length]); TitanProperty p = v.addProperty("uid","v"+i); p.setProperty("name", strs[i % strs.length]); p.setProperty("text", strs[i % strs.length]); previous=v; } }