Search in sources :

Example 26 with PropertyKey

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

the class TitanIndexTest method testIndexQueryWithScore.

@Test
public void testIndexQueryWithScore() throws InterruptedException {
    PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make();
    mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX);
    mgmt.commit();
    TitanVertex v1 = tx.addVertex();
    TitanVertex v2 = tx.addVertex();
    TitanVertex v3 = tx.addVertex();
    v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello");
    v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf");
    v3.property("text", "Hello");
    tx.commit();
    Thread.sleep(5000);
    Set<Double> scores = new HashSet<Double>();
    for (TitanIndexQuery.Result<TitanVertex> r : graph.indexQuery("store1", "v.text:(Hello)").vertices()) {
        scores.add(r.getScore());
    }
    Assert.assertEquals(3, scores.size());
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanIndexQuery(com.thinkaurelius.titan.core.TitanIndexQuery) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with PropertyKey

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

the class TitanIndexTest method testIndexing.

private void testIndexing(Cardinality cardinality) {
    if (supportsCollections()) {
        PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make();
        PropertyKey intProperty = mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(cardinality).make();
        PropertyKey longProperty = mgmt.makePropertyKey("long").dataType(Long.class).cardinality(cardinality).make();
        PropertyKey uuidProperty = mgmt.makePropertyKey("uuid").dataType(UUID.class).cardinality(cardinality).make();
        PropertyKey geoProperty = mgmt.makePropertyKey("geo").dataType(Geoshape.class).cardinality(cardinality).make();
        mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).addKey(intProperty).addKey(longProperty).addKey(uuidProperty).addKey(geoProperty).buildMixedIndex(INDEX);
        finishSchema();
        testCollection(cardinality, "name", "Totoro", "Hiro");
        testCollection(cardinality, "age", 1, 2);
        testCollection(cardinality, "long", 1L, 2L);
        testCollection(cardinality, "uuid", UUID.randomUUID(), UUID.randomUUID());
        testCollection(cardinality, "geo", Geoshape.point(1.0, 1.0), Geoshape.point(2.0, 2.0));
    } else {
        try {
            PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make();
            //This should throw an exception
            mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX);
            Assert.fail("Should have thrown an exception");
        } catch (TitanException e) {
        }
    }
}
Also used : TitanException(com.thinkaurelius.titan.core.TitanException) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 28 with PropertyKey

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

the class TitanIndexTest method testContainsWithMultipleValues.

@Test
public // so we need to make sure that we don't apply AND twice.
void testContainsWithMultipleValues() throws Exception {
    PropertyKey name = makeKey("name", String.class);
    mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX);
    mgmt.commit();
    TitanVertex v1 = tx.addVertex();
    v1.property("name", "hercules was here");
    tx.commit();
    Thread.sleep(2000);
    TitanVertex r = Iterables.<TitanVertex>get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0);
    Assert.assertEquals(r.property("name").value(), "hercules was here");
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 29 with PropertyKey

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

the class TitanIndexTest method setupChainGraph.

private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) {
    clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping);
    TitanGraphIndex vindex = getExternalIndex(Vertex.class, INDEX);
    TitanGraphIndex eindex = getExternalIndex(Edge.class, INDEX);
    TitanGraphIndex pindex = getExternalIndex(TitanVertexProperty.class, INDEX);
    PropertyKey name = makeKey("name", String.class);
    mgmt.addIndexKey(vindex, name, getStringMapping());
    mgmt.addIndexKey(eindex, name, getStringMapping());
    mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr"));
    PropertyKey text = makeKey("text", String.class);
    mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext"));
    mgmt.addIndexKey(eindex, text, getTextMapping());
    mgmt.addIndexKey(pindex, text, getTextMapping());
    mgmt.makeEdgeLabel("knows").signature(name).make();
    mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make();
    finishSchema();
    TitanVertex previous = null;
    for (int i = 0; i < numV; i++) {
        TitanVertex v = graph.addVertex("name", strs[i % strs.length], "text", strs[i % strs.length]);
        Edge e = v.addEdge("knows", previous == null ? v : previous, "name", strs[i % strs.length], "text", strs[i % strs.length]);
        VertexProperty p = v.property("uid", "v" + i, "name", strs[i % strs.length], "text", strs[i % strs.length]);
        previous = v;
    }
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) TitanVertexProperty(com.thinkaurelius.titan.core.TitanVertexProperty) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 30 with PropertyKey

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

the class TitanIndexTest method testNestedWrites.

private void testNestedWrites(String initialValue, String updatedValue) throws BackendException {
    // This method touches a single vertex with multiple transactions,
    // leading to deadlock under BDB and cascading test failures. Check for
    // the hasTxIsolation() store feature, which is currently true for BDB
    // but false for HBase/Cassandra. This is kind of a hack; a more robust
    // approach might implement different methods/assertions depending on
    // whether the store is capable of deadlocking or detecting conflicting
    // writes and aborting a transaction.
    Backend b = null;
    try {
        b = graph.getConfiguration().getBackend();
        if (b.getStoreFeatures().hasTxIsolation()) {
            log.info("Skipping " + getClass().getSimpleName() + "." + methodName.getMethodName());
            return;
        }
    } finally {
        if (null != b)
            b.close();
    }
    final String propName = "foo";
    // Write schema and one vertex
    PropertyKey prop = makeKey(propName, String.class);
    createExternalVertexIndex(prop, INDEX);
    finishSchema();
    TitanVertex v = graph.addVertex();
    if (null != initialValue)
        v.property(VertexProperty.Cardinality.single, propName, initialValue);
    graph.tx().commit();
    Object id = v.id();
    // Open two transactions and modify the same vertex
    TitanTransaction vertexDeleter = graph.newTransaction();
    TitanTransaction propDeleter = graph.newTransaction();
    getV(vertexDeleter, id).remove();
    if (null == updatedValue)
        getV(propDeleter, id).property(propName).remove();
    else
        getV(propDeleter, id).property(VertexProperty.Cardinality.single, propName, updatedValue);
    vertexDeleter.commit();
    propDeleter.commit();
    // The vertex must not exist after deletion
    graph.tx().rollback();
    assertEquals(null, getV(graph, id));
    assertEmpty(graph.query().has(propName).vertices());
    if (null != updatedValue)
        assertEmpty(graph.query().has(propName, updatedValue).vertices());
    graph.tx().rollback();
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Backend(com.thinkaurelius.titan.diskstorage.Backend) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

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