Search in sources :

Example 21 with PrimitiveLongIterator

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

the class ReadRecordsStep method nextBatchOrNull.

@SuppressWarnings("unchecked")
@Override
protected Object nextBatchOrNull(long ticket, int batchSize) {
    PrimitiveLongIterator ids;
    while ((ids = this.ids.nextBatch()) != null) {
        RECORD[] batch = (RECORD[]) Array.newInstance(klass, batchSize);
        int i = 0;
        while (ids.hasNext()) {
            if (cursor.next(ids.next()) && !IdValidator.isReservedId(record.getId())) {
                batch[i++] = (RECORD) record.clone();
            }
        }
        if (i > 0) {
            count += i;
            return i == batchSize ? batch : Arrays.copyOf(batch, i);
        }
    }
    return null;
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator)

Example 22 with PrimitiveLongIterator

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

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexScanWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexScanWithIndexQuery() throws Exception {
    // Given
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    when(txState.indexUpdatesForScan(index)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    IndexReader indexReader = addMockedIndexReader(statement);
    IndexQuery query = IndexQuery.exists(index.schema().getPropertyId());
    when(indexReader.query(query)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, query);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 23 with PrimitiveLongIterator

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

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix.

@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix() throws Exception {
    // Given
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    when(txState.indexUpdatesForRangeSeekByPrefix(index, "prefix")).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    IndexReader indexReader = addMockedIndexReader(statement);
    IndexQuery.StringPrefixPredicate query = IndexQuery.stringPrefix(index.schema().getPropertyId(), "prefix");
    when(indexReader.query(query)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, query);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 24 with PrimitiveLongIterator

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

the class NodeLoadingIteratorTest method shouldHandleANonEmptyIteratorWithNotFoundEntities.

@Test
public void shouldHandleANonEmptyIteratorWithNotFoundEntities() throws Exception {
    // given
    Map<Long, Cursor<NodeItem>> map = new HashMap<>(3);
    map.put(1L, mockCursor());
    map.put(2L, null);
    map.put(3L, mockCursor());
    PrimitiveLongIterator inner = PrimitiveLongCollections.iterator(1, 2, 3);
    NodeLoadingIterator iterator = new NodeLoadingIterator(inner, createMapping(map));
    // when - then
    for (long i = 1; i <= 2; i++) {
        assertTrue(iterator.hasNext());
        assertEquals(map.get(i + (i - 1)), iterator.next());
    }
    assertNoMoreElements(iterator);
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) HashMap(java.util.HashMap) Cursor(org.neo4j.cursor.Cursor) Test(org.junit.Test)

Example 25 with PrimitiveLongIterator

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

the class NodeLoadingIteratorTest method shouldHandleANonEmptyIterator.

@Test
public void shouldHandleANonEmptyIterator() throws Exception {
    // given
    Map<Long, Cursor<NodeItem>> map = new HashMap<>(3);
    map.put(1L, mockCursor());
    map.put(2L, mockCursor());
    map.put(3L, mockCursor());
    PrimitiveLongIterator inner = PrimitiveLongCollections.iterator(1, 2, 3);
    NodeLoadingIterator iterator = new NodeLoadingIterator(inner, createMapping(map));
    // when - then
    for (long i = 1; i <= 3; i++) {
        assertTrue(iterator.hasNext());
        assertEquals(map.get(i), iterator.next());
    }
    assertNoMoreElements(iterator);
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) HashMap(java.util.HashMap) Cursor(org.neo4j.cursor.Cursor) Test(org.junit.Test)

Aggregations

PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)68 Test (org.junit.Test)47 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)15 Transaction (org.neo4j.graphdb.Transaction)10 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)10 ReadOperations (org.neo4j.kernel.api.ReadOperations)8 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 IOException (java.io.IOException)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Node (org.neo4j.graphdb.Node)4 Statement (org.neo4j.kernel.api.Statement)4 DiffSets (org.neo4j.kernel.impl.util.diffsets.DiffSets)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 ArrayList (java.util.ArrayList)3 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2