Search in sources :

Example 71 with PropertyKey

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

the class ManagementSystem method createCompositeIndex.

private TitanGraphIndex createCompositeIndex(String indexName, ElementCategory elementCategory, boolean unique, TitanSchemaType constraint, PropertyKey... keys) {
    checkIndexName(indexName);
    Preconditions.checkArgument(keys != null && keys.length > 0, "Need to provide keys to index [%s]", indexName);
    Preconditions.checkArgument(!unique || elementCategory == ElementCategory.VERTEX, "Unique indexes can only be created on vertices [%s]", indexName);
    boolean allSingleKeys = true;
    boolean oneNewKey = false;
    for (PropertyKey key : keys) {
        Preconditions.checkArgument(key != null && key instanceof PropertyKeyVertex, "Need to provide valid keys: %s", key);
        if (key.cardinality() != Cardinality.SINGLE)
            allSingleKeys = false;
        if (key.isNew())
            oneNewKey = true;
        else
            updatedTypes.add((PropertyKeyVertex) key);
    }
    Cardinality indexCardinality;
    if (unique)
        indexCardinality = Cardinality.SINGLE;
    else
        indexCardinality = (allSingleKeys ? Cardinality.SET : Cardinality.LIST);
    TypeDefinitionMap def = new TypeDefinitionMap();
    def.setValue(TypeDefinitionCategory.INTERNAL_INDEX, true);
    def.setValue(TypeDefinitionCategory.ELEMENT_CATEGORY, elementCategory);
    def.setValue(TypeDefinitionCategory.BACKING_INDEX, Token.INTERNAL_INDEX_NAME);
    def.setValue(TypeDefinitionCategory.INDEXSTORE_NAME, indexName);
    def.setValue(TypeDefinitionCategory.INDEX_CARDINALITY, indexCardinality);
    def.setValue(TypeDefinitionCategory.STATUS, oneNewKey ? SchemaStatus.ENABLED : SchemaStatus.INSTALLED);
    TitanSchemaVertex indexVertex = transaction.makeSchemaVertex(TitanSchemaCategory.GRAPHINDEX, indexName, def);
    for (int i = 0; i < keys.length; i++) {
        Parameter[] paras = { ParameterType.INDEX_POSITION.getParameter(i) };
        addSchemaEdge(indexVertex, keys[i], TypeDefinitionCategory.INDEX_FIELD, paras);
    }
    Preconditions.checkArgument(constraint == null || (elementCategory.isValidConstraint(constraint) && constraint instanceof TitanSchemaVertex));
    if (constraint != null) {
        addSchemaEdge(indexVertex, (TitanSchemaVertex) constraint, TypeDefinitionCategory.INDEX_SCHEMA_CONSTRAINT, null);
    }
    updateSchemaVertex(indexVertex);
    TitanGraphIndexWrapper index = new TitanGraphIndexWrapper(indexVertex.asIndexType());
    if (!oneNewKey)
        updateIndex(index, SchemaAction.REGISTER_INDEX);
    return index;
}
Also used : Cardinality(com.thinkaurelius.titan.core.Cardinality) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) Parameter(com.thinkaurelius.titan.core.schema.Parameter) PropertyKeyVertex(com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex) TypeDefinitionMap(com.thinkaurelius.titan.graphdb.types.TypeDefinitionMap) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 72 with PropertyKey

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

the class ManagementSystem method updateIndex.

/* --------------
    Schema Update
     --------------- */
@Override
public IndexJobFuture updateIndex(TitanIndex index, SchemaAction updateAction) {
    Preconditions.checkArgument(index != null, "Need to provide an index");
    Preconditions.checkArgument(updateAction != null, "Need to provide update action");
    TitanSchemaVertex schemaVertex = getSchemaVertex(index);
    Set<TitanSchemaVertex> dependentTypes;
    Set<PropertyKeyVertex> keySubset = ImmutableSet.of();
    if (index instanceof RelationTypeIndex) {
        dependentTypes = ImmutableSet.of((TitanSchemaVertex) ((InternalRelationType) schemaVertex).getBaseType());
        if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
            return null;
    } else if (index instanceof TitanGraphIndex) {
        IndexType indexType = schemaVertex.asIndexType();
        dependentTypes = Sets.newHashSet();
        if (indexType.isCompositeIndex()) {
            if (!updateAction.isApplicableStatus(schemaVertex.getStatus()))
                return null;
            for (PropertyKey key : ((TitanGraphIndex) index).getFieldKeys()) {
                dependentTypes.add((PropertyKeyVertex) key);
            }
        } else {
            keySubset = Sets.newHashSet();
            MixedIndexType cindexType = (MixedIndexType) indexType;
            Set<SchemaStatus> applicableStatus = updateAction.getApplicableStatus();
            for (ParameterIndexField field : cindexType.getFieldKeys()) {
                if (applicableStatus.contains(field.getStatus()))
                    keySubset.add((PropertyKeyVertex) field.getFieldKey());
            }
            if (keySubset.isEmpty())
                return null;
            dependentTypes.addAll(keySubset);
        }
    } else
        throw new UnsupportedOperationException("Updates not supported for index: " + index);
    IndexIdentifier indexId = new IndexIdentifier(index);
    StandardScanner.Builder builder;
    IndexJobFuture future;
    switch(updateAction) {
        case REGISTER_INDEX:
            setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
            updatedTypes.add(schemaVertex);
            updatedTypes.addAll(dependentTypes);
            setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.REGISTERED, keySubset));
            future = new EmptyIndexJobFuture();
            break;
        case REINDEX:
            builder = graph.getBackend().buildEdgeScanJob();
            builder.setFinishJob(indexId.getIndexJobFinisher(graph, SchemaAction.ENABLE_INDEX));
            builder.setJobId(indexId);
            builder.setJob(VertexJobConverter.convert(graph, new IndexRepairJob(indexId.indexName, indexId.relationTypeName)));
            try {
                future = builder.execute();
            } catch (BackendException e) {
                throw new TitanException(e);
            }
            break;
        case ENABLE_INDEX:
            setStatus(schemaVertex, SchemaStatus.ENABLED, keySubset);
            updatedTypes.add(schemaVertex);
            if (!keySubset.isEmpty())
                updatedTypes.addAll(dependentTypes);
            future = new EmptyIndexJobFuture();
            break;
        case DISABLE_INDEX:
            setStatus(schemaVertex, SchemaStatus.INSTALLED, keySubset);
            updatedTypes.add(schemaVertex);
            if (!keySubset.isEmpty())
                updatedTypes.addAll(dependentTypes);
            setUpdateTrigger(new UpdateStatusTrigger(graph, schemaVertex, SchemaStatus.DISABLED, keySubset));
            future = new EmptyIndexJobFuture();
            break;
        case REMOVE_INDEX:
            if (index instanceof RelationTypeIndex) {
                builder = graph.getBackend().buildEdgeScanJob();
            } else {
                TitanGraphIndex gindex = (TitanGraphIndex) index;
                if (gindex.isMixedIndex())
                    throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly.");
                builder = graph.getBackend().buildGraphIndexScanJob();
            }
            builder.setFinishJob(indexId.getIndexJobFinisher());
            builder.setJobId(indexId);
            builder.setJob(new IndexRemoveJob(graph, indexId.indexName, indexId.relationTypeName));
            try {
                future = builder.execute();
            } catch (BackendException e) {
                throw new TitanException(e);
            }
            break;
        default:
            throw new UnsupportedOperationException("Update action not supported: " + updateAction);
    }
    return future;
}
Also used : Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) TitanSchemaVertex(com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) IndexRepairJob(com.thinkaurelius.titan.graphdb.olap.job.IndexRepairJob) ParameterIndexField(com.thinkaurelius.titan.graphdb.types.ParameterIndexField) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) StandardScanner(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.StandardScanner) TitanException(com.thinkaurelius.titan.core.TitanException) PropertyKeyVertex(com.thinkaurelius.titan.graphdb.types.vertices.PropertyKeyVertex) IndexType(com.thinkaurelius.titan.graphdb.types.IndexType) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) IndexRemoveJob(com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob)

Example 73 with PropertyKey

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

the class ModificationDeserializer method parseRelation.

public static InternalRelation parseRelation(TransactionLogHeader.Modification modification, StandardTitanTx tx) {
    Change state = modification.state;
    assert state.isProper();
    long outVertexId = modification.outVertexId;
    Entry relEntry = modification.relationEntry;
    InternalVertex outVertex = tx.getInternalVertex(outVertexId);
    //Special relation parsing, compare to {@link RelationConstructor}
    RelationCache relCache = tx.getEdgeSerializer().readRelation(relEntry, false, tx);
    assert relCache.direction == Direction.OUT;
    InternalRelationType type = (InternalRelationType) tx.getExistingRelationType(relCache.typeId);
    assert type.getBaseType() == null;
    InternalRelation rel;
    if (type.isPropertyKey()) {
        if (state == Change.REMOVED) {
            rel = new StandardVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), ElementLifeCycle.Removed);
        } else {
            rel = new CacheVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), relEntry);
        }
    } else {
        assert type.isEdgeLabel();
        InternalVertex otherVertex = tx.getInternalVertex(relCache.getOtherVertexId());
        if (state == Change.REMOVED) {
            rel = new StandardEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, ElementLifeCycle.Removed);
        } else {
            rel = new CacheEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, relEntry);
        }
    }
    if (state == Change.REMOVED && relCache.hasProperties()) {
        //copy over properties
        for (LongObjectCursor<Object> entry : relCache) {
            rel.setPropertyDirect(tx.getExistingPropertyKey(entry.key), entry.value);
        }
    }
    return rel;
}
Also used : EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) Change(com.thinkaurelius.titan.core.log.Change) InternalRelation(com.thinkaurelius.titan.graphdb.internal.InternalRelation) Entry(com.thinkaurelius.titan.diskstorage.Entry) InternalVertex(com.thinkaurelius.titan.graphdb.internal.InternalVertex) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 74 with PropertyKey

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

the class Titan0GraphManagement method createExactMatchIndex.

@Override
public void createExactMatchIndex(String propertyName, boolean enforceUniqueness, List<AtlasPropertyKey> propertyKeys) {
    TitanManagement.IndexBuilder indexBuilder = management.buildIndex(propertyName, Vertex.class);
    for (AtlasPropertyKey key : propertyKeys) {
        PropertyKey titanKey = TitanObjectFactory.createPropertyKey(key);
        indexBuilder.addKey(titanKey);
    }
    if (enforceUniqueness) {
        indexBuilder.unique();
    }
    indexBuilder.buildCompositeIndex();
}
Also used : AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 75 with PropertyKey

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

the class Titan0GraphManagement method createFullTextIndex.

@Override
public void createFullTextIndex(String indexName, AtlasPropertyKey propertyKey, String backingIndex) {
    PropertyKey fullText = TitanObjectFactory.createPropertyKey(propertyKey);
    management.buildIndex(indexName, Vertex.class).addKey(fullText, com.thinkaurelius.titan.core.schema.Parameter.of("mapping", Mapping.TEXT)).buildMixedIndex(backingIndex);
}
Also used : AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) 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