Search in sources :

Example 46 with TokenRead

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

the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludePopulatingIndexes.

@Test
void schemaStatementsMustNotIncludePopulatingIndexes() throws ProcedureException, IndexNotFoundKernelException {
    IndexDescriptor index = someIndex();
    InternalIndexState indexState = InternalIndexState.POPULATING;
    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)

Example 47 with TokenRead

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

the class SchemaStatementProcedureTest method schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex.

@Test
void schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex() throws IndexNotFoundKernelException, ProcedureException {
    IndexDescriptor index = someOrphanedIndex();
    ConstraintDescriptor constraint = indexBackedConstraint(index);
    index = indexBoundToConstraint(index, constraint);
    InternalIndexState internalIndexState = InternalIndexState.ONLINE;
    SchemaReadCore schemaReadCore = getSchemaReadCore(constraint, index, internalIndexState);
    TokenRead tokenRead = mock(TokenRead.class);
    Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
    Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
    assertTrue(iter.hasNext());
    BuiltInProcedures.SchemaStatementResult next = iter.next();
    assertEquals(SchemaStatementProcedure.SchemaRuleType.CONSTRAINT.name(), next.type);
    assertEquals(CONSTRAINT_NAME, next.name);
    assertFalse(iter.hasNext());
}
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 48 with TokenRead

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

the class AwaitIndexProcedureTest method setup.

@BeforeEach
void setup() throws LabelNotFoundKernelException, PropertyKeyIdNotFoundKernelException {
    final int labelId = 0;
    final int propId = 0;
    LabelSchemaDescriptor anyDescriptor = SchemaDescriptor.forLabel(labelId, propId);
    anyIndex = forSchema(anyDescriptor).withName("index").materialise(13);
    KernelTransaction transaction = mock(KernelTransaction.class);
    schemaRead = mock(SchemaRead.class);
    when(transaction.schemaRead()).thenReturn(schemaRead);
    TokenRead tokenRead = mock(TokenRead.class);
    when(tokenRead.nodeLabelName(labelId)).thenReturn("label_0");
    when(tokenRead.propertyKeyName(propId)).thenReturn("prop_0");
    when(tokenRead.labelGetName(labelId)).thenReturn("label_0");
    when(tokenRead.propertyKeyGetName(propId)).thenReturn("prop_0");
    when(transaction.tokenRead()).thenReturn(tokenRead);
    procedure = new IndexProcedures(transaction, null);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 49 with TokenRead

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

the class FulltextIndexProviderTest method shouldAnswerExactIfCypherCompatible.

@Test
void shouldAnswerExactIfCypherCompatible() throws KernelException {
    IndexDescriptor indexReference;
    Label containsLabel = label("containsLabel");
    String containsProp = "containsProp";
    long nodea;
    long nodeapa1;
    long nodeapa2;
    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");
        createNode(tx, containsLabel, containsProp, "longapa");
        nodeapaapa = createNode(tx, containsLabel, containsProp, "apa apa");
        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, exactQuery(containsPropertyId, "a"), nodea);
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2);
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa a"));
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa apa"), nodeapaapa);
        assertQueryResult(ktx, exactQuery(containsPropertyId, "*apa"));
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa*"));
        IndexNotApplicableKernelException e = assertThrows(IndexNotApplicableKernelException.class, () -> assertQueryResult(ktx, exactQuery(containsPropertyId, 1)));
        assertThat(e.getMessage()).contains("A fulltext schema index cannot answer " + PropertyIndexQuery.IndexQueryType.exact + " queries on " + ValueCategory.NUMBER + " values.");
    }
    controller.restartDbms();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        assertQueryResult(ktx, exactQuery(containsPropertyId, "a"), nodea);
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2);
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa a"));
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa apa"), nodeapaapa);
        assertQueryResult(ktx, exactQuery(containsPropertyId, "*apa"));
        assertQueryResult(ktx, exactQuery(containsPropertyId, "apa*"));
        IndexNotApplicableKernelException e = assertThrows(IndexNotApplicableKernelException.class, () -> assertQueryResult(ktx, exactQuery(containsPropertyId, 1)));
        assertThat(e.getMessage()).contains("A fulltext schema index cannot answer " + PropertyIndexQuery.IndexQueryType.exact + " queries on " + ValueCategory.NUMBER + " values.");
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) 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 50 with TokenRead

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

the class FulltextIndexProviderTest method shouldAnswerEndsWithIfCypherCompatible.

@Test
void shouldAnswerEndsWithIfCypherCompatible() throws KernelException {
    IndexDescriptor indexReference;
    Label containsLabel = label("containsLabel");
    String containsProp = "containsProp";
    long nodea;
    long nodeapa1;
    long nodeapa2;
    long nodelongapa;
    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");
        nodelongapa = createNode(tx, containsLabel, containsProp, "longapa");
        nodeapaapa = createNode(tx, containsLabel, containsProp, "apa apa");
        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, endsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodelongapa, nodeapaapa);
        assertQueryResult(ktx, endsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodelongapa, nodeapaapa);
        assertQueryResult(ktx, endsWithQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, endsWithQuery(containsPropertyId, "a apa"), nodeapaapa);
        assertQueryResult(ktx, endsWithQuery(containsPropertyId, "*apa"));
    }
    controller.restartDbms();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        assertQueryResult(ktx, endsWithQuery(containsPropertyId, "a"), nodea, nodeapa1, nodeapa2, nodelongapa, nodeapaapa);
        assertQueryResult(ktx, endsWithQuery(containsPropertyId, "apa"), nodeapa1, nodeapa2, nodelongapa, nodeapaapa);
        assertQueryResult(ktx, endsWithQuery(containsPropertyId, "apa*"));
        assertQueryResult(ktx, endsWithQuery(containsPropertyId, "a apa"), nodeapaapa);
        assertQueryResult(ktx, endsWithQuery(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)

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