Search in sources :

Example 11 with TitanGraphIndex

use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project titan by thinkaurelius.

the class TitanIndexTest method testIndexUpdatesWithoutReindex.

@Test
public void testIndexUpdatesWithoutReindex() throws InterruptedException, ExecutionException {
    Object[] settings = new Object[] { option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250) };
    clopen(settings);
    final String defText = "Mountain rocks are great friends";
    final int defTime = 5;
    final double defHeight = 101.1;
    final String[] defPhones = new String[] { "1234", "5678" };
    //Creates types and index only two keys key
    mgmt.makePropertyKey("time").dataType(Integer.class).make();
    PropertyKey text = mgmt.makePropertyKey("text").dataType(String.class).make();
    mgmt.makePropertyKey("height").dataType(Double.class).make();
    if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
        mgmt.makePropertyKey("phone").dataType(String.class).cardinality(Cardinality.LIST).make();
    }
    mgmt.buildIndex("theIndex", Vertex.class).addKey(text, getTextMapping(), getFieldMap(text)).buildMixedIndex(INDEX);
    finishSchema();
    //Add initial data
    addVertex(defTime, defText, defHeight, defPhones);
    //Indexes should not yet be in use
    clopen(settings);
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 1, new boolean[] { false, true });
    evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 1, new boolean[] { false, true });
    evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 1, new boolean[] { false, true });
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 1, new boolean[] { false, true }, "theIndex");
    if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
        evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
        evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 1, new boolean[] { false, true });
    }
    newTx();
    //Add another key to index ------------------------------------------------------
    finishSchema();
    PropertyKey time = mgmt.getPropertyKey("time");
    mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), time, getFieldMap(time));
    finishSchema();
    newTx();
    //Add more data
    addVertex(defTime, defText, defHeight, defPhones);
    tx.commit();
    //Should not yet be able to enable since not yet registered
    assertNull(mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX));
    //This call is redundant and just here to make sure it doesn't mess anything up
    mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.REGISTER_INDEX).get();
    mgmt.commit();
    ManagementSystem.awaitGraphIndexStatus(graph, "theIndex").timeout(10L, ChronoUnit.SECONDS).call();
    finishSchema();
    mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX).get();
    finishSchema();
    //Add more data
    addVertex(defTime, defText, defHeight, defPhones);
    //One more key should be indexed but only sees partial data
    clopen(settings);
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 3, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 3, new boolean[] { false, true });
    evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 2, new boolean[] { false, true }, "theIndex");
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 2, new boolean[] { false, true }, "theIndex");
    if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
        evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 3, new boolean[] { false, true });
        evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 3, new boolean[] { false, true });
    }
    newTx();
    //Add another key to index ------------------------------------------------------
    finishSchema();
    PropertyKey height = mgmt.getPropertyKey("height");
    mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), height);
    if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
        PropertyKey phone = mgmt.getPropertyKey("phone");
        mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), phone, new Parameter("mapping", Mapping.STRING));
    }
    finishSchema();
    //Add more data
    addVertex(defTime, defText, defHeight, defPhones);
    tx.commit();
    mgmt.commit();
    ManagementUtil.awaitGraphIndexUpdate(graph, "theIndex", 10, ChronoUnit.SECONDS);
    finishSchema();
    mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.ENABLE_INDEX);
    finishSchema();
    TitanGraphIndex index = mgmt.getGraphIndex("theIndex");
    for (PropertyKey key : index.getFieldKeys()) {
        assertEquals(SchemaStatus.ENABLED, index.getIndexStatus(key));
    }
    //Add more data
    addVertex(defTime, defText, defHeight, defPhones);
    //One more key should be indexed but only sees partial data
    clopen(settings);
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 4, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
    if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
        evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
        evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "theIndex");
    }
    newTx();
    finishSchema();
    mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.REINDEX).get();
    mgmt.commit();
    finishSchema();
    //All the data should now be in the index
    clopen(settings);
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().interval("height", 100, 200), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().interval("height", 100, 200).has("time", 5), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
    evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks").has("time", 5).interval("height", 100, 200), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
    if (indexFeatures.supportsCardinality(Cardinality.LIST)) {
        evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "1234"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
        evaluateQuery(tx.query().has("phone", Cmp.EQUAL, "5678"), ElementCategory.VERTEX, 5, new boolean[] { true, true }, "theIndex");
    }
    mgmt.updateIndex(mgmt.getGraphIndex("theIndex"), SchemaAction.DISABLE_INDEX).get();
    tx.commit();
    mgmt.commit();
    ManagementUtil.awaitGraphIndexUpdate(graph, "theIndex", 10, ChronoUnit.SECONDS);
    finishSchema();
    index = mgmt.getGraphIndex("theIndex");
    for (PropertyKey key : index.getFieldKeys()) {
        assertEquals(SchemaStatus.DISABLED, index.getIndexStatus(key));
    }
    newTx();
    //This now requires a full graph scan
    evaluateQuery(tx.query().has("time", 5), ElementCategory.VERTEX, 5, new boolean[] { false, true });
}
Also used : Parameter(com.thinkaurelius.titan.core.schema.Parameter) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 12 with TitanGraphIndex

use of com.thinkaurelius.titan.core.schema.TitanGraphIndex 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 13 with TitanGraphIndex

use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project incubator-atlas by apache.

the class Titan0GraphManagement method addVertexIndexKey.

@Override
public void addVertexIndexKey(String indexName, AtlasPropertyKey propertyKey) {
    PropertyKey titanKey = TitanObjectFactory.createPropertyKey(propertyKey);
    TitanGraphIndex vertexIndex = management.getGraphIndex(indexName);
    management.addIndexKey(vertexIndex, titanKey);
}
Also used : TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 14 with TitanGraphIndex

use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project incubator-atlas by apache.

the class Titan1Graph method getIndexKeys.

private Set<String> getIndexKeys(Class<? extends Element> titanElementClass) {
    TitanManagement mgmt = getGraph().openManagement();
    Iterable<TitanGraphIndex> indices = mgmt.getGraphIndexes(titanElementClass);
    Set<String> result = new HashSet<String>();
    for (TitanGraphIndex index : indices) {
        result.add(index.name());
    }
    mgmt.commit();
    return result;
}
Also used : TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) HashSet(java.util.HashSet)

Example 15 with TitanGraphIndex

use of com.thinkaurelius.titan.core.schema.TitanGraphIndex in project incubator-atlas by apache.

the class Titan1GraphManagement method addVertexIndexKey.

@Override
public void addVertexIndexKey(String indexName, AtlasPropertyKey propertyKey) {
    PropertyKey titanKey = TitanObjectFactory.createPropertyKey(propertyKey);
    TitanGraphIndex vertexIndex = management.getGraphIndex(indexName);
    management.addIndexKey(vertexIndex, titanKey);
}
Also used : TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Aggregations

TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)31 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)20 Test (org.junit.Test)16 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)13 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)10 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)8 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)7 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)7 BaseVertexLabel (com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel)6 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)5 CompositeIndexType (com.thinkaurelius.titan.graphdb.types.CompositeIndexType)4 TitanSchemaVertex (com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)4 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)3 ScanMetrics (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics)3 IndexType (com.thinkaurelius.titan.graphdb.types.IndexType)3 MixedIndexType (com.thinkaurelius.titan.graphdb.types.MixedIndexType)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 RelationType (com.thinkaurelius.titan.core.RelationType)2 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)2 TitanException (com.thinkaurelius.titan.core.TitanException)2