Search in sources :

Example 16 with IndexPrototype

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

the class IndexPopulationJobTest method shouldPopulateRelationshipIndexWithASmallDataset.

@Test
void shouldPopulateRelationshipIndexWithASmallDataset() {
    // GIVEN
    String value = "Philip J.Fry";
    long node1 = createNode(map(name, value), FIRST);
    long node2 = createNode(map(name, value), SECOND);
    long node3 = createNode(map(age, 31), FIRST);
    long node4 = createNode(map(age, 35, name, value), FIRST);
    long rel1 = createRelationship(map(name, value), likes, node1, node3);
    createRelationship(map(name, value), knows, node3, node1);
    createRelationship(map(age, 31), likes, node2, node1);
    long rel4 = createRelationship(map(age, 35, name, value), likes, node4, node4);
    int rel = tokenHolders.relationshipTypeTokens().getIdByName(likes.name());
    int prop = tokenHolders.propertyKeyTokens().getIdByName(name);
    IndexPrototype descriptor = IndexPrototype.forSchema(SchemaDescriptor.forRelType(rel, prop));
    IndexPopulator actualPopulator = indexPopulator(descriptor);
    TrackingIndexPopulator populator = new TrackingIndexPopulator(actualPopulator);
    IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor);
    // WHEN
    job.run();
    // THEN
    IndexEntryUpdate<?> update1 = add(rel1, descriptor, Values.of(value));
    IndexEntryUpdate<?> update2 = add(rel4, descriptor, Values.of(value));
    assertTrue(populator.created);
    assertEquals(Arrays.asList(update1, update2), populator.includedSamples);
    assertEquals(1, populator.adds.size());
    assertTrue(populator.resultSampled);
    assertTrue(populator.closeCall);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Test(org.junit.jupiter.api.Test)

Example 17 with IndexPrototype

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

the class IndexPopulationJobTest method indexPrototype.

private IndexPrototype indexPrototype(Label label, String propertyKey, boolean constraint) throws KernelException {
    try (KernelTransaction tx = kernel.beginTransaction(IMPLICIT, LoginContext.AUTH_DISABLED)) {
        int labelId = tx.tokenWrite().labelGetOrCreateForName(label.name());
        int propertyKeyId = tx.tokenWrite().propertyKeyGetOrCreateForName(propertyKey);
        SchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyKeyId);
        IndexPrototype descriptor = constraint ? IndexPrototype.uniqueForSchema(schema, PROVIDER_DESCRIPTOR) : IndexPrototype.forSchema(schema, PROVIDER_DESCRIPTOR);
        tx.commit();
        return descriptor;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype)

Example 18 with IndexPrototype

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

the class StubStorageCursors method indexDescriptor.

private IndexDescriptor indexDescriptor(EntityType entityType, long id) {
    IndexPrototype indexPrototype = IndexPrototype.forSchema(forAnyEntityTokens(entityType)).withIndexType(LOOKUP).withIndexProvider(new IndexProviderDescriptor("token-lookup", "1.0"));
    indexPrototype = indexPrototype.withName(SchemaRule.generateName(indexPrototype, new String[] {}, new String[] {}));
    return indexPrototype.materialise(id);
}
Also used : IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor)

Example 19 with IndexPrototype

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

the class ConstraintIndexCreatorTest method createTransaction.

private KernelTransactionImplementation createTransaction() {
    KernelTransactionImplementation transaction = mock(KernelTransactionImplementation.class);
    try {
        StorageEngine storageEngine = mock(StorageEngine.class);
        StorageReader storageReader = mock(StorageReader.class);
        when(storageEngine.newReader()).thenReturn(storageReader);
        Locks.Client locks = mock(Locks.Client.class);
        when(transaction.lockClient()).thenReturn(locks);
        when(transaction.tokenRead()).thenReturn(tokenRead);
        when(transaction.schemaRead()).thenReturn(schemaRead);
        when(transaction.schemaWrite()).thenReturn(schemaWrite);
        TransactionState transactionState = mock(TransactionState.class);
        when(transaction.txState()).thenReturn(transactionState);
        when(transaction.indexUniqueCreate(any(IndexPrototype.class))).thenAnswer(i -> i.<IndexPrototype>getArgument(0).materialise(INDEX_ID));
        when(transaction.newStorageReader()).thenReturn(mock(StorageReader.class));
    } catch (InvalidTransactionTypeKernelException e) {
        fail("Expected write transaction");
    }
    return transaction;
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Locks(org.neo4j.kernel.impl.locking.Locks) StorageEngine(org.neo4j.storageengine.api.StorageEngine)

Example 20 with IndexPrototype

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

the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnFulltextSchemas.

@Test
void indexedBackedConstraintCreateMustThrowOnFulltextSchemas() throws Exception {
    // given
    when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 123));
    when(tokenHolders.propertyKeyTokens().getTokenById(anyInt())).thenReturn(new NamedToken("prop", 456));
    SchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, this.schema.getEntityTokenIds(), this.schema.getPropertyIds());
    IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName("constraint name").withIndexProvider(GenericNativeIndexProvider.DESCRIPTOR);
    IndexDescriptor constraintIndex = prototype.materialise(42);
    when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), eq(prototype))).thenReturn(constraintIndex);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexProxy.getDescriptor()).thenReturn(constraintIndex);
    when(indexingService.getIndexProxy(constraintIndex)).thenReturn(indexProxy);
    when(storageReader.constraintsGetForSchema(schema)).thenReturn(Collections.emptyIterator());
    when(storageReader.indexGetForSchema(schema)).thenReturn(Collections.emptyIterator());
    // when
    var e = assertThrows(KernelException.class, () -> operations.uniquePropertyConstraintCreate(prototype));
    assertThat(e.getUserMessage(tokenHolders)).contains("full-text schema");
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) NamedToken(org.neo4j.token.api.NamedToken) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

IndexPrototype (org.neo4j.internal.schema.IndexPrototype)45 Test (org.junit.jupiter.api.Test)25 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)24 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)16 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)8 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)7 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)7 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)7 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)5 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)3 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)3 NamedToken (org.neo4j.token.api.NamedToken)3 KernelException (org.neo4j.exceptions.KernelException)2 Transaction (org.neo4j.graphdb.Transaction)2 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)2 RelationshipValueIndexCursor (org.neo4j.internal.kernel.api.RelationshipValueIndexCursor)2 IndexConfig (org.neo4j.internal.schema.IndexConfig)2 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)2