Search in sources :

Example 51 with SchemaRead

use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.

the class AwaitIndexProcedureTest method setup.

@BeforeEach
void setup() throws LabelNotFoundKernelException, PropertyKeyIdNotFoundKernelException {
    final int labelId = 0;
    final int propId = 0;
    LabelSchemaDescriptor anyDescriptor = SchemaDescriptor.forLabel(labelId, propId);
    anyIndex = forSchema(anyDescriptor).withName("index").materialise(13);
    KernelTransaction transaction = mock(KernelTransaction.class);
    schemaRead = mock(SchemaRead.class);
    when(transaction.schemaRead()).thenReturn(schemaRead);
    TokenRead tokenRead = mock(TokenRead.class);
    when(tokenRead.nodeLabelName(labelId)).thenReturn("label_0");
    when(tokenRead.propertyKeyName(propId)).thenReturn("prop_0");
    when(tokenRead.labelGetName(labelId)).thenReturn("label_0");
    when(tokenRead.propertyKeyGetName(propId)).thenReturn("prop_0");
    when(transaction.tokenRead()).thenReturn(tokenRead);
    procedure = new IndexProcedures(transaction, null);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 52 with SchemaRead

use of org.neo4j.internal.kernel.api.SchemaRead 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

SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)36 Test (org.junit.jupiter.api.Test)28 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)26 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)22 TokenRead (org.neo4j.internal.kernel.api.TokenRead)12 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)9 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)8 ArrayList (java.util.ArrayList)7 Read (org.neo4j.internal.kernel.api.Read)5 HashMap (java.util.HashMap)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Arrays (java.util.Arrays)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 EntityType (org.neo4j.common.EntityType)3 KernelException (org.neo4j.exceptions.KernelException)3 Transaction (org.neo4j.graphdb.Transaction)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3