Search in sources :

Example 36 with TitanVertex

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) {
        }
    }
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Instant(java.time.Instant) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) TitanException(com.thinkaurelius.titan.core.TitanException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 37 with TitanVertex

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))));
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Date(java.util.Date) Test(org.junit.Test)

Example 38 with TitanVertex

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);
}
Also used : PreloadedVertex(com.thinkaurelius.titan.graphdb.vertices.PreloadedVertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) Map(java.util.Map) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Example 39 with TitanVertex

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);
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EntryList(com.thinkaurelius.titan.diskstorage.EntryList) CacheVertex(com.thinkaurelius.titan.graphdb.vertices.CacheVertex) TitanRelation(com.thinkaurelius.titan.core.TitanRelation) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)

Example 40 with TitanVertex

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);
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType)

Aggregations

TitanVertex (com.thinkaurelius.titan.core.TitanVertex)77 Test (org.junit.Test)63 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)46 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)21 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)17 Edge (org.apache.tinkerpop.gremlin.structure.Edge)17 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)14 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)12 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)12 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)10 BaseVertexLabel (com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)8 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)7 ElementCategory (com.thinkaurelius.titan.graphdb.internal.ElementCategory)4 Category (org.junit.experimental.categories.Category)4 SchemaViolationException (com.thinkaurelius.titan.core.SchemaViolationException)3 VertexList (com.thinkaurelius.titan.core.VertexList)3 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)3 TitanGraphBaseTest (com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)3