Search in sources :

Example 6 with PrimitiveLongIterator

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

the class LuceneLegacyIndex method gatherIdsModifiedInTransactionState.

private PrimitiveLongSet gatherIdsModifiedInTransactionState(List<EntityId> simpleTransactionStateIds, IndexSearcher fulltextTransactionStateSearcher, Query query) throws IOException {
    // If there's no state them don't bother gathering it
    if (simpleTransactionStateIds.isEmpty() && fulltextTransactionStateSearcher == null) {
        return PrimitiveLongCollections.emptySet();
    }
    // There's potentially some state
    DocValuesCollector docValuesCollector = null;
    int fulltextSize = 0;
    if (fulltextTransactionStateSearcher != null) {
        docValuesCollector = new DocValuesCollector();
        fulltextTransactionStateSearcher.search(query, docValuesCollector);
        fulltextSize = docValuesCollector.getTotalHits();
        // Nah, no state
        if (simpleTransactionStateIds.isEmpty() && fulltextSize == 0) {
            return PrimitiveLongCollections.emptySet();
        }
    }
    PrimitiveLongSet set = longSet(simpleTransactionStateIds.size() + fulltextSize);
    // Add from simple tx state
    for (EntityId id : simpleTransactionStateIds) {
        set.add(id.id());
    }
    if (docValuesCollector != null) {
        // Add from fulltext tx state
        PrimitiveLongIterator valuesIterator = docValuesCollector.getValuesIterator(LuceneLegacyIndex.KEY_DOC_ID);
        while (valuesIterator.hasNext()) {
            set.add(valuesIterator.next());
        }
    }
    return set;
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)

Example 7 with PrimitiveLongIterator

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

the class PageOfRangesIteratorTest method shouldReadPagesOfDocumentsFromSearcher.

@Test
public void shouldReadPagesOfDocumentsFromSearcher() throws Exception {
    final int labelId = 7;
    final int pageSize = 2;
    // given
    Query query = mock(Query.class);
    IndexSearcher searcher = mock(IndexSearcher.class);
    NumericDocValues rangeNDV = mock(NumericDocValues.class);
    when(rangeNDV.get(11)).thenReturn(0x1L);
    when(rangeNDV.get(16)).thenReturn(0x2L);
    when(rangeNDV.get(37)).thenReturn(0x3L);
    NumericDocValues labelNDV = mock(NumericDocValues.class);
    when(labelNDV.get(11)).thenReturn(0x01L);
    when(labelNDV.get(16)).thenReturn(0x03L);
    when(labelNDV.get(37)).thenReturn(0x30L);
    Map<String, NumericDocValues> docValues = MapUtil.genericMap("range", rangeNDV, "7", labelNDV);
    IndexReaderStub reader = new IndexReaderStub(docValues);
    reader.setElements(new String[] { "11", "16", "37" });
    final LeafReaderContext context = reader.getContext();
    doAnswer(invocation -> {
        DocValuesCollector collector = (DocValuesCollector) invocation.getArguments()[1];
        collector.doSetNextReader(context);
        collector.collect(11);
        collector.collect(16);
        collector.collect(37);
        return null;
    }).when(searcher).search(same(query), any(DocValuesCollector.class));
    PrimitiveLongIterator iterator = concat(new PageOfRangesIterator(format, searcher, pageSize, query, Occur.MUST, labelId));
    // when
    List<Long> longs = PrimitiveLongCollections.asList(iterator);
    // then
    assertEquals(asList(/*doc1:*/
    1L << format.bitmapFormat().shift, /*doc2:*/
    2L << format.bitmapFormat().shift, (2L << format.bitmapFormat().shift) + 1, /*doc3:*/
    (3L << format.bitmapFormat().shift) + 4, (3L << format.bitmapFormat().shift) + 5), longs);
    verify(searcher, times(1)).search(same(query), any(DocValuesCollector.class));
    verify(rangeNDV, times(6)).get(anyInt());
    verify(labelNDV, times(3)).get(anyInt());
    verifyNoMoreInteractions(searcher);
    verifyNoMoreInteractions(labelNDV);
    verifyNoMoreInteractions(rangeNDV);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) NumericDocValues(org.apache.lucene.index.NumericDocValues) Query(org.apache.lucene.search.Query) IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Test(org.junit.Test)

Example 8 with PrimitiveLongIterator

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

the class DatabaseCompositeIndexAccessorTest method indexReaderShouldSupportScan.

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

Example 9 with PrimitiveLongIterator

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

the class DatabaseIndexAccessorTest method indexNumberRangeQuery.

@Test
public void indexNumberRangeQuery() throws Exception {
    updateAndCommit(asList(add(1, 1), add(2, 2), add(3, 3), add(4, 4), add(5, Double.NaN)));
    IndexReader reader = accessor.newReader();
    PrimitiveLongIterator rangeTwoThree = reader.query(range(PROP_ID, 2, true, 3, true));
    assertThat(PrimitiveLongCollections.asArray(rangeTwoThree), LongArrayMatcher.of(2, 3));
    PrimitiveLongIterator infiniteMaxRange = reader.query(range(PROP_ID, 2, true, Long.MAX_VALUE, true));
    assertThat(PrimitiveLongCollections.asArray(infiniteMaxRange), LongArrayMatcher.of(2, 3, 4));
    PrimitiveLongIterator infiniteMinRange = reader.query(range(PROP_ID, Long.MIN_VALUE, true, 3, true));
    assertThat(PrimitiveLongCollections.asArray(infiniteMinRange), LongArrayMatcher.of(PROP_ID, 2, 3));
    PrimitiveLongIterator maxNanInterval = reader.query(range(PROP_ID, 3, true, Double.NaN, true));
    assertThat(PrimitiveLongCollections.asArray(maxNanInterval), LongArrayMatcher.of(3, 4, 5));
    PrimitiveLongIterator minNanInterval = reader.query(range(PROP_ID, Double.NaN, true, 5, true));
    assertThat(PrimitiveLongCollections.asArray(minNanInterval), LongArrayMatcher.emptyArrayMatcher());
    PrimitiveLongIterator nanInterval = reader.query(range(PROP_ID, Double.NaN, true, Double.NaN, true));
    assertThat(PrimitiveLongCollections.asArray(nanInterval), LongArrayMatcher.of(5));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 10 with PrimitiveLongIterator

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

the class DocValuesCollectorTest method shouldReturnDocValuesInIndexOrderWhenNoSortIsGiven.

@Test
public void shouldReturnDocValuesInIndexOrderWhenNoSortIsGiven() throws Exception {
    // given
    DocValuesCollector collector = new DocValuesCollector(false);
    IndexReaderStub readerStub = indexReaderWithMaxDocs(42);
    // when
    collector.doSetNextReader(readerStub.getContext());
    collector.collect(1);
    collector.collect(2);
    // then
    PrimitiveLongIterator valuesIterator = collector.getSortedValuesIterator("id", null);
    assertEquals(1, valuesIterator.next());
    assertEquals(2, valuesIterator.next());
    assertFalse(valuesIterator.hasNext());
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReaderStub(org.neo4j.kernel.api.impl.index.IndexReaderStub) 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