Search in sources :

Example 6 with IndexValueCapability

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

the class EntityValueIndexCursorTestBase method shouldNotFindDeletedEntityInIndexScan.

@Test
void shouldNotFindDeletedEntityInIndexScan() throws Exception {
    // Given
    boolean needsValues = indexParams.indexProvidesAllValues();
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability wildcardCapability = index.reference().getCapability().valueCapability(ValueCategory.UNKNOWN);
    try (KernelTransaction tx = beginTransaction();
        var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexScan(tx, index, cursor, unordered(needsValues));
        assertThat(cursor.numberOfProperties()).isEqualTo(1);
        assertFoundEntitiesAndValue(cursor, TOTAL_ENTITY_COUNT, uniqueIds, wildcardCapability, needsValues);
        // then
        entityParams.entityDelete(tx, strOne);
        entityParams.entityIndexScan(tx, index, cursor, unordered(needsValues));
        assertFoundEntitiesAndValue(cursor, TOTAL_ENTITY_COUNT - 1, uniqueIds, wildcardCapability, needsValues);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 7 with IndexValueCapability

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

the class EntityValueIndexCursorTestBase method shouldPerformIndexScan.

@Test
void shouldPerformIndexScan() throws Exception {
    // given
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability wildcardCapability = index.reference().getCapability().valueCapability(ValueCategory.UNKNOWN);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexScan(tx, index, cursor, unordered(indexParams.indexProvidesAllValues()));
        // then
        assertThat(cursor.numberOfProperties()).isEqualTo(1);
        assertFoundEntitiesAndValue(cursor, TOTAL_ENTITY_COUNT, uniqueIds, wildcardCapability, indexParams.indexProvidesAllValues());
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 8 with IndexValueCapability

use of org.neo4j.internal.schema.IndexValueCapability 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 9 with IndexValueCapability

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

the class EntityValueIndexCursorTestBase method shouldPerformBooleanSearch.

@Test
void shouldPerformBooleanSearch() throws KernelException {
    // given
    boolean needsValues = indexParams.indexProvidesBooleanValues();
    IndexQueryConstraints constraints = unordered(needsValues);
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability capability = index.reference().getCapability().valueCapability(ValueGroup.BOOLEAN.category());
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.exact(prop, false));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, capability, needsValues);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.exact(prop, true));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, capability, needsValues);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 10 with IndexValueCapability

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

the class EntityValueIndexCursorTestBase method shouldPerformTextArraySearch.

@Test
void shouldPerformTextArraySearch() throws KernelException {
    // given
    boolean needsValues = indexParams.indexProvidesArrayValues();
    IndexQueryConstraints constraints = unordered(needsValues);
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability capability = index.reference().getCapability().valueCapability(ValueGroup.TEXT_ARRAY.category());
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.exact(prop, new String[] { "first", "second", "third" }));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, capability, needsValues);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.exact(prop, new String[] { "fourth", "fifth", "sixth", "seventh" }));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, capability, needsValues);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)14 IndexValueCapability (org.neo4j.internal.schema.IndexValueCapability)14 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)12 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)12 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)12 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)7 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 IndexCapability (org.neo4j.internal.schema.IndexCapability)2 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1