use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanIndexTest method testSimpleUpdate.
@Test
public void testSimpleUpdate() {
PropertyKey name = makeKey("name", String.class);
EdgeLabel knows = makeLabel("knows");
mgmt.buildIndex("namev", Vertex.class).addKey(name).buildMixedIndex(INDEX);
mgmt.buildIndex("namee", Edge.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
TitanVertex v = tx.addVertex("name", "Marko Rodriguez");
Edge e = v.addEdge("knows", v, "name", "Hulu Bubab");
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
assertCount(1, tx.query().has("name", Text.CONTAINS, "Hulu").edges());
for (Vertex u : tx.getVertices()) assertEquals("Marko Rodriguez", u.value("name"));
clopen();
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
assertCount(1, tx.query().has("name", Text.CONTAINS, "Hulu").edges());
for (Vertex u : tx.getVertices()) assertEquals("Marko Rodriguez", u.value("name"));
v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko"));
v.property(VertexProperty.Cardinality.single, "name", "Marko");
e = getOnlyEdge(v.query().direction(Direction.OUT));
e.property("name", "Tubu Rubu");
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
assertCount(1, tx.query().has("name", Text.CONTAINS, "Rubu").edges());
assertCount(0, tx.query().has("name", Text.CONTAINS, "Hulu").edges());
for (Vertex u : tx.getVertices()) assertEquals("Marko", u.value("name"));
clopen();
assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices());
assertCount(1, tx.query().has("name", Text.CONTAINS, "Rubu").edges());
assertCount(0, tx.query().has("name", Text.CONTAINS, "Hulu").edges());
for (Vertex u : tx.getVertices()) assertEquals("Marko", u.value("name"));
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanIndexTest method testVertexTTLWithMixedIndices.
/* ==================================================================================
TIME-TO-LIVE
==================================================================================*/
@Test
public void testVertexTTLWithMixedIndices() throws Exception {
if (!features.hasCellTTL() || !indexFeatures.supportsDocumentTTL()) {
return;
}
PropertyKey name = makeKey("name", String.class);
PropertyKey time = makeKey("time", Long.class);
PropertyKey text = makeKey("text", String.class);
VertexLabel event = mgmt.makeVertexLabel("event").setStatic().make();
final int eventTTLSeconds = (int) TestGraphConfigs.getTTL(TimeUnit.SECONDS);
mgmt.setTTL(event, Duration.ofSeconds(eventTTLSeconds));
mgmt.buildIndex("index1", Vertex.class).addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX);
mgmt.buildIndex("index2", Vertex.class).indexOnly(event).addKey(text, getTextMapping()).buildMixedIndex(INDEX);
assertEquals(Duration.ZERO, mgmt.getTTL(name));
assertEquals(Duration.ZERO, mgmt.getTTL(time));
assertEquals(Duration.ofSeconds(eventTTLSeconds), mgmt.getTTL(event));
finishSchema();
TitanVertex v1 = tx.addVertex("event");
v1.property(VertexProperty.Cardinality.single, "name", "first event");
v1.property(VertexProperty.Cardinality.single, "text", "this text will help to identify the first event");
long time1 = System.currentTimeMillis();
v1.property(VertexProperty.Cardinality.single, "time", time1);
TitanVertex v2 = tx.addVertex("event");
v2.property(VertexProperty.Cardinality.single, "name", "second event");
v2.property(VertexProperty.Cardinality.single, "text", "this text won't match");
long time2 = time1 + 1;
v2.property(VertexProperty.Cardinality.single, "time", time2);
evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr), ElementCategory.VERTEX, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "index2");
clopen();
Object v1Id = v1.id();
Object v2Id = v2.id();
evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr), ElementCategory.VERTEX, 1, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "index2");
v1 = getV(tx, v1Id);
v2 = getV(tx, v1Id);
assertNotNull(v1);
assertNotNull(v2);
Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));
clopen();
Thread.sleep(TimeUnit.MILLISECONDS.convert((long) Math.ceil(eventTTLSeconds * 1.25), TimeUnit.SECONDS));
evaluateQuery(tx.query().has("text", Text.CONTAINS, "help").has(LABEL_NAME, "event"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "index2");
evaluateQuery(tx.query().has("name", "first event").orderBy("time", decr), ElementCategory.VERTEX, 0, new boolean[] { true, true }, tx.getPropertyKey("time"), Order.DESC, "index1");
v1 = getV(tx, v1Id);
v2 = getV(tx, v2Id);
assertNull(v1);
assertNull(v2);
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanIndexTest method testCompositeAndMixedIndexing.
@Test
public void testCompositeAndMixedIndexing() {
PropertyKey name = makeKey("name", String.class);
PropertyKey weight = makeKey("weight", Double.class);
PropertyKey text = makeKey("text", String.class);
PropertyKey flag = makeKey("flag", Boolean.class);
TitanGraphIndex composite = mgmt.buildIndex("composite", Vertex.class).addKey(name).addKey(weight).buildCompositeIndex();
TitanGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(weight).addKey(text, getTextMapping()).buildMixedIndex(INDEX);
mixed.name();
composite.name();
finishSchema();
final int numV = 100;
String[] strs = { "houseboat", "humanoid", "differential", "extraordinary" };
String[] strs2 = new String[strs.length];
for (int i = 0; i < strs.length; i++) strs2[i] = strs[i] + " " + strs[i];
final int modulo = 5;
final int divisor = modulo * strs.length;
for (int i = 0; i < numV; i++) {
TitanVertex v = tx.addVertex();
v.property("name", strs[i % strs.length]);
v.property("text", strs[i % strs.length]);
v.property("weight", (i % modulo) + 0.5);
v.property("flag", true);
}
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, true });
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has("flag"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, true }, mixed.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, composite.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, composite.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name(), composite.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name(), composite.name());
clopen();
//Same queries as above
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, true });
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]), ElementCategory.VERTEX, numV / strs.length, new boolean[] { true, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[0]).has("flag"), ElementCategory.VERTEX, numV / strs.length, new boolean[] { false, true }, mixed.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, composite.name());
evaluateQuery(tx.query().has("name", Cmp.EQUAL, strs[0]).has("weight", Cmp.EQUAL, 1.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, composite.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[2]).has("weight", Cmp.EQUAL, 2.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5), ElementCategory.VERTEX, numV / divisor, new boolean[] { true, true }, mixed.name(), composite.name());
evaluateQuery(tx.query().has("text", Text.CONTAINS, strs[3]).has("name", Cmp.EQUAL, strs[3]).has("weight", Cmp.EQUAL, 3.5).has("flag"), ElementCategory.VERTEX, numV / divisor, new boolean[] { false, true }, mixed.name(), composite.name());
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanIndexTest method testWidcardQuery.
/**
* Tests indexing using _all virtual field
*/
@Test
public void testWidcardQuery() {
if (supportsWildcardQuery()) {
PropertyKey p1 = makeKey("p1", String.class);
PropertyKey p2 = makeKey("p2", String.class);
mgmt.buildIndex("mixedIndex", Vertex.class).addKey(p1).addKey(p2).buildMixedIndex(INDEX);
finishSchema();
clopen();
TitanVertex v1 = graph.addVertex();
v1.property("p1", "test1");
v1.property("p2", "test2");
//Flush the index
clopen();
assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test1\"").vertices().iterator().next().getElement());
assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test2\"").vertices().iterator().next().getElement());
}
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class CassandraScanJobIT method testPartitionedVertexFilteredScan.
@Test
public void testPartitionedVertexFilteredScan() throws Exception {
tearDown();
clearGraph(getConfiguration());
WriteConfiguration partConf = getConfiguration();
open(partConf);
mgmt.makeVertexLabel("part").partition().make();
finishSchema();
TitanVertex supernode = graph.addVertex("part");
for (int i = 0; i < 128; i++) {
TitanVertex v = graph.addVertex("part");
v.addEdge("default", supernode);
if (0 < i && 0 == i % 4)
graph.tx().commit();
}
graph.tx().commit();
org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration();
c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName());
c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift");
c.set(ConfigElement.getPath(TitanHadoopConfiguration.FILTER_PARTITIONED_VERTICES), "true");
c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner");
Job job = getVertexJobWithDefaultMapper(c);
// Should succeed
assertTrue(job.waitForCompletion(true));
}
Aggregations