Search in sources :

Example 21 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader 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 22 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method canRemoveExistingData.

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

Example 23 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method canChangeExistingData.

@Test
public void canChangeExistingData() throws Exception {
    // GIVEN
    updateAndCommit(asList(add(nodeId, value)));
    // WHEN
    updateAndCommit(asList(change(nodeId, value, value2)));
    IndexReader reader = accessor.newReader();
    // THEN
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(reader.query(exact(PROP_ID, value2))));
    assertEquals(emptySetOf(Long.class), PrimitiveLongCollections.toSet(reader.query(exact(PROP_ID, value))));
    reader.close();
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 24 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class OnlineIndexSamplingJob method run.

@Override
public void run() {
    try (DurationLogger durationLogger = new DurationLogger(log, "Sampling index " + indexUserDescription)) {
        try {
            try (IndexReader reader = indexProxy.newReader()) {
                IndexSampler sampler = reader.createSampler();
                IndexSample sample = sampler.sampleIndex();
                // check again if the index is online before saving the counts in the store
                if (indexProxy.getState() == ONLINE) {
                    storeView.replaceIndexCounts(indexId, sample.uniqueValues(), sample.sampleSize(), sample.indexSize());
                    durationLogger.markAsFinished();
                    log.info(format("Sampled index %s with %d unique values in sample of avg size %d taken from " + "index containing %d entries", indexUserDescription, sample.uniqueValues(), sample.sampleSize(), sample.indexSize()));
                } else {
                    durationLogger.markAsAborted("Index no longer ONLINE");
                }
            }
        } catch (IndexNotFoundKernelException e) {
            durationLogger.markAsAborted("Attempted to sample missing/already deleted index " + indexUserDescription);
        }
    }
}
Also used : DurationLogger(org.neo4j.kernel.impl.util.DurationLogger) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler)

Example 25 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class StateHandlingStatementOperations method indexQuery.

@Override
public PrimitiveLongIterator indexQuery(KernelStatement state, NewIndexDescriptor index, IndexQuery... predicates) throws IndexNotFoundKernelException, IndexNotApplicableKernelException {
    StorageStatement storeStatement = state.getStoreStatement();
    IndexReader reader = storeStatement.getIndexReader(index);
    PrimitiveLongIterator committed = reader.query(predicates);
    PrimitiveLongIterator exactMatches = LookupFilter.exactIndexMatches(this, state, committed, predicates);
    IndexQuery firstPredicate = predicates[0];
    switch(firstPredicate.type()) {
        case exact:
            IndexQuery.ExactPredicate[] exactPreds = assertOnlyExactPredicates(predicates);
            return filterIndexStateChangesForSeek(state, exactMatches, index, OrderedPropertyValues.of(exactPreds));
        case stringSuffix:
        case stringContains:
        case exists:
            return filterIndexStateChangesForScan(state, exactMatches, index);
        case rangeNumeric:
            {
                assertSinglePredicate(predicates);
                IndexQuery.NumberRangePredicate numPred = (IndexQuery.NumberRangePredicate) firstPredicate;
                return filterIndexStateChangesForRangeSeekByNumber(state, index, numPred.from(), numPred.fromInclusive(), numPred.to(), numPred.toInclusive(), exactMatches);
            }
        case rangeString:
            {
                assertSinglePredicate(predicates);
                IndexQuery.StringRangePredicate strPred = (IndexQuery.StringRangePredicate) firstPredicate;
                return filterIndexStateChangesForRangeSeekByString(state, index, strPred.from(), strPred.fromInclusive(), strPred.to(), strPred.toInclusive(), committed);
            }
        case stringPrefix:
            {
                assertSinglePredicate(predicates);
                IndexQuery.StringPrefixPredicate strPred = (IndexQuery.StringPrefixPredicate) firstPredicate;
                return filterIndexStateChangesForRangeSeekByPrefix(state, index, strPred.prefix(), committed);
            }
        default:
            throw new UnsupportedOperationException("Query not supported: " + Arrays.toString(predicates));
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) StorageStatement(org.neo4j.storageengine.api.StorageStatement) IndexReader(org.neo4j.storageengine.api.schema.IndexReader)

Aggregations

IndexReader (org.neo4j.storageengine.api.schema.IndexReader)50 Test (org.junit.Test)38 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)19 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)11 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)10 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)10 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)9 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)9 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)6 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)5 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TermQuery (org.apache.lucene.search.TermQuery)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.fail (org.junit.Assert.fail)2 Before (org.junit.Before)2