Search in sources :

Example 1 with SchemaDescriptorSupplier

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

the class DropConstraintFailureException method getUserMessage.

@Override
public String getUserMessage(TokenNameLookup tokenNameLookup) {
    String message;
    if (constraint instanceof SchemaDescriptorSupplier) {
        SchemaDescriptorSupplier schemaish = (SchemaDescriptorSupplier) constraint;
        message = "Unable to drop constraint on " + schemaish.userDescription(tokenNameLookup) + ": ";
    } else if (constraint instanceof String) {
        String name = (String) constraint;
        message = "Unable to drop constraint `" + name + "`: ";
    } else {
        return getMessage();
    }
    Throwable cause = getCause();
    if (cause instanceof KernelException) {
        KernelException exception = (KernelException) cause;
        message += exception.getUserMessage(tokenNameLookup);
    } else {
        message += cause.getMessage();
    }
    return message;
}
Also used : SchemaDescriptorSupplier(org.neo4j.internal.schema.SchemaDescriptorSupplier) KernelException(org.neo4j.exceptions.KernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)

Example 2 with SchemaDescriptorSupplier

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

the class DbStructureCollector method lookup.

public DbStructureLookup lookup() {
    return new DbStructureLookup() {

        @Override
        public Iterator<Pair<Integer, String>> labels() {
            return labels.iterator();
        }

        @Override
        public Iterator<Pair<Integer, String>> properties() {
            return propertyKeys.iterator();
        }

        @Override
        public Iterator<Pair<Integer, String>> relationshipTypes() {
            return relationshipTypes.iterator();
        }

        @Override
        public Iterator<Pair<String[], String[]>> knownIndices() {
            return regularIndices.iterator();
        }

        @Override
        public Iterator<Pair<String[], String[]>> knownUniqueIndices() {
            return uniqueIndices.iterator();
        }

        @Override
        public Iterator<Pair<String, String[]>> knownUniqueConstraints() {
            return idsToNames(uniquenessConstraints);
        }

        @Override
        public Iterator<Pair<String, String[]>> knownNodePropertyExistenceConstraints() {
            return idsToNames(nodePropertyExistenceConstraints);
        }

        @Override
        public Iterator<Pair<String, String[]>> knownNodeKeyConstraints() {
            return idsToNames(nodeKeyConstraints);
        }

        @Override
        public long nodesAllCardinality() {
            return allNodesCount;
        }

        @Override
        public Iterator<Pair<String, String[]>> knownRelationshipPropertyExistenceConstraints() {
            return Iterators.map(relConstraint -> {
                String label = labels.byIdOrFail(relConstraint.schema().getRelTypeId());
                String[] propertyKeyNames = propertyKeys.byIdOrFail(relConstraint.schema().getPropertyIds());
                return Pair.of(label, propertyKeyNames);
            }, relPropertyExistenceConstraints.iterator());
        }

        @Override
        public long nodesWithLabelCardinality(int labelId) {
            return nodeCounts.getIfAbsent(labelId, 0L);
        }

        @Override
        public long cardinalityByLabelsAndRelationshipType(int fromLabelId, int relTypeId, int toLabelId) {
            RelSpecifier specifier = new RelSpecifier(fromLabelId, relTypeId, toLabelId);
            Long result = relCounts.get(specifier);
            return result == null ? 0L : result;
        }

        @Override
        public double indexUniqueValueSelectivity(int labelId, int... propertyKeyIds) {
            SchemaDescriptor descriptor = SchemaDescriptor.forLabel(labelId, propertyKeyIds);
            IndexStatistics result1 = regularIndices.getIndex(descriptor);
            IndexStatistics result2 = result1 == null ? uniqueIndices.getIndex(descriptor) : result1;
            return result2 == null ? Double.NaN : result2.uniqueValuesPercentage;
        }

        @Override
        public double indexPropertyExistsSelectivity(int labelId, int... propertyKeyIds) {
            SchemaDescriptor descriptor = SchemaDescriptor.forLabel(labelId, propertyKeyIds);
            IndexStatistics result1 = regularIndices.getIndex(descriptor);
            IndexStatistics result2 = result1 == null ? uniqueIndices.getIndex(descriptor) : result1;
            double indexSize = result2 == null ? Double.NaN : result2.size;
            return indexSize / nodesWithLabelCardinality(labelId);
        }

        private Iterator<Pair<String, String[]>> idsToNames(Iterable<? extends SchemaDescriptorSupplier> nodeConstraints) {
            return Iterators.map(nodeConstraint -> {
                String label = labels.byIdOrFail(nodeConstraint.schema().getLabelId());
                String[] propertyKeyNames = propertyKeys.byIdOrFail(nodeConstraint.schema().getPropertyIds());
                return Pair.of(label, propertyKeyNames);
            }, nodeConstraints.iterator());
        }
    };
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) SchemaDescriptorSupplier(org.neo4j.internal.schema.SchemaDescriptorSupplier) Pair(org.neo4j.internal.helpers.collection.Pair)

Aggregations

SchemaDescriptorSupplier (org.neo4j.internal.schema.SchemaDescriptorSupplier)2 KernelException (org.neo4j.exceptions.KernelException)1 Pair (org.neo4j.internal.helpers.collection.Pair)1 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)1 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)1