Search in sources :

Example 41 with SchemaDescriptor

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

the class SchemaRuleSerialization35 method readIndexRule.

// PRIVATE
// READ INDEX
private static IndexDescriptor readIndexRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
    String providerKey = getDecodedStringFrom(source);
    String providerVersion = getDecodedStringFrom(source);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(providerKey, providerVersion);
    byte indexRuleType = source.get();
    Optional<String> name;
    switch(indexRuleType) {
        case GENERAL_INDEX:
            {
                SchemaDescriptor schema = readSchema(source);
                name = readRuleName(source);
                IndexPrototype prototype = IndexPrototype.forSchema(schema, providerDescriptor);
                if (schema.isFulltextSchemaDescriptor()) {
                    prototype = prototype.withIndexType(IndexType.FULLTEXT);
                }
                if (name.isPresent()) {
                    prototype = prototype.withName(name.get());
                } else {
                    prototype = prototype.withName(defaultIndexName(id));
                }
                return prototype.materialise(id);
            }
        case UNIQUE_INDEX:
            {
                long readOwningConstraint = source.getLong();
                SchemaDescriptor schema = readSchema(source);
                name = readRuleName(source);
                IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema, providerDescriptor);
                if (name.isPresent()) {
                    prototype = prototype.withName(name.get());
                } else {
                    prototype = prototype.withName(defaultIndexName(id));
                }
                IndexDescriptor index = prototype.materialise(id);
                if (readOwningConstraint != NO_OWNING_CONSTRAINT_YET) {
                    index = index.withOwningConstraintId(readOwningConstraint);
                }
                return index;
            }
        default:
            throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType));
    }
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 42 with SchemaDescriptor

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

the class DefaultPooledCursorsTestBase method shouldReuseRelationshipIndexCursors.

@Test
void shouldReuseRelationshipIndexCursors() throws Exception {
    // given
    int connection;
    int name;
    String indexName = "myIndex";
    IndexDescriptor index;
    try (KernelTransaction tx = beginTransaction()) {
        connection = tx.tokenWrite().relationshipTypeGetOrCreateForName("Connection");
        name = tx.tokenWrite().propertyKeyGetOrCreateForName("name");
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, array(connection), array(name));
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withName(indexName).withIndexType(IndexType.FULLTEXT);
        index = tx.schemaWrite().indexCreate(prototype);
        tx.commit();
    }
    Predicates.awaitEx(() -> tx.schemaRead().indexGetState(index) == ONLINE, 1, MINUTES);
    RelationshipValueIndexCursor c1 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
    IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
    read.relationshipIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.fulltextSearch("hello"));
    c1.close();
    RelationshipValueIndexCursor c2 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 43 with SchemaDescriptor

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

the class SimpleRandomizedIndexAccessorCompatibility method generateUpdatesFromValues.

private List<ValueIndexEntryUpdate<?>> generateUpdatesFromValues(List<Value> values, MutableLong nextId) {
    List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
    for (Value value : values) {
        ValueIndexEntryUpdate<SchemaDescriptor> update = add(nextId.getAndIncrement(), descriptor.schema(), value);
        updates.add(update);
    }
    return updates;
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) Value(org.neo4j.values.storable.Value)

Example 44 with SchemaDescriptor

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

the class CompositeIndexAccessorCompatibility method testExactMatchOnRandomCompositeValues.

@Test
public void testExactMatchOnRandomCompositeValues() throws Exception {
    // given
    ValueType[] types = randomSetOfSupportedTypes();
    List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
    Set<ValueTuple> duplicateChecker = new HashSet<>();
    for (long id = 0; id < 10_000; id++) {
        ValueIndexEntryUpdate<SchemaDescriptor> update;
        do {
            update = add(id, descriptor.schema(), random.randomValues().nextValueOfTypes(types), random.randomValues().nextValueOfTypes(types));
        } while (!duplicateChecker.add(ValueTuple.of(update.values())));
        updates.add(update);
    }
    updateAndCommit(updates);
    // when
    InMemoryTokens tokenNameLookup = new InMemoryTokens();
    for (ValueIndexEntryUpdate<?> update : updates) {
        // then
        List<Long> hits = query(exact(0, update.values()[0]), exact(1, update.values()[1]));
        assertEquals(update.describe(tokenNameLookup) + " " + hits, 1, hits.size());
        assertThat(single(hits)).isEqualTo(update.getEntityId());
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) InMemoryTokens(org.neo4j.test.InMemoryTokens) ValueType(org.neo4j.values.storable.ValueType) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) ValueTuple(org.neo4j.values.storable.ValueTuple) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 45 with SchemaDescriptor

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

the class SchemaImpl method asConstraintDefinition.

private ConstraintDefinition asConstraintDefinition(ConstraintDescriptor constraint, TokenRead tokenRead) {
    // internal storage engine API.
    if (constraint.isNodePropertyExistenceConstraint() || constraint.isNodeKeyConstraint() || constraint.isUniquenessConstraint()) {
        SchemaDescriptor schemaDescriptor = constraint.schema();
        int[] entityTokenIds = schemaDescriptor.getEntityTokenIds();
        Label[] labels = new Label[entityTokenIds.length];
        for (int i = 0; i < entityTokenIds.length; i++) {
            labels[i] = label(tokenRead.labelGetName(entityTokenIds[i]));
        }
        String[] propertyKeys = Arrays.stream(schemaDescriptor.getPropertyIds()).mapToObj(tokenRead::propertyKeyGetName).toArray(String[]::new);
        if (constraint.isNodePropertyExistenceConstraint()) {
            return new NodePropertyExistenceConstraintDefinition(actions, constraint, labels[0], propertyKeys);
        } else if (constraint.isUniquenessConstraint()) {
            return new UniquenessConstraintDefinition(actions, constraint, new IndexDefinitionImpl(actions, null, labels, propertyKeys, true));
        } else {
            return new NodeKeyConstraintDefinition(actions, constraint, new IndexDefinitionImpl(actions, null, labels, propertyKeys, true));
        }
    } else if (constraint.isRelationshipPropertyExistenceConstraint()) {
        RelationTypeSchemaDescriptor descriptor = constraint.schema().asRelationshipTypeSchemaDescriptor();
        return new RelationshipPropertyExistenceConstraintDefinition(actions, constraint, withName(tokenRead.relationshipTypeGetName(descriptor.getRelTypeId())), tokenRead.propertyKeyGetName(descriptor.getPropertyId()));
    }
    throw new IllegalArgumentException("Unknown constraint " + constraint);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) Label(org.neo4j.graphdb.Label) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor)

Aggregations

SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)58 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)27 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)23 Test (org.junit.jupiter.api.Test)18 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)18 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)18 Value (org.neo4j.values.storable.Value)11 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 ArrayList (java.util.ArrayList)6 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)6 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)5 IndexConfig (org.neo4j.internal.schema.IndexConfig)5 MemoryTracker (org.neo4j.memory.MemoryTracker)5 KernelException (org.neo4j.exceptions.KernelException)4 UnspecifiedKernelException (org.neo4j.exceptions.UnspecifiedKernelException)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 IndexNotApplicableKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)4 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)4