use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanIndexTest method testInstantIndexing.
/**
* Tests indexing instants
*/
@Test
public void testInstantIndexing() {
PropertyKey name = makeKey("instant", Instant.class);
mgmt.buildIndex("instantIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
Instant firstTimestamp = Instant.ofEpochMilli(1);
Instant secondTimestamp = Instant.ofEpochMilli(2000);
TitanVertex v1 = graph.addVertex();
v1.property("instant", firstTimestamp);
TitanVertex v2 = graph.addVertex();
v2.property("instant", secondTimestamp);
testInstant(firstTimestamp, secondTimestamp, v1, v2);
firstTimestamp = Instant.ofEpochSecond(0, 1);
v1 = (TitanVertex) graph.vertices(v1.id()).next();
v1.property("instant", firstTimestamp);
if (indexFeatures.supportsNanoseconds()) {
testInstant(firstTimestamp, secondTimestamp, v1, v2);
} else {
//Flush the index
clopen();
try {
assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp)));
Assert.fail("Should have failed to update the index");
} catch (Exception e) {
}
}
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanIndexTest method testDateIndexing.
/**
* Tests indexing dates
*/
@Test
public void testDateIndexing() {
PropertyKey name = makeKey("date", Date.class);
mgmt.buildIndex("dateIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
finishSchema();
clopen();
TitanVertex v1 = graph.addVertex();
v1.property("date", new Date(1));
TitanVertex v2 = graph.addVertex();
v2.property("date", new Date(2000));
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));
//Flush the index
clopen();
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1))));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices()));
assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000))));
assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices()));
assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1))));
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class VertexJobConverter method process.
@Override
public void process(StaticBuffer key, Map<SliceQuery, EntryList> entries, ScanMetrics metrics) {
long vertexId = getVertexId(key);
assert entries.get(VERTEX_EXISTS_QUERY) != null;
if (isGhostVertex(vertexId, entries.get(VERTEX_EXISTS_QUERY))) {
metrics.incrementCustom(GHOST_VERTEX_COUNT);
return;
}
TitanVertex vertex = tx.getInternalVertex(vertexId);
Preconditions.checkArgument(vertex instanceof PreloadedVertex, "The bounding transaction is not configured correctly");
PreloadedVertex v = (PreloadedVertex) vertex;
v.setAccessCheck(PreloadedVertex.OPENSTAR_CHECK);
for (Map.Entry<SliceQuery, EntryList> entry : entries.entrySet()) {
SliceQuery sq = entry.getKey();
if (sq.equals(VERTEX_EXISTS_QUERY))
continue;
EntryList entryList = entry.getValue();
if (entryList.size() >= sq.getLimit())
metrics.incrementCustom(TRUNCATED_ENTRY_LISTS);
v.addToQueryCache(sq.updateLimit(Query.NO_LIMIT), entryList);
}
job.process(v, metrics);
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class GhostVertexRemover method process.
@Override
public void process(StaticBuffer key, Map<SliceQuery, EntryList> entries, ScanMetrics metrics) {
long vertexId = getVertexId(key);
assert entries.size() == 1;
assert entries.get(everythingQueryLimit) != null;
final EntryList everything = entries.get(everythingQueryLimit);
if (!isGhostVertex(vertexId, everything)) {
return;
}
if (everything.size() >= RELATION_COUNT_LIMIT) {
metrics.incrementCustom(SKIPPED_GHOST_LIMIT_COUNT);
return;
}
TitanVertex vertex = tx.getInternalVertex(vertexId);
Preconditions.checkArgument(vertex instanceof CacheVertex, "The bounding transaction is not configured correctly");
CacheVertex v = (CacheVertex) vertex;
v.loadRelations(EVERYTHING_QUERY, new Retriever<SliceQuery, EntryList>() {
@Override
public EntryList get(SliceQuery input) {
return everything;
}
});
int removedRelations = 0;
Iterator<TitanRelation> iter = v.query().noPartitionRestriction().relations().iterator();
while (iter.hasNext()) {
iter.next();
iter.remove();
removedRelations++;
}
//There should be no more system relations to remove
metrics.incrementCustom(REMOVED_VERTEX_COUNT);
metrics.incrementCustom(REMOVED_RELATION_COUNT, removedRelations);
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class ManagementSystem method getRelationIndex.
@Override
public RelationTypeIndex getRelationIndex(RelationType type, String name) {
Preconditions.checkArgument(type != null);
Preconditions.checkArgument(StringUtils.isNotBlank(name));
String composedName = composeRelationTypeIndexName(type, name);
//Don't use SchemaCache to make code more compact and since we don't need the extra performance here
TitanVertex v = Iterables.getOnlyElement(QueryUtil.getVertices(transaction, BaseKey.SchemaName, TitanSchemaCategory.getRelationTypeName(composedName)), null);
if (v == null)
return null;
assert v instanceof InternalRelationType;
return new RelationTypeIndexWrapper((InternalRelationType) v);
}
Aggregations