From c2f12becbbb89c402a2e7387104ce4a079fe2253 Mon Sep 17 00:00:00 2001 From: fickludd Date: Wed, 8 Nov 2017 13:21:35 +0100 Subject: [PATCH] refactor and javadoc och IndexProgressor and friends --- .../impl/newapi/ExplicitIndexProgressor.java | 11 +- .../neo4j/kernel/impl/newapi/IndexCursor.java | 6 +- .../kernel/impl/newapi/IndexCursorFilter.java | 19 +-- .../impl/newapi/IndexCursorProgressor.java | 57 ------- .../impl/newapi/NodeExplicitIndexCursor.java | 8 +- .../impl/newapi/NodeLabelIndexCursor.java | 8 +- .../impl/newapi/NodeLabelIndexProgressor.java | 11 +- .../impl/newapi/NodeValueIndexCursor.java | 10 +- .../org/neo4j/kernel/impl/newapi/Read.java | 11 +- .../RelationshipExplicitIndexCursor.java | 8 +- .../api/schema/IndexProgressor.java | 144 ++++++++++++++++++ .../storageengine/api/schema/IndexReader.java | 25 +-- .../api/schema/NodeValueIndexProgressor.java | 11 +- .../impl/newapi/IndexCursorFilterTest.java | 24 +-- .../schema/reader/SimpleIndexReaderTest.java | 2 +- 15 files changed, 231 insertions(+), 124 deletions(-) delete mode 100644 community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorProgressor.java create mode 100644 community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexProgressor.java diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/ExplicitIndexProgressor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/ExplicitIndexProgressor.java index c2f400fa2b41..391705e9d678 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/ExplicitIndexProgressor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/ExplicitIndexProgressor.java @@ -20,16 +20,17 @@ package org.neo4j.kernel.impl.newapi; import org.neo4j.kernel.api.ExplicitIndexHits; +import org.neo4j.storageengine.api.schema.IndexProgressor; -class ExplicitIndexProgressor implements IndexCursorProgressor +class ExplicitIndexProgressor implements IndexProgressor { - private final ExplicitCursor cursor; + private final ExplicitClient client; private final ExplicitIndexHits hits; - ExplicitIndexProgressor( ExplicitCursor cursor, ExplicitIndexHits hits ) + ExplicitIndexProgressor( ExplicitIndexHits hits, ExplicitClient client ) { - this.cursor = cursor; this.hits = hits; + this.client = client; } @Override @@ -37,7 +38,7 @@ public boolean next() { while ( hits.hasNext() ) { - if ( cursor.entity( hits.next(), hits.currentScore() ) ) + if ( client.acceptEntity( hits.next(), hits.currentScore() ) ) { return true; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursor.java index db623fa931a2..177c54cc63cd 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursor.java @@ -19,11 +19,13 @@ */ package org.neo4j.kernel.impl.newapi; +import org.neo4j.storageengine.api.schema.IndexProgressor; + abstract class IndexCursor { - private IndexCursorProgressor progressor; + private IndexProgressor progressor; - final void initialize( IndexCursorProgressor progressor ) + final void initialize( IndexProgressor progressor ) { this.progressor = progressor; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorFilter.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorFilter.java index 1c24d999ad15..83ce6da98015 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorFilter.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorFilter.java @@ -23,19 +23,20 @@ import java.util.Comparator; import org.neo4j.internal.kernel.api.IndexQuery; +import org.neo4j.storageengine.api.schema.IndexProgressor; import org.neo4j.values.storable.Value; -class IndexCursorFilter implements IndexCursorProgressor.NodeValueCursor +class IndexCursorFilter implements IndexProgressor.NodeValueClient { private static final Comparator ASCENDING_BY_KEY = Comparator.comparingInt( IndexQuery::propertyKeyId ); - private final IndexCursorProgressor.NodeValueCursor target; + private final IndexProgressor.NodeValueClient target; private final NodeCursor node; private final PropertyCursor property; private final IndexQuery[] filters; private int[] keys; IndexCursorFilter( - IndexCursorProgressor.NodeValueCursor target, + IndexProgressor.NodeValueClient target, NodeCursor node, PropertyCursor property, IndexQuery... filters ) { this.target = target; @@ -46,10 +47,10 @@ class IndexCursorFilter implements IndexCursorProgressor.NodeValueCursor } @Override - public void initialize( IndexCursorProgressor progressor, int[] keys ) + public void initialize( IndexProgressor progressor, int[] propertyIds ) { - this.keys = keys; - target.initialize( progressor, keys ); + this.keys = propertyIds; + target.initialize( progressor, propertyIds ); } @Override @@ -61,7 +62,7 @@ public void done() } @Override - public boolean node( long reference, Value[] values ) + public boolean acceptNode( long reference, Value[] values ) { if ( keys != null && values != null ) { @@ -102,7 +103,7 @@ private boolean filterByIndexValues( long reference, Value[] values ) assert false : "Cannot satisfy filter " + filter + " - no corresponding key!"; return false; } - return target.node( reference, values ); + return target.acceptNode( reference, values ); } private boolean filterByCursors( long reference, Value[] values ) @@ -132,6 +133,6 @@ else if ( property.propertyKey() < filter.propertyKeyId() ) { return false; // not all filters were matched } - return target.node( reference, values ); + return target.acceptNode( reference, values ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorProgressor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorProgressor.java deleted file mode 100644 index 82312fb7a739..000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/IndexCursorProgressor.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2002-2017 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.kernel.impl.newapi; - -import org.neo4j.internal.kernel.api.LabelSet; -import org.neo4j.values.storable.Value; - -public interface IndexCursorProgressor extends AutoCloseable -{ - boolean next(); - - void close(); - - interface NodeValueCursor - { - void initialize( IndexCursorProgressor progressor, int[] keys ); - - boolean node( long reference, Value[] values ); - - void done(); - } - - interface NodeLabelCursor - { - void initialize( IndexCursorProgressor progressor, boolean providesLabels ); - - boolean node( long reference, LabelSet labels ); - - void done(); - } - - interface ExplicitCursor - { - void initialize( IndexCursorProgressor progressor, int expectedSize ); - - boolean entity( long reference, float score ); - - void done(); - } -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeExplicitIndexCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeExplicitIndexCursor.java index b59869501a67..4f93a2b412c3 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeExplicitIndexCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeExplicitIndexCursor.java @@ -20,11 +20,13 @@ package org.neo4j.kernel.impl.newapi; import org.neo4j.internal.kernel.api.NodeCursor; +import org.neo4j.storageengine.api.schema.IndexProgressor; +import org.neo4j.storageengine.api.schema.IndexProgressor.ExplicitClient; import static org.neo4j.kernel.impl.store.record.AbstractBaseRecord.NO_ID; class NodeExplicitIndexCursor extends IndexCursor - implements org.neo4j.internal.kernel.api.NodeExplicitIndexCursor, IndexCursorProgressor.ExplicitCursor + implements org.neo4j.internal.kernel.api.NodeExplicitIndexCursor, ExplicitClient { private final Read read; private int expectedSize; @@ -37,14 +39,14 @@ class NodeExplicitIndexCursor extends IndexCursor } @Override - public void initialize( IndexCursorProgressor progressor, int expectedSize ) + public void initialize( IndexProgressor progressor, int expectedSize ) { super.initialize( progressor ); this.expectedSize = expectedSize; } @Override - public boolean entity( long reference, float score ) + public boolean acceptEntity( long reference, float score ) { this.node = reference; this.score = score; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexCursor.java index f73ebe4981c8..f5273b5f2098 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexCursor.java @@ -21,11 +21,13 @@ import org.neo4j.internal.kernel.api.LabelSet; import org.neo4j.internal.kernel.api.NodeCursor; +import org.neo4j.storageengine.api.schema.IndexProgressor; +import org.neo4j.storageengine.api.schema.IndexProgressor.NodeLabelClient; import static org.neo4j.kernel.impl.store.record.AbstractBaseRecord.NO_ID; class NodeLabelIndexCursor extends IndexCursor - implements org.neo4j.internal.kernel.api.NodeLabelIndexCursor, IndexCursorProgressor.NodeLabelCursor + implements org.neo4j.internal.kernel.api.NodeLabelIndexCursor, NodeLabelClient { private final Read read; private long node; @@ -37,13 +39,13 @@ class NodeLabelIndexCursor extends IndexCursor } @Override - public void initialize( IndexCursorProgressor progressor, boolean providesLabels ) + public void initialize( IndexProgressor progressor, boolean providesLabels ) { super.initialize( progressor ); } @Override - public boolean node( long reference, LabelSet labels ) + public boolean acceptNode( long reference, LabelSet labels ) { this.node = reference; this.labels = labels; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexProgressor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexProgressor.java index 6d0cf8dfea02..3900d7d568dc 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexProgressor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexProgressor.java @@ -21,16 +21,17 @@ import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.graphdb.Resource; +import org.neo4j.storageengine.api.schema.IndexProgressor; -class NodeLabelIndexProgressor implements IndexCursorProgressor +class NodeLabelIndexProgressor implements IndexProgressor { private final PrimitiveLongIterator iterator; - private final NodeLabelCursor target; + private final NodeLabelClient client; - NodeLabelIndexProgressor( PrimitiveLongIterator iterator, NodeLabelCursor target ) + NodeLabelIndexProgressor( PrimitiveLongIterator iterator, NodeLabelClient client ) { this.iterator = iterator; - this.target = target; + this.client = client; } @Override @@ -38,7 +39,7 @@ public boolean next() { while ( iterator.hasNext() ) { - if ( target.node( iterator.next(), null ) ) + if ( client.acceptNode( iterator.next(), null ) ) { return true; } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeValueIndexCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeValueIndexCursor.java index a8fb8c098edd..be6057f4e17f 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeValueIndexCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeValueIndexCursor.java @@ -20,12 +20,14 @@ package org.neo4j.kernel.impl.newapi; import org.neo4j.internal.kernel.api.NodeCursor; +import org.neo4j.storageengine.api.schema.IndexProgressor; +import org.neo4j.storageengine.api.schema.IndexProgressor.NodeValueClient; import org.neo4j.values.storable.Value; import static org.neo4j.kernel.impl.store.record.AbstractBaseRecord.NO_ID; class NodeValueIndexCursor extends IndexCursor - implements org.neo4j.internal.kernel.api.NodeValueIndexCursor, IndexCursorProgressor.NodeValueCursor + implements org.neo4j.internal.kernel.api.NodeValueIndexCursor, NodeValueClient { private final Read read; private long node; @@ -38,14 +40,14 @@ class NodeValueIndexCursor extends IndexCursor } @Override - public void initialize( IndexCursorProgressor progressor, int[] keys ) + public void initialize( IndexProgressor progressor, int[] propertyIds ) { super.initialize( progressor ); - this.keys = keys; + this.keys = propertyIds; } @Override - public boolean node( long reference, Value[] values ) + public boolean acceptNode( long reference, Value[] values ) { this.node = reference; this.values = values; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Read.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Read.java index 06dab70f866f..e442206cdb59 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Read.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/Read.java @@ -37,6 +37,7 @@ import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord; import org.neo4j.kernel.impl.store.record.RelationshipRecord; +import org.neo4j.storageengine.api.schema.IndexProgressor; import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.LabelScanReader; import org.neo4j.values.storable.ArrayValue; @@ -59,7 +60,7 @@ public final void nodeIndexSeek( org.neo4j.internal.kernel.api.NodeValueIndexCursor cursor, IndexQuery... query ) throws KernelException { - IndexCursorProgressor.NodeValueCursor target = (NodeValueIndexCursor) cursor; + IndexProgressor.NodeValueClient target = (NodeValueIndexCursor) cursor; IndexReader reader = indexReader( (IndexReference) index ); if ( !reader.hasFullNumberPrecision( query ) ) { @@ -127,9 +128,9 @@ public void nodeLabelIntersectionScan( org.neo4j.internal.kernel.api.NodeLabelIn labelScan( (NodeLabelIndexCursor) cursor, labelScanReader().nodesWithAllLabels( labels ) ); } - private void labelScan( IndexCursorProgressor.NodeLabelCursor target, PrimitiveLongIterator iterator ) + private void labelScan( IndexProgressor.NodeLabelClient client, PrimitiveLongIterator iterator ) { - target.initialize( new NodeLabelIndexProgressor( iterator, target ), false ); + client.initialize( new NodeLabelIndexProgressor( iterator, client ), false ); } @Override @@ -339,9 +340,9 @@ public void relationshipExplicitIndexQuery( key, query instanceof Value ? ((Value) query).asObject() : query, source, target ) ); } - private static void explicitIndex( IndexCursorProgressor.ExplicitCursor cursor, ExplicitIndexHits hits ) + private static void explicitIndex( IndexProgressor.ExplicitClient client, ExplicitIndexHits hits ) { - cursor.initialize( new ExplicitIndexProgressor( cursor, hits ), hits.size() ); + client.initialize( new ExplicitIndexProgressor( hits, client ), hits.size() ); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/RelationshipExplicitIndexCursor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/RelationshipExplicitIndexCursor.java index 7e61bf79a3bc..6055bbcc36d6 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/RelationshipExplicitIndexCursor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/RelationshipExplicitIndexCursor.java @@ -21,11 +21,13 @@ import org.neo4j.internal.kernel.api.NodeCursor; import org.neo4j.internal.kernel.api.RelationshipScanCursor; +import org.neo4j.storageengine.api.schema.IndexProgressor; +import org.neo4j.storageengine.api.schema.IndexProgressor.ExplicitClient; import static org.neo4j.kernel.impl.store.record.AbstractBaseRecord.NO_ID; class RelationshipExplicitIndexCursor extends IndexCursor - implements org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor, IndexCursorProgressor.ExplicitCursor + implements org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor, ExplicitClient { private final Read read; private int expectedSize; @@ -38,14 +40,14 @@ class RelationshipExplicitIndexCursor extends IndexCursor } @Override - public void initialize( IndexCursorProgressor progressor, int expectedSize ) + public void initialize( IndexProgressor progressor, int expectedSize ) { super.initialize( progressor ); this.expectedSize = expectedSize; } @Override - public boolean entity( long reference, float score ) + public boolean acceptEntity( long reference, float score ) { this.relationship = reference; this.score = score; diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexProgressor.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexProgressor.java new file mode 100644 index 000000000000..8222f31c3bcf --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexProgressor.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2002-2017 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.storageengine.api.schema; + +import org.neo4j.internal.kernel.api.LabelSet; +import org.neo4j.values.storable.Value; + +/** + * The index progressor is a cursor like class, which allows controlled progression through the entries of an index. + * In contrast to a cursor, the progressor does not hold value state, but rather attempts to write the next entry to a + * Client. The client can them accept the entry, in which case next() returns, or reject it, in which case the + * progression continues until an acceptable entry is found or the progression is done. + * + * A Progressor is expected to feed a single client, which is setup for example in the constructor. The typical + * interaction goes something like + * + * -- query(client) -> INDEX + * progressor = new Progressor( client ) + * client.initialize( progressor, ... ) + * + * -- next() --> client + * client ---- next() --> progressor + * <-- accept() -- + * :false + * <-- accept() -- + * :false + * <-- accept() -- + * :true + * client <-------------- + * <----------- + */ +public interface IndexProgressor extends AutoCloseable +{ + /** + * Progress through the index until the next accepted entry. Entries are feed to a Client, which + * is setup in an implementation specific way. + * + * @return true if an accepted entry was found, false otherwise + */ + boolean next(); + + /** + * Close the progressor and all attached resources. Idempotent. + */ + void close(); + + /** + * Client which accepts nodes and some of their property values. + */ + interface NodeValueClient + { + /** + * Setup the client for progressing using the supplied progressor. The values feed in accept map to the + * propertyIds provided here. Called by index implementation. + * @param progressor The progressor + * @param propertyIds The property ids of this progression + */ + void initialize( IndexProgressor progressor, int[] propertyIds ); + + /** + * Accept the node id and values of a candidate index entry. Return true if the entry is + * accepted, false otherwise. + * @param reference the node id of the candidate index entry + * @param values the values of the candidate index entry + * @return true if the entry is accepted, false otherwise + */ + boolean acceptNode( long reference, Value[] values ); + + /** + * Called by progressor so signal that there are no more entries. + */ + void done(); + } + + /** + * Client which accepts nodes and some of their labels. + */ + interface NodeLabelClient + { + /** + * Setup the client for progressing using the supplied progressor. Called by index implementation. + * @param progressor the progressor + * @param providesLabels true if the progression can provide label information + */ + void initialize( IndexProgressor progressor, boolean providesLabels ); + + /** + * Accept the node id and (some) labels of a candidate index entry. Return true if the entry + * is accepted, false otherwise. + * @param reference the node id of the candidate index entry + * @param labels some labels of the candidate index entry + * @return true if the entry is accepted, false otherwise + */ + boolean acceptNode( long reference, LabelSet labels ); + + /** + * Called by progressor so signal that there are no more entries. + */ + void done(); + } + + /** + * Client which accepts graph entities (nodes and relationships) and a fuzzy score. + */ + interface ExplicitClient + { + /** + * Setup the client for progressing using the supplied progressor. Called by index implementation. + * @param progressor the progressor + * @param expectedSize expected number of entries this progressor will feed the client. + */ + void initialize( IndexProgressor progressor, int expectedSize ); + + /** + * Accept the entity id and a score. Return true if the entry is accepted, false otherwise + * @param reference the node id of the candidate index entry + * @param score score of the candidate index entry + * @return true if the entry is accepted, false otherwise + */ + boolean acceptEntity( long reference, float score ); + + /** + * Called by progressor so signal that there are no more entries. + */ + void done(); + } +} diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexReader.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexReader.java index fa418e22f262..aa841157fa2f 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexReader.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/IndexReader.java @@ -24,7 +24,6 @@ import org.neo4j.graphdb.Resource; import org.neo4j.internal.kernel.api.IndexQuery; import org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException; -import org.neo4j.kernel.impl.newapi.IndexCursorProgressor; import org.neo4j.values.storable.Value; /** @@ -50,6 +49,19 @@ public interface IndexReader extends Resource */ PrimitiveLongIterator query( IndexQuery... predicates ) throws IndexNotApplicableKernelException; + /** + * Queries the index for the given {@link IndexQuery} predicates. + * + * @param client the client which will control the progression though query results. + * @param query the query so serve. + */ + default void query( + IndexProgressor.NodeValueClient client, + IndexQuery... query ) throws IndexNotApplicableKernelException + { + client.initialize( new NodeValueIndexProgressor( query( query ), client ), null ); + } + /** * @param predicates query to determine whether or not index has full number precision for. * @return whether or not this reader will only return 100% matching results from {@link #query(IndexQuery...)} @@ -93,16 +105,9 @@ public boolean hasFullNumberPrecision( IndexQuery... predicates ) } @Override - public void query( IndexCursorProgressor.NodeValueCursor cursor, IndexQuery... query ) + public void query( IndexProgressor.NodeValueClient client, IndexQuery... query ) { - cursor.done(); + client.done(); } }; - - default void query( - IndexCursorProgressor.NodeValueCursor cursor, - IndexQuery... query ) throws IndexNotApplicableKernelException - { - cursor.initialize( new NodeValueIndexProgressor( query( query ), cursor ), null ); - } } diff --git a/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/NodeValueIndexProgressor.java b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/NodeValueIndexProgressor.java index af4e53a67c15..3f1152f7e506 100644 --- a/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/NodeValueIndexProgressor.java +++ b/community/kernel/src/main/java/org/neo4j/storageengine/api/schema/NodeValueIndexProgressor.java @@ -21,17 +21,16 @@ import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.graphdb.Resource; -import org.neo4j.kernel.impl.newapi.IndexCursorProgressor; -class NodeValueIndexProgressor implements IndexCursorProgressor +class NodeValueIndexProgressor implements IndexProgressor { private final PrimitiveLongIterator ids; - private final NodeValueCursor target; + private final NodeValueClient client; - NodeValueIndexProgressor( PrimitiveLongIterator ids, NodeValueCursor target ) + NodeValueIndexProgressor( PrimitiveLongIterator ids, NodeValueClient client ) { this.ids = ids; - this.target = target; + this.client = client; } @Override @@ -39,7 +38,7 @@ public boolean next() { while ( ids.hasNext() ) { - if ( target.node( ids.next(), null ) ) + if ( client.acceptNode( ids.next(), null ) ) { return true; } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/IndexCursorFilterTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/IndexCursorFilterTest.java index 795f5c1b70c2..4a5be5627426 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/IndexCursorFilterTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/IndexCursorFilterTest.java @@ -31,6 +31,8 @@ import org.junit.Test; import org.neo4j.internal.kernel.api.IndexQuery; +import org.neo4j.storageengine.api.schema.IndexProgressor; +import org.neo4j.storageengine.api.schema.IndexProgressor.NodeValueClient; import org.neo4j.values.storable.Value; import static org.junit.Assert.assertEquals; @@ -40,7 +42,7 @@ import static org.neo4j.kernel.impl.store.record.AbstractBaseRecord.NO_ID; import static org.neo4j.values.storable.Values.stringValue; -public class IndexCursorFilterTest implements IndexCursorProgressor, IndexCursorProgressor.NodeValueCursor +public class IndexCursorFilterTest implements IndexProgressor, NodeValueClient { @Rule public final MockStore store = new MockStore(); @@ -54,7 +56,7 @@ public void shouldAcceptAllNodesOnNoFilters() throws Exception IndexCursorFilter filter = initializeFilter( null ); // when - assertTrue( filter.node( 17, null ) ); + assertTrue( filter.acceptNode( 17, null ) ); filter.done(); // then @@ -68,7 +70,7 @@ public void shouldRejectNodeNotInUse() throws Exception IndexCursorFilter filter = initializeFilter( null, IndexQuery.exists( 12 ) ); // when - assertFalse( filter.node( 17, null ) ); + assertFalse( filter.acceptNode( 17, null ) ); filter.done(); // then @@ -83,7 +85,7 @@ public void shouldRejectNodeWithNoProperties() throws Exception IndexCursorFilter filter = initializeFilter( null, IndexQuery.exists( 12 ) ); // when - assertFalse( filter.node( 17, null ) ); + assertFalse( filter.acceptNode( 17, null ) ); filter.done(); // then @@ -99,7 +101,7 @@ public void shouldAcceptNodeWithMatchingProperty() throws Exception IndexCursorFilter filter = initializeFilter( null, IndexQuery.exists( 12 ) ); // when - assertTrue( filter.node( 17, null ) ); + assertTrue( filter.acceptNode( 17, null ) ); filter.done(); // then @@ -115,7 +117,7 @@ public void shouldNotAcceptNodeWithoutMatchingProperty() throws Exception IndexCursorFilter filter = initializeFilter( null, IndexQuery.exists( 12 ) ); // when - assertFalse( filter.node( 17, null ) ); + assertFalse( filter.acceptNode( 17, null ) ); filter.done(); // then @@ -141,9 +143,9 @@ private Event.Initialize initialize( int... keys ) } @Override - public void initialize( IndexCursorProgressor progressor, int[] keys ) + public void initialize( IndexProgressor progressor, int[] propertyIds ) { - events.add( new Event.Initialize( progressor, keys ) ); + events.add( new Event.Initialize( progressor, propertyIds ) ); } @Override @@ -153,7 +155,7 @@ public void done() } @Override - public boolean node( long reference, Value[] values ) + public boolean acceptNode( long reference, Value[] values ) { events.add( new Event.Node( reference, values ) ); return true; @@ -175,10 +177,10 @@ private abstract static class Event { static class Initialize extends Event { - final transient IndexCursorProgressor progressor; + final transient IndexProgressor progressor; final int[] keys; - Initialize( IndexCursorProgressor progressor, int[] keys ) + Initialize( IndexProgressor progressor, int[] keys ) { this.progressor = progressor; this.keys = keys; diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReaderTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReaderTest.java index 6d2d6e66faf3..c76a695cc2ea 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReaderTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/api/impl/schema/reader/SimpleIndexReaderTest.java @@ -46,7 +46,7 @@ import org.neo4j.values.storable.Values; import static org.hamcrest.Matchers.instanceOf; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when;