Search in sources :

Example 46 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method indexStringRangeQuery.

@Test
public void indexStringRangeQuery() throws Exception {
    updateAndCommit(asList(add(PROP_ID, "A"), add(2, "B"), add(3, "C"), add(4, "")));
    IndexReader reader = accessor.newReader();
    PrimitiveLongIterator rangeFromBInclusive = reader.query(range(PROP_ID, "B", true, null, false));
    assertThat(PrimitiveLongCollections.asArray(rangeFromBInclusive), LongArrayMatcher.of(2, 3));
    PrimitiveLongIterator rangeFromANonInclusive = reader.query(range(PROP_ID, "A", false, null, false));
    assertThat(PrimitiveLongCollections.asArray(rangeFromANonInclusive), LongArrayMatcher.of(2, 3));
    PrimitiveLongIterator emptyLowInclusive = reader.query(range(PROP_ID, "", true, null, false));
    assertThat(PrimitiveLongCollections.asArray(emptyLowInclusive), LongArrayMatcher.of(PROP_ID, 2, 3, 4));
    PrimitiveLongIterator emptyUpperNonInclusive = reader.query(range(PROP_ID, "B", true, "", false));
    assertThat(PrimitiveLongCollections.asArray(emptyUpperNonInclusive), LongArrayMatcher.emptyArrayMatcher());
    PrimitiveLongIterator emptyInterval = reader.query(range(PROP_ID, "", true, "", true));
    assertThat(PrimitiveLongCollections.asArray(emptyInterval), LongArrayMatcher.of(4));
    PrimitiveLongIterator emptyAllNonInclusive = reader.query(range(PROP_ID, "", false, null, false));
    assertThat(PrimitiveLongCollections.asArray(emptyAllNonInclusive), LongArrayMatcher.of(PROP_ID, 2, 3));
    PrimitiveLongIterator nullNonInclusive = reader.query(range(PROP_ID, (String) null, false, null, false));
    assertThat(PrimitiveLongCollections.asArray(nullNonInclusive), LongArrayMatcher.of(PROP_ID, 2, 3, 4));
    PrimitiveLongIterator nullInclusive = reader.query(range(PROP_ID, (String) null, false, null, false));
    assertThat(PrimitiveLongCollections.asArray(nullInclusive), LongArrayMatcher.of(PROP_ID, 2, 3, 4));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 47 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class NonUniqueDatabaseIndexPopulatorTest method addUpdates.

@Test
public void addUpdates() throws Exception {
    populator = newPopulator();
    List<IndexEntryUpdate> updates = Arrays.asList(IndexEntryUpdate.add(1, labelSchemaDescriptor, "foo"), IndexEntryUpdate.add(2, labelSchemaDescriptor, "bar"), IndexEntryUpdate.add(42, labelSchemaDescriptor, "bar"));
    populator.add(updates);
    index.maybeRefreshBlocking();
    try (IndexReader reader = index.getIndexReader()) {
        int propertyKeyId = labelSchemaDescriptor.getPropertyId();
        PrimitiveLongIterator allEntities = reader.query(IndexQuery.exists(propertyKeyId));
        assertArrayEquals(new long[] { 1, 2, 42 }, PrimitiveLongCollections.asArray(allEntities));
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 48 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class CompositeIndexingIT method shouldSeeAllNodesAddedInTransaction.

@Test
public void shouldSeeAllNodesAddedInTransaction() throws Exception {
    if (// this test does not make any sense for UNIQUE indexes
    index.type() != UNIQUE) {
        try (Transaction ignore = graphDatabaseAPI.beginTx()) {
            long nodeID1 = createNode();
            long nodeID2 = createNode();
            long nodeID3 = createNode();
            PrimitiveLongIterator resultIterator = seek();
            Set<Long> result = PrimitiveLongCollections.toSet(resultIterator);
            assertThat(result, contains(nodeID1, nodeID2, nodeID3));
        }
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 49 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class CompositeIndexingIT method shouldNotSeeNodesLackingOneProperty.

@Test
public void shouldNotSeeNodesLackingOneProperty() throws Exception {
    long nodeID1 = createNode();
    try (Transaction ignore = graphDatabaseAPI.beginTx()) {
        DataWriteOperations writeOperations = statement().dataWriteOperations();
        long irrelevantNodeID = writeOperations.nodeCreate();
        writeOperations.nodeAddLabel(irrelevantNodeID, LABEL_ID);
        for (int i = 0; i < index.schema().getPropertyIds().length - 1; i++) {
            int propID = index.schema().getPropertyIds()[i];
            writeOperations.nodeSetProperty(irrelevantNodeID, DefinedProperty.intProperty(propID, propID));
        }
        PrimitiveLongIterator resultIterator = seek();
        Set<Long> result = PrimitiveLongCollections.toSet(resultIterator);
        assertThat(result, contains(nodeID1));
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 50 with PrimitiveLongIterator

use of org.neo4j.collection.primitive.PrimitiveLongIterator in project neo4j by neo4j.

the class CompositeIndexingIT method shouldSeeNodeAddedByPropertyToIndexInTranslation.

@Test
public void shouldSeeNodeAddedByPropertyToIndexInTranslation() throws Exception {
    try (Transaction ignore = graphDatabaseAPI.beginTx()) {
        DataWriteOperations writeOperations = statement().dataWriteOperations();
        long nodeID = writeOperations.nodeCreate();
        writeOperations.nodeAddLabel(nodeID, LABEL_ID);
        for (int propID : index.schema().getPropertyIds()) {
            writeOperations.nodeSetProperty(nodeID, DefinedProperty.intProperty(propID, propID));
        }
        PrimitiveLongIterator resultIterator = seek();
        assertThat(resultIterator.next(), equalTo(nodeID));
        assertFalse(resultIterator.hasNext());
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Aggregations

PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)65 Test (org.junit.Test)50 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)18 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)11 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)8 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)8 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)8 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)8 Transaction (org.neo4j.graphdb.Transaction)7 IndexReaderStub (org.neo4j.kernel.api.impl.index.IndexReaderStub)6 IOException (java.io.IOException)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Statement (org.neo4j.kernel.api.Statement)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 DiffSets (org.neo4j.kernel.impl.util.diffsets.DiffSets)4 Cursor (org.neo4j.cursor.Cursor)3 ReadOperations (org.neo4j.kernel.api.ReadOperations)3 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2