Search in sources :

Example 31 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.

the class TitanIndexTest method testBooleanIndexing.

/**
     * Tests indexing boolean
     */
@Test
public void testBooleanIndexing() {
    PropertyKey name = makeKey("visible", Boolean.class);
    mgmt.buildIndex("booleanIndex", Vertex.class).addKey(name).buildMixedIndex(INDEX);
    finishSchema();
    clopen();
    TitanVertex v1 = graph.addVertex();
    v1.property("visible", true);
    TitanVertex v2 = graph.addVertex();
    v2.property("visible", false);
    assertCount(2, graph.vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
    //Flush the index
    clopen();
    assertCount(2, graph.vertices());
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", true)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", false)));
    assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true)));
    assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false)));
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 32 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey 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 33 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey 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 34 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.

the class BaseVertexCentricQueryBuilder method orderBy.

@Override
public Q orderBy(String keyName, org.apache.tinkerpop.gremlin.process.traversal.Order order) {
    Preconditions.checkArgument(schemaInspector.containsPropertyKey(keyName), "Provided key does not exist: %s", keyName);
    PropertyKey key = schemaInspector.getPropertyKey(keyName);
    Preconditions.checkArgument(key != null && order != null, "Need to specify and key and an order");
    Preconditions.checkArgument(Comparable.class.isAssignableFrom(key.dataType()), "Can only order on keys with comparable data type. [%s] has datatype [%s]", key.name(), key.dataType());
    Preconditions.checkArgument(key.cardinality() == Cardinality.SINGLE, "Ordering is undefined on multi-valued key [%s]", key.name());
    Preconditions.checkArgument(!(key instanceof SystemRelationType), "Cannot use system types in ordering: %s", key);
    Preconditions.checkArgument(!orders.containsKey(key));
    Preconditions.checkArgument(orders.isEmpty(), "Only a single sort order is supported on vertex queries");
    orders.add(key, Order.convert(order));
    return getThis();
}
Also used : SystemRelationType(com.thinkaurelius.titan.graphdb.types.system.SystemRelationType) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 35 with PropertyKey

use of com.thinkaurelius.titan.core.PropertyKey in project titan by thinkaurelius.

the class IndexTypeWrapper method getField.

@Override
public IndexField getField(PropertyKey key) {
    Map<PropertyKey, IndexField> result = fieldMap;
    if (result == null) {
        ImmutableMap.Builder<PropertyKey, IndexField> b = ImmutableMap.builder();
        for (IndexField f : getFieldKeys()) b.put(f.getFieldKey(), f);
        result = b.build();
        fieldMap = result;
    }
    assert result != null;
    return result.get(key);
}
Also used : IndexField(com.thinkaurelius.titan.graphdb.types.IndexField) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

PropertyKey (com.thinkaurelius.titan.core.PropertyKey)79 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)49 Test (org.junit.Test)49 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)21 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)20 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)18 Edge (org.apache.tinkerpop.gremlin.structure.Edge)15 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)14 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 AtlasPropertyKey (org.apache.atlas.repository.graphdb.AtlasPropertyKey)12 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)11 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)11 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)11 BaseVertexLabel (com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel)8 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)8 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)7 TitanException (com.thinkaurelius.titan.core.TitanException)6 HashSet (java.util.HashSet)6 Instant (java.time.Instant)5