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));
}
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();
}
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();
}
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);
}
}
}
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));
}
}
Aggregations