Search in sources :

Example 16 with PropertyKey

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

the class TitanGraphTest method evaluateQuery.

public static void evaluateQuery(TitanVertexQuery query, RelationCategory resultType, int expectedResults, int numSubQueries, boolean[] subQuerySpecs, Map<PropertyKey, Order> orderMap) {
    SimpleQueryProfiler profiler = new SimpleQueryProfiler();
    ((BasicVertexCentricQueryBuilder) query).profiler(profiler);
    Iterable<? extends TitanElement> result;
    switch(resultType) {
        case PROPERTY:
            result = query.properties();
            break;
        case EDGE:
            result = query.edges();
            break;
        case RELATION:
            result = query.relations();
            break;
        default:
            throw new AssertionError();
    }
    OrderList orders = profiler.getAnnotation(QueryProfiler.ORDERS_ANNOTATION);
    //Check elements and that they are returned in the correct order
    int no = 0;
    TitanElement previous = null;
    for (TitanElement e : result) {
        assertNotNull(e);
        no++;
        if (previous != null && !orders.isEmpty()) {
            assertTrue(orders.compare(previous, e) <= 0);
        }
        previous = e;
    }
    assertEquals(expectedResults, no);
    //Check OrderList of query
    assertNotNull(orders);
    assertEquals(orderMap.size(), orders.size());
    for (int i = 0; i < orders.size(); i++) {
        assertEquals(orderMap.get(orders.getKey(i)), orders.getOrder(i));
    }
    for (PropertyKey key : orderMap.keySet()) assertTrue(orders.containsKey(key));
    //Check subqueries
    assertEquals(1, (Number) profiler.getAnnotation(QueryProfiler.NUMVERTICES_ANNOTATION));
    int subQueryCounter = 0;
    for (SimpleQueryProfiler subProfiler : profiler) {
        assertNotNull(subProfiler);
        if (subProfiler.getGroupName().equals(QueryProfiler.OPTIMIZATION))
            continue;
        if (subQuerySpecs.length == 2) {
            //0=>fitted, 1=>ordered
            assertEquals(subQuerySpecs[0], (Boolean) subProfiler.getAnnotation(QueryProfiler.FITTED_ANNOTATION));
            assertEquals(subQuerySpecs[1], (Boolean) subProfiler.getAnnotation(QueryProfiler.ORDERED_ANNOTATION));
        }
        //assertEquals(1,Iterables.size(subProfiler)); This only applies if a disk call is necessary
        subQueryCounter++;
    }
    assertEquals(numSubQueries, subQueryCounter);
}
Also used : BasicVertexCentricQueryBuilder(com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder) TitanElement(com.thinkaurelius.titan.core.TitanElement) OrderList(com.thinkaurelius.titan.graphdb.internal.OrderList) SimpleQueryProfiler(com.thinkaurelius.titan.graphdb.query.profile.SimpleQueryProfiler) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 17 with PropertyKey

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

the class TitanGraphTest method testIndexQueryWithLabelsAndContainsIN.

@Test
public void testIndexQueryWithLabelsAndContainsIN() {
    // This test is based on the steps to reproduce #882
    String labelName = "labelName";
    VertexLabel label = mgmt.makeVertexLabel(labelName).make();
    PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make();
    TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex();
    mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK);
    finishSchema();
    TitanVertex foo = graph.addVertex(labelName);
    TitanVertex bar = graph.addVertex(labelName);
    foo.property("uid", "foo");
    bar.property("uid", "bar");
    graph.tx().commit();
    Iterable<TitanVertex> vertexes = graph.query().has("uid", Contain.IN, ImmutableList.of("foo", "bar")).has(LABEL_NAME, labelName).vertices();
    assertEquals(2, Iterables.size(vertexes));
    for (TitanVertex v : vertexes) {
        assertEquals(labelName, v.vertexLabel().name());
    }
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) BaseVertexLabel(com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel) VertexLabel(com.thinkaurelius.titan.core.VertexLabel) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 18 with PropertyKey

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

the class TitanGraphTest method testMultivaluedVertexProperty.

/**
     * Tests multi-valued properties with special focus on indexing and incident unidirectional edges
     * which is not tested in {@link #testSchemaTypes()}
     * <p/>
     * -->TODO: split and move this into other test cases: ordering to query, indexing to index
     */
@Test
public <V> void testMultivaluedVertexProperty() {
    /*
         * Constant test data
         *
         * The values list below must have at least two elements. The string
         * literals were chosen arbitrarily and have no special significance.
         */
    final String foo = "foo", bar = "bar", weight = "weight";
    final List<String> values = ImmutableList.of("four", "score", "and", "seven");
    assertTrue("Values list must have multiple elements for this test to make sense", 2 <= values.size());
    // Create property with name pname and a vertex
    PropertyKey w = makeKey(weight, Integer.class);
    PropertyKey f = ((StandardPropertyKeyMaker) mgmt.makePropertyKey(foo)).dataType(String.class).cardinality(Cardinality.LIST).sortKey(w).sortOrder(Order.DESC).make();
    mgmt.buildIndex(foo, Vertex.class).addKey(f).buildCompositeIndex();
    PropertyKey b = mgmt.makePropertyKey(bar).dataType(String.class).cardinality(Cardinality.LIST).make();
    mgmt.buildIndex(bar, Vertex.class).addKey(b).buildCompositeIndex();
    finishSchema();
    TitanVertex v = tx.addVertex();
    // Insert prop values
    int i = 0;
    for (String s : values) {
        v.property(foo, s, weight, ++i);
        v.property(bar, s, weight, i);
    }
    //Verify correct number of properties
    assertCount(values.size(), v.properties(foo));
    assertCount(values.size(), v.properties(bar));
    //Verify order
    for (String prop : new String[] { foo, bar }) {
        int sum = 0;
        int index = values.size();
        for (TitanVertexProperty<String> p : v.query().labels(foo).properties()) {
            assertTrue(values.contains(p.value()));
            int wint = p.value(weight);
            sum += wint;
            if (prop == foo)
                assertEquals(index, wint);
            index--;
        }
        assertEquals(values.size() * (values.size() + 1) / 2, sum);
    }
    assertCount(1, tx.query().has(foo, values.get(1)).vertices());
    assertCount(1, tx.query().has(foo, values.get(3)).vertices());
    assertCount(1, tx.query().has(bar, values.get(1)).vertices());
    assertCount(1, tx.query().has(bar, values.get(3)).vertices());
    // Check that removing properties works
    asStream(v.properties(foo)).forEach(p -> p.remove());
    // Check that the properties were actually deleted from v
    assertEmpty(v.properties(foo));
    // Reopen database
    clopen();
    assertCount(0, tx.query().has(foo, values.get(1)).vertices());
    assertCount(0, tx.query().has(foo, values.get(3)).vertices());
    assertCount(1, tx.query().has(bar, values.get(1)).vertices());
    assertCount(1, tx.query().has(bar, values.get(3)).vertices());
    // Retrieve and check our test vertex
    v = getV(tx, v);
    assertEmpty(v.properties(foo));
    assertCount(values.size(), v.properties(bar));
    // Reinsert prop values
    for (String s : values) {
        v.property(foo, s);
    }
    assertCount(values.size(), v.properties(foo));
    // Check that removing properties works
    asStream(v.properties(foo)).forEach(p -> p.remove());
    // Check that the properties were actually deleted from v
    assertEmpty(v.properties(foo));
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) StandardPropertyKeyMaker(com.thinkaurelius.titan.graphdb.types.StandardPropertyKeyMaker) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 19 with PropertyKey

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

the class TitanGraphTest method testBasic.

/**
     * 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.property(uid.name(), "abcd");
    clopen();
    long nid = n1.longId();
    uid = tx.getPropertyKey("name");
    assertTrue(getV(tx, nid) != null);
    assertTrue(getV(tx, uid.longId()) != null);
    assertMissing(tx, nid + 64);
    uid = tx.getPropertyKey(uid.name());
    n1 = getV(tx, nid);
    assertEquals(n1, getOnlyVertex(tx.query().has(uid.name(), "abcd")));
    //TODO: how to expose relations?
    assertEquals(1, Iterables.size(n1.query().relations()));
    assertEquals("abcd", n1.value(uid.name()));
    assertCount(1, tx.query().vertices());
    close();
    TitanCleanup.clear(graph);
    open(config);
    assertEmpty(tx.query().vertices());
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 20 with PropertyKey

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

the class TitanGraphTest method testStaleVertex.

@Test
public void testStaleVertex() {
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
    mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex();
    finishSchema();
    TitanVertex cartman = graph.addVertex("name", "cartman", "age", 10);
    TitanVertex stan = graph.addVertex("name", "stan", "age", 8);
    graph.tx().commit();
    cartman = getOnlyElement(graph.query().has("name", "cartman").vertices());
    graph.tx().commit();
    TitanVertexProperty p = (TitanVertexProperty) cartman.properties().next();
    assertTrue(((Long) p.longId()) > 0);
    graph.tx().commit();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanVertexProperty(com.thinkaurelius.titan.core.TitanVertexProperty) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

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