Search in sources :

Example 1 with IndexType

use of org.neo4j.internal.schema.IndexType in project neo4j by neo4j.

the class SchemaStore method schemaIndexToMap.

private static void schemaIndexToMap(IndexDescriptor rule, Map<String, Value> map) {
    // Rule
    putStringProperty(map, PROP_SCHEMA_RULE_TYPE, "INDEX");
    IndexType indexType = rule.getIndexType();
    putStringProperty(map, PROP_INDEX_TYPE, indexType.name());
    if (rule.isUnique()) {
        putStringProperty(map, PROP_INDEX_RULE_TYPE, "UNIQUE");
        if (rule.getOwningConstraintId().isPresent()) {
            map.put(PROP_OWNING_CONSTRAINT, Values.longValue(rule.getOwningConstraintId().getAsLong()));
        }
    } else {
        putStringProperty(map, PROP_INDEX_RULE_TYPE, "NON_UNIQUE");
    }
    // Provider
    indexProviderToMap(rule, map);
    // Index config
    IndexConfig indexConfig = rule.getIndexConfig();
    indexConfigToMap(indexConfig, map);
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexType(org.neo4j.internal.schema.IndexType)

Example 2 with IndexType

use of org.neo4j.internal.schema.IndexType in project neo4j by neo4j.

the class SchemaRuleException method describe.

public static String describe(SchemaDescriptorSupplier schemaThing) {
    SchemaDescriptor schema = schemaThing.schema();
    String tagType;
    switch(schema.entityType()) {
        case NODE:
            tagType = "label";
            break;
        case RELATIONSHIP:
            tagType = "relationship type";
            break;
        default:
            throw new AssertionError("Unknown entity type: " + schema.entityType());
    }
    if (schemaThing instanceof ConstraintDescriptor) {
        ConstraintDescriptor constraint = (ConstraintDescriptor) schemaThing;
        switch(constraint.type()) {
            case UNIQUE:
                return tagType + " uniqueness constraint";
            case EXISTS:
                return tagType + " property existence constraint";
            case UNIQUE_EXISTS:
                return schema.entityType().name().toLowerCase() + " key constraint";
            default:
                throw new AssertionError("Unknown constraint type: " + constraint.type());
        }
    } else {
        IndexDescriptor index = (IndexDescriptor) schemaThing;
        IndexType indexType = index.getIndexType();
        if (indexType != IndexType.BTREE) {
            String indexTypeName = indexType.name().toLowerCase();
            return indexTypeName + " " + tagType + " index";
        } else {
            return tagType + " index";
        }
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexType(org.neo4j.internal.schema.IndexType)

Example 3 with IndexType

use of org.neo4j.internal.schema.IndexType in project neo4j by neo4j.

the class GraphCountsSection method indexes.

private static List<Map<String, Object>> indexes(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer) throws IndexNotFoundKernelException {
    List<Map<String, Object>> indexes = new ArrayList<>();
    Iterator<IndexDescriptor> iterator = schemaRead.indexesGetAll();
    while (iterator.hasNext()) {
        IndexDescriptor index = iterator.next();
        IndexType indexType = index.getIndexType();
        if (indexType == IndexType.FULLTEXT) {
            /* For full text indexes, we currently do not return its options, which makes returning information on
                 * this index not useful and if the index type is ignored, this would even be misleading.
                 */
            continue;
        }
        EntityType entityType = index.schema().entityType();
        Map<String, Object> data = new HashMap<>();
        switch(entityType) {
            case NODE:
                data.put("labels", map(index.schema().getEntityTokenIds(), id -> anonymizer.label(tokens.labelGetName(id), id)));
                break;
            case RELATIONSHIP:
                data.put("relationshipTypes", map(index.schema().getEntityTokenIds(), id -> anonymizer.relationshipType(tokens.relationshipTypeGetName(id), id)));
                break;
            default:
        }
        data.put("properties", map(index.schema().getPropertyIds(), id -> anonymizer.propertyKey(tokens.propertyKeyGetName(id), id)));
        var indexSample = schemaRead.indexSample(index);
        data.put("totalSize", indexSample.indexSize());
        data.put("updatesSinceEstimation", indexSample.updates());
        data.put("estimatedUniqueSize", indexSample.uniqueValues());
        data.put("indexType", indexType.name());
        indexes.add(data);
    }
    return indexes;
}
Also used : Arrays(java.util.Arrays) Iterator(java.util.Iterator) Read(org.neo4j.internal.kernel.api.Read) Iterators(org.neo4j.internal.helpers.collection.Iterators) IndexType(org.neo4j.internal.schema.IndexType) TokenRead(org.neo4j.internal.kernel.api.TokenRead) HashMap(java.util.HashMap) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) Kernel(org.neo4j.kernel.api.Kernel) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) Stream(java.util.stream.Stream) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) EntityType(org.neo4j.common.EntityType) Map(java.util.Map) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NamedToken(org.neo4j.token.api.NamedToken) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) IntFunction(java.util.function.IntFunction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) EntityType(org.neo4j.common.EntityType) IndexType(org.neo4j.internal.schema.IndexType) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IndexType (org.neo4j.internal.schema.IndexType)3 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)2 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 IntFunction (java.util.function.IntFunction)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 EntityType (org.neo4j.common.EntityType)1 Iterators (org.neo4j.internal.helpers.collection.Iterators)1 Read (org.neo4j.internal.kernel.api.Read)1 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)1 TokenRead (org.neo4j.internal.kernel.api.TokenRead)1 TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)1 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)1 LoginContext (org.neo4j.internal.kernel.api.security.LoginContext)1