Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for label scan in the Kernel API implementation
- Loading branch information
Showing
9 changed files
with
246 additions
and
12 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
.../kernel-api/src/test/java/org/neo4j/internal/kernel/api/NodeLabelIndexCursorTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.internal.kernel.api; | ||
|
||
import org.junit.Test; | ||
|
||
import org.neo4j.collection.primitive.Primitive; | ||
import org.neo4j.collection.primitive.PrimitiveLongSet; | ||
import org.neo4j.graphdb.GraphDatabaseService; | ||
import org.neo4j.graphdb.Transaction; | ||
|
||
import static org.neo4j.graphdb.Label.label; | ||
import static org.neo4j.internal.kernel.api.NodeValueIndexCursorTestBase.assertFoundNodes; | ||
|
||
public abstract class NodeLabelIndexCursorTestBase<G extends KernelAPIReadTestSupport> | ||
extends KernelAPIReadTestBase<G> | ||
{ | ||
@Override | ||
void createTestGraph( GraphDatabaseService graphDb ) | ||
{ | ||
try ( Transaction tx = graphDb.beginTx() ) | ||
{ | ||
graphDb.createNode( label( "One" ), label( "First" ) ); | ||
graphDb.createNode( label( "Two" ), label( "First" ) ); | ||
graphDb.createNode( label( "Three" ), label( "First" ) ); | ||
graphDb.createNode( label( "Two" ) ); | ||
graphDb.createNode( label( "Three" ) ); | ||
graphDb.createNode( label( "Three" ) ); | ||
|
||
tx.success(); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldFindNodesByLabel() throws Exception | ||
{ | ||
// given | ||
int one = read.nodeLabel( "One" ); | ||
int two = read.nodeLabel( "Two" ); | ||
int three = read.nodeLabel( "Three" ); | ||
int first = read.nodeLabel( "First" ); | ||
try ( NodeLabelIndexCursor cursor = cursors.allocateNodeLabelIndexCursor(); | ||
PrimitiveLongSet uniqueIds = Primitive.longSet() ) | ||
{ | ||
// when | ||
read.nodeLabelScan( one, cursor ); | ||
|
||
// then | ||
assertFoundNodes( cursor, 1, uniqueIds ); | ||
|
||
// when | ||
read.nodeLabelScan( two, cursor ); | ||
|
||
// then | ||
assertFoundNodes( cursor, 2, uniqueIds ); | ||
|
||
// when | ||
read.nodeLabelScan( three, cursor ); | ||
|
||
// then | ||
assertFoundNodes( cursor, 3, uniqueIds ); | ||
|
||
// when | ||
uniqueIds.clear(); | ||
read.nodeLabelScan( first, cursor ); | ||
|
||
// then | ||
assertFoundNodes( cursor, 3, uniqueIds ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
community/kernel/src/main/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexProgressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.kernel.impl.newapi; | ||
|
||
import org.neo4j.collection.primitive.PrimitiveLongIterator; | ||
import org.neo4j.graphdb.Resource; | ||
|
||
class NodeLabelIndexProgressor implements IndexCursorProgressor | ||
{ | ||
private final PrimitiveLongIterator iterator; | ||
private final NodeLabelCursor target; | ||
|
||
NodeLabelIndexProgressor( PrimitiveLongIterator iterator, NodeLabelCursor target ) | ||
{ | ||
this.iterator = iterator; | ||
this.target = target; | ||
} | ||
|
||
@Override | ||
public boolean next() | ||
{ | ||
while ( iterator.hasNext() ) | ||
{ | ||
if ( target.node( iterator.next(), null ) ) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
if ( iterator instanceof Resource ) | ||
{ | ||
((Resource) iterator).close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
community/kernel/src/test/java/org/neo4j/kernel/impl/newapi/NodeLabelIndexCursorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.kernel.impl.newapi; | ||
|
||
import org.neo4j.internal.kernel.api.NodeLabelIndexCursorTestBase; | ||
|
||
public class NodeLabelIndexCursorTest extends NodeLabelIndexCursorTestBase<ReadTestSupport> | ||
{ | ||
@Override | ||
public ReadTestSupport newTestSupport() | ||
{ | ||
return new ReadTestSupport(); | ||
} | ||
} |