Search in sources :

Example 1 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class FulltextIndexProviderTest method shouldAnswerStartsWithIfCypherCompatible.

@Test
void shouldAnswerStartsWithIfCypherCompatible() throws KernelException {
    IndexDescriptor indexReference;
    Label containsLabel = label("containsLabel");
    String containsProp = "containsProp";
    long nodea;
    long nodeapa1;
    long nodeapa2;
    long nodeapaapa;
    long nodeapalong;
    try (Transaction tx = db.beginTx()) {
        nodea = createNode(tx, containsLabel, containsProp, "a");
        createNode(tx, containsLabel, containsProp, "A");
        nodeapa1 = createNode(tx, containsLabel, containsProp, "apa");
        nodeapa2 = createNode(tx, containsLabel, containsProp, "apa");
        createNode(tx, containsLabel, containsProp, "longapa");
        nodeapaapa = createNode(tx, containsLabel, containsProp, "apa apa");
        nodeapalong = createNode(tx, containsLabel, containsProp, "apalong");
        tx.commit();
    }
    int containsLabelId;
    int containsPropertyId;
    try (Transaction tx = db.beginTx()) {
        TokenRead tokenRead = tokenRead(tx);
        containsLabelId = tokenRead.nodeLabel(containsLabel.name());
        containsPropertyId = tokenRead.propertyKey(containsProp);
    }
    indexReference = createIndex(new int[] { containsLabelId }, new int[] { containsPropertyId }, "cypher");
    await(indexReference);
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapaapa, nodeapalong);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa a"), nodeapaapa);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "*apa"));
    }
    controller.restartDbms();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapaapa, nodeapalong);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "apa a"), nodeapaapa);
        assertQueryResult(ktx, startsWithQuery(containsPropertyId, "*apa"));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Label(org.neo4j.graphdb.Label) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 2 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class FulltextIndexProviderTest method shouldAnswerContainsIfCypherCompatible.

@Test
void shouldAnswerContainsIfCypherCompatible() throws KernelException {
    IndexDescriptor indexReference;
    Label containsLabel = label("containsLabel");
    String containsProp = "containsProp";
    long nodea;
    long nodeapa1;
    long nodeapa2;
    long nodeapalong;
    long nodeapaapa;
    try (Transaction tx = db.beginTx()) {
        nodea = createNode(tx, containsLabel, containsProp, "a");
        createNode(tx, containsLabel, containsProp, "A");
        nodeapa1 = createNode(tx, containsLabel, containsProp, "apa");
        nodeapa2 = createNode(tx, containsLabel, containsProp, "apa");
        nodeapalong = createNode(tx, containsLabel, containsProp, "apalong");
        nodeapaapa = createNode(tx, containsLabel, containsProp, "apa apa");
        tx.commit();
    }
    int containsLabelId;
    int containsPropertyId;
    try (Transaction tx = db.beginTx()) {
        TokenRead tokenRead = tokenRead(tx);
        containsLabelId = tokenRead.nodeLabel(containsLabel.name());
        containsPropertyId = tokenRead.propertyKey(containsProp);
    }
    indexReference = createIndex(new int[] { containsLabelId }, new int[] { containsPropertyId }, "cypher");
    await(indexReference);
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        assertQueryResult(ktx, containsQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
        assertQueryResult(ktx, containsQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
        assertQueryResult(ktx, containsQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, containsQuery(containsPropertyId, "pa ap"), nodeapaapa);
    }
    controller.restartDbms();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        assertQueryResult(ktx, containsQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
        assertQueryResult(ktx, containsQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodeapalong, nodeapaapa);
        assertQueryResult(ktx, containsQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, containsQuery(containsPropertyId, "pa ap"), nodeapaapa);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Label(org.neo4j.graphdb.Label) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 3 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method verifyExpectedProvider.

private static void verifyExpectedProvider(GraphDatabaseAPI db, Label label, IndexProviderDescriptor expectedDescriptor) throws TransactionFailureException {
    try (InternalTransaction tx = (InternalTransaction) db.beginTx();
        KernelTransaction kernelTransaction = tx.kernelTransaction()) {
        TokenRead tokenRead = kernelTransaction.tokenRead();
        SchemaRead schemaRead = kernelTransaction.schemaRead();
        int labelId = tokenRead.nodeLabel(label.name());
        int key1Id = tokenRead.propertyKey(KEY1);
        int key2Id = tokenRead.propertyKey(KEY2);
        IndexDescriptor index = single(schemaRead.index(SchemaDescriptor.forLabel(labelId, key1Id)));
        assertIndexHasExpectedProvider(expectedDescriptor, index);
        index = single(schemaRead.index(SchemaDescriptor.forLabel(labelId, key1Id, key2Id)));
        assertIndexHasExpectedProvider(expectedDescriptor, index);
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 4 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludeIndexBackedConstraintsWithFailedIndexIndex.

@Test
void schemaStatementsMustNotIncludeIndexBackedConstraintsWithFailedIndexIndex() throws IndexNotFoundKernelException, ProcedureException {
    IndexDescriptor index = someOrphanedIndex();
    ConstraintDescriptor constraint = indexBackedConstraint(index);
    index = indexBoundToConstraint(index, constraint);
    InternalIndexState internalIndexState = InternalIndexState.FAILED;
    SchemaReadCore schemaReadCore = getSchemaReadCore(constraint, index, internalIndexState);
    TokenRead tokenRead = mock(TokenRead.class);
    Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
    assertEquals(0, result.size());
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 5 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.

the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludeOrphanedIndexes.

@Test
void schemaStatementsMustNotIncludeOrphanedIndexes() throws IndexNotFoundKernelException, ProcedureException {
    IndexDescriptor index = someOrphanedIndex();
    InternalIndexState indexState = InternalIndexState.ONLINE;
    SchemaReadCore schemaReadCore = getSchemaReadCore(index, indexState);
    TokenRead tokenRead = mock(TokenRead.class);
    Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
    assertEquals(0, result.size());
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Aggregations

TokenRead (org.neo4j.internal.kernel.api.TokenRead)59 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)42 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)27 Test (org.junit.jupiter.api.Test)19 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)18 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 Transaction (org.neo4j.graphdb.Transaction)13 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)13 Label (org.neo4j.graphdb.Label)12 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)11 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)11 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)10 RelationshipType (org.neo4j.graphdb.RelationshipType)7 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)6 Arrays (java.util.Arrays)5 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Stream (java.util.stream.Stream)5