Search in sources :

Example 1 with IndexCapability

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

the class IndexConfigurationCompletionCompatibility method mustNotOverwriteExistingCapabilities.

@Test
public void mustNotOverwriteExistingCapabilities() {
    IndexCapability capability = new IndexCapability() {

        @Override
        public IndexOrderCapability orderCapability(ValueCategory... valueCategories) {
            return IndexOrderCapability.NONE;
        }

        @Override
        public IndexValueCapability valueCapability(ValueCategory... valueCategories) {
            return IndexValueCapability.NO;
        }
    };
    IndexDescriptor index = descriptor.withIndexCapability(capability);
    IndexDescriptor completed = indexProvider.completeConfiguration(index);
    assertSame(capability, completed.getCapability());
}
Also used : ValueCategory(org.neo4j.values.storable.ValueCategory) IndexCapability(org.neo4j.internal.schema.IndexCapability) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.Test)

Example 2 with IndexCapability

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

the class SchemaCacheTest method shouldCompleteConfigurationOfIndexesAddedToCache.

@Test
void shouldCompleteConfigurationOfIndexesAddedToCache() {
    IndexCapability capability = new IndexCapability() {

        @Override
        public IndexOrderCapability orderCapability(ValueCategory... valueCategories) {
            return IndexOrderCapability.NONE;
        }

        @Override
        public IndexValueCapability valueCapability(ValueCategory... valueCategories) {
            return IndexValueCapability.NO;
        }
    };
    List<IndexDescriptor> completed = new ArrayList<>();
    IndexConfigCompleter completer = index -> {
        completed.add(index);
        return index.withIndexCapability(capability);
    };
    SchemaCache cache = new SchemaCache(new ConstraintSemantics(), completer);
    IndexDescriptor index1 = newIndexRule(1, 2, 3);
    ConstraintDescriptor constraint1 = uniquenessConstraint(2, 2, 3, 1);
    IndexDescriptor index2 = newIndexRule(3, 4, 5);
    ConstraintDescriptor constraint2 = uniquenessConstraint(4, 4, 5, 3);
    IndexDescriptor index3 = newIndexRule(5, 5, 5);
    cache.load(asList(index1, constraint1));
    cache.addSchemaRule(index2);
    cache.addSchemaRule(constraint2);
    cache.addSchemaRule(index3);
    assertEquals(List.of(index1, index2, index3), completed);
    assertEquals(capability, cache.getIndex(index1.getId()).getCapability());
    assertEquals(capability, cache.getIndex(index2.getId()).getCapability());
    assertEquals(capability, cache.getIndex(index3.getId()).getCapability());
}
Also used : IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) IndexCapability(org.neo4j.internal.schema.IndexCapability) MutableInt(org.apache.commons.lang3.mutable.MutableInt) SchemaRule(org.neo4j.internal.schema.SchemaRule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ConstraintDescriptorFactory.uniqueForLabel(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory.uniqueForLabel) ConstraintDescriptorFactory(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory) ArrayList(java.util.ArrayList) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) Iterables(org.neo4j.internal.helpers.collection.Iterables) Arrays.asList(java.util.Arrays.asList) SchemaDescriptor.forRelType(org.neo4j.internal.schema.SchemaDescriptor.forRelType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SchemaDescriptor.fulltext(org.neo4j.internal.schema.SchemaDescriptor.fulltext) Iterator(java.util.Iterator) Iterators(org.neo4j.internal.helpers.collection.Iterators) ConstraintType(org.neo4j.internal.schema.ConstraintType) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) Set(java.util.Set) ValueCategory(org.neo4j.values.storable.ValueCategory) Iterators.single(org.neo4j.internal.helpers.collection.Iterators.single) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) Test(org.junit.jupiter.api.Test) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) List(java.util.List) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) Iterators.asSet(org.neo4j.internal.helpers.collection.Iterators.asSet) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Collections(java.util.Collections) NODE(org.neo4j.common.EntityType.NODE) Race(org.neo4j.test.Race) ValueCategory(org.neo4j.values.storable.ValueCategory) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexCapability(org.neo4j.internal.schema.IndexCapability) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with IndexCapability

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

the class FusionIndexProvider method completeConfiguration.

@Override
public IndexDescriptor completeConfiguration(IndexDescriptor index) {
    EnumMap<IndexSlot, IndexDescriptor> descriptors = new EnumMap<>(IndexSlot.class);
    EnumMap<IndexSlot, IndexCapability> capabilities = new EnumMap<>(IndexSlot.class);
    for (IndexSlot slot : IndexSlot.values()) {
        IndexDescriptor result = providers.select(slot).completeConfiguration(index);
        descriptors.put(slot, result);
        capabilities.put(slot, result.getCapability());
    }
    IndexConfig config = index.getIndexConfig();
    for (IndexDescriptor result : descriptors.values()) {
        IndexConfig resultConfig = result.getIndexConfig();
        for (Pair<String, Value> entry : resultConfig.entries()) {
            config = config.withIfAbsent(entry.getOne(), entry.getTwo());
        }
    }
    index = index.withIndexConfig(config);
    if (index.getCapability().equals(IndexCapability.NO_CAPABILITY)) {
        index = index.withIndexCapability(new FusionIndexCapability(slotSelector, new InstanceSelector<>(capabilities)));
    }
    return index;
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexCapability(org.neo4j.internal.schema.IndexCapability) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) EnumMap(java.util.EnumMap)

Example 4 with IndexCapability

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

the class IndexSizesTest method createIndexes.

private void createIndexes(int numSmall, int numLarge) {
    IndexCapability capabilityWithValue = mock(IndexCapability.class);
    when(capabilityWithValue.valueCapability(any())).thenReturn(IndexValueCapability.YES);
    IndexPrototype prototype = prototype();
    for (int i = 0; i < numLarge; i++) {
        // using id as "size"
        indexes.add(prototype.materialise(highNodeId / 2 + i).withIndexCapability(capabilityWithValue));
    }
    for (int i = 0; i < numSmall; i++) {
        // using id as "size"
        indexes.add(prototype.materialise(i).withIndexCapability(capabilityWithValue));
    }
    try {
        sizes.initialize();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IndexCapability(org.neo4j.internal.schema.IndexCapability) IndexPrototype(org.neo4j.internal.schema.IndexPrototype)

Example 5 with IndexCapability

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

the class IndexSizes method hasValues.

static boolean hasValues(IndexDescriptor index) {
    IndexCapability capabilities = index.getCapability();
    ValueCategory[] categories = new ValueCategory[index.schema().getPropertyIds().length];
    Arrays.fill(categories, ValueCategory.UNKNOWN);
    return capabilities.valueCapability(categories) == IndexValueCapability.YES && !index.schema().isFulltextSchemaDescriptor();
}
Also used : ValueCategory(org.neo4j.values.storable.ValueCategory) IndexCapability(org.neo4j.internal.schema.IndexCapability)

Aggregations

IndexCapability (org.neo4j.internal.schema.IndexCapability)7 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 ValueCategory (org.neo4j.values.storable.ValueCategory)4 Test (org.junit.jupiter.api.Test)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Set (java.util.Set)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)2 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.singleton (java.util.Collections.singleton)1