Search in sources :

Example 61 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class GraphDbStructureGuide method showIndices.

private void showIndices(DbStructureVisitor visitor, ReadOperations read, TokenNameLookup nameLookup) throws IndexNotFoundKernelException {
    for (NewIndexDescriptor descriptor : loop(read.indexesGetAll())) {
        String userDescription = descriptor.schema().userDescription(nameLookup);
        double uniqueValuesPercentage = read.indexUniqueValuesSelectivity(descriptor);
        long size = read.indexSize(descriptor);
        visitor.visitIndex(descriptor, userDescription, uniqueValuesPercentage, size);
    }
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Example 62 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class IndexingAcceptanceTest method shouldConsiderNodesChangedInSameTxInIndexPrefixSearch.

@Test
public void shouldConsiderNodesChangedInSameTxInIndexPrefixSearch() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
    // GIVEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
    createNodes(db, LABEL1, "name", "Mattias");
    PrimitiveLongSet toChangeToMatch = createNodes(db, LABEL1, "name", "Mats");
    PrimitiveLongSet toChangeToNotMatch = createNodes(db, LABEL1, "name", "Karlsson");
    PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl");
    String prefix = "Karl";
    // WHEN
    PrimitiveLongSet found = Primitive.longSet();
    try (Transaction tx = db.beginTx()) {
        PrimitiveLongIterator toMatching = toChangeToMatch.iterator();
        while (toMatching.hasNext()) {
            long id = toMatching.next();
            db.getNodeById(id).setProperty("name", prefix + "X" + id);
            expected.add(id);
        }
        PrimitiveLongIterator toNotMatching = toChangeToNotMatch.iterator();
        while (toNotMatching.hasNext()) {
            long id = toNotMatching.next();
            db.getNodeById(id).setProperty("name", "X" + id);
            expected.remove(id);
        }
        Statement statement = getStatement((GraphDatabaseAPI) db);
        ReadOperations readOperations = statement.readOperations();
        NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
        int propertyKeyId = descriptor.schema().getPropertyId();
        found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, prefix)));
    }
    // THEN
    assertThat(found, equalTo(expected));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 63 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class IndexingAcceptanceTest method shouldIncludeNodesCreatedInSameTxInIndexSeekByPrefix.

@Test
public void shouldIncludeNodesCreatedInSameTxInIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
    // GIVEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
    createNodes(db, LABEL1, "name", "Mattias", "Mats");
    PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Carl", "Carlsson");
    // WHEN
    PrimitiveLongSet found = Primitive.longSet();
    try (Transaction tx = db.beginTx()) {
        expected.add(createNode(db, map("name", "Carlchen"), LABEL1).getId());
        createNode(db, map("name", "Karla"), LABEL1);
        Statement statement = getStatement((GraphDatabaseAPI) db);
        ReadOperations readOperations = statement.readOperations();
        NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
        int propertyKeyId = descriptor.schema().getPropertyId();
        found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, "Carl")));
    }
    // THEN
    assertThat(found, equalTo(expected));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 64 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class GraphDbStructureGuideTest method visitsUniqueConstraintsAndIndices.

@Test
public void visitsUniqueConstraintsAndIndices() throws Exception {
    DbStructureVisitor visitor = mock(DbStructureVisitor.class);
    int labelId = createLabel("Person");
    int pkId = createPropertyKey("name");
    commitAndReOpen();
    UniquenessConstraint constraint = createUniqueConstraint(labelId, pkId);
    NewIndexDescriptor descriptor = NewIndexDescriptorFactory.uniqueForLabel(labelId, pkId);
    // WHEN
    accept(visitor);
    // THEN
    verify(visitor).visitUniqueIndex(descriptor, ":Person(name)", 1.0d, 0L);
    verify(visitor).visitUniqueConstraint(constraint, "CONSTRAINT ON ( person:Person ) ASSERT person.name IS " + "UNIQUE");
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) Test(org.junit.Test)

Example 65 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class LuceneSchemaIndexCorruptionTest method shouldRequestIndexPopulationWhenFailingWithEOFException.

@Test
public void shouldRequestIndexPopulationWhenFailingWithEOFException() throws Exception {
    // Given
    long faultyIndexId = 1;
    EOFException error = new EOFException("/some/path/somewhere");
    LuceneSchemaIndexProvider provider = newFaultySchemaIndexProvider(faultyIndexId, error);
    // When
    NewIndexDescriptor descriptor = NewIndexDescriptorFactory.forLabel(1, 1);
    InternalIndexState initialState = provider.getInitialState(faultyIndexId, descriptor);
    // Then
    assertThat(initialState, equalTo(InternalIndexState.POPULATING));
    logProvider.assertAtLeastOnce(loggedException(error));
}
Also used : InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) EOFException(java.io.EOFException) Test(org.junit.Test)

Aggregations

NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)99 Test (org.junit.Test)55 Statement (org.neo4j.kernel.api.Statement)24 ReadOperations (org.neo4j.kernel.api.ReadOperations)17 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)9 InternalIndexState (org.neo4j.kernel.api.index.InternalIndexState)7 Transaction (org.neo4j.graphdb.Transaction)6 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)5 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)5 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)5 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 KernelException (org.neo4j.kernel.api.exceptions.KernelException)4 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)4