Search in sources :

Example 41 with PrimitiveLongIterator

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

the class DynamicIndexStoreViewTest method shouldBeAbleToForceStoreScan.

@Test
public void shouldBeAbleToForceStoreScan() throws Exception {
    when(labelScanStore.newReader()).thenThrow(new RuntimeException("Should not be used"));
    PrimitiveLongIterator labeledNodesIterator = PrimitiveLongCollections.iterator(1, 2, 3, 4, 5, 6, 7, 8);
    when(nodeStore.getHighestPossibleIdInUse()).thenReturn(200L);
    when(nodeStore.getHighId()).thenReturn(20L);
    mockLabelNodeCount(countStore, 2);
    mockLabelNodeCount(countStore, 6);
    DynamicIndexStoreView storeView = new DynamicIndexStoreView(labelScanStore, LockService.NO_LOCK_SERVICE, neoStores, NullLogProvider.getInstance());
    StoreScan<Exception> storeScan = storeView.visitNodes(new int[] { 2, 6 }, propertyKeyIdFilter, propertyUpdateVisitor, labelUpdateVisitor, true);
    storeScan.run();
    Mockito.verify(nodeStore, times(20)).getRecord(anyLong(), any(NodeRecord.class), any(RecordLoad.class));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) Test(org.junit.Test)

Example 42 with PrimitiveLongIterator

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

the class LuceneLegacyIndex method letThroughAdditions.

private void letThroughAdditions(IndexSearcher additionsSearcher, Query query, Collection<EntityId> removed) throws IOException {
    // This could be improved further by doing a term-dict lookup for every term in removed
    // and retaining only those that did not match.
    // This is getting quite low-level though
    DocValuesCollector collector = new DocValuesCollector(false);
    additionsSearcher.search(query, collector);
    PrimitiveLongIterator valuesIterator = collector.getValuesIterator(KEY_DOC_ID);
    LongCostume id = new LongCostume();
    while (valuesIterator.hasNext()) {
        long value = valuesIterator.next();
        removed.remove(id.setId(value));
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) LongCostume(org.neo4j.index.impl.lucene.legacy.EntityId.LongCostume) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)

Example 43 with PrimitiveLongIterator

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

the class DocValuesCollectorTest method shouldReturnDocValuesInGivenOrder.

@Test
public void shouldReturnDocValuesInGivenOrder() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    collector.collect(2);
    // then
    Sort byIdDescending = new Sort(new SortField("id", SortField.Type.LONG, true));
    PrimitiveLongIterator valuesIterator = collector.getSortedValuesIterator("id", byIdDescending);
    assertEquals(2, valuesIterator.next());
    assertEquals(1, valuesIterator.next());
    assertFalse(valuesIterator.hasNext());
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) Test(org.junit.Test)

Example 44 with PrimitiveLongIterator

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

the class DatabaseIndexAccessorTest method indexReaderShouldSupportScan.

@Test
public void indexReaderShouldSupportScan() throws Exception {
    // GIVEN
    updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
    IndexReader reader = accessor.newReader();
    // WHEN
    PrimitiveLongIterator results = reader.query(IndexQuery.exists(PROP_ID));
    // THEN
    assertEquals(asSet(nodeId, nodeId2), PrimitiveLongCollections.toSet(results));
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(reader.query(IndexQuery.exact(PROP_ID, value))));
    reader.close();
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 45 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)

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