Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With main purpose to access distinct values and counts for each value regardless of index provider. There are procedures floating around for doing this on IndexReader from provider backed by Lucene, but this doesn't work for native indexes, until now. Two points of ugliness in this commit: - A cast from Layout -> SchemaLayout in NativeSchemaIndexReader. This is done to prevent a bigger refactoring, which have already been done in 3.5. - HashBasedIndex just throws UnsupportedOperationException in its distinctValues. This is because this functionality isn't really needed for this testing index and HashBasedIndex and in-memory indexing as a whole has been removed in 3.5.
- Loading branch information
Showing
17 changed files
with
732 additions
and
44 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...rnel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeDistinctValuesProgressor.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,90 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.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.index.schema; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.util.Collection; | ||
|
||
import org.neo4j.cursor.RawCursor; | ||
import org.neo4j.index.internal.gbptree.Hit; | ||
|
||
public class NativeDistinctValuesProgressor<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> extends NativeIndexProgressor<KEY,VALUE> | ||
{ | ||
private final SchemaLayout<KEY> layout; | ||
private final KEY prev; | ||
private boolean first = true; | ||
private long countForCurrentValue; | ||
private boolean last; | ||
|
||
NativeDistinctValuesProgressor( RawCursor<Hit<KEY,VALUE>,IOException> seeker, NodeValueClient client, | ||
Collection<RawCursor<Hit<KEY,VALUE>,IOException>> toRemoveFromOnClose, SchemaLayout<KEY> layout ) | ||
{ | ||
super( seeker, client, toRemoveFromOnClose ); | ||
this.layout = layout; | ||
prev = layout.newKey(); | ||
} | ||
|
||
@Override | ||
public boolean next() | ||
{ | ||
try | ||
{ | ||
while ( seeker.next() ) | ||
{ | ||
KEY key = seeker.get().key(); | ||
try | ||
{ | ||
if ( first ) | ||
{ | ||
first = false; | ||
countForCurrentValue = 1; | ||
} | ||
else if ( layout.compareValue( prev, key ) == 0 ) | ||
{ | ||
// same as previous | ||
countForCurrentValue++; | ||
} | ||
else | ||
{ | ||
// different from previous | ||
boolean accepted = client.acceptNode( countForCurrentValue, extractValues( prev ) ); | ||
countForCurrentValue = 1; | ||
if ( accepted ) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
finally | ||
{ | ||
layout.copyKey( key, prev ); | ||
} | ||
} | ||
boolean finalResult = !first && !last && client.acceptNode( countForCurrentValue, extractValues( prev ) ); | ||
last = true; | ||
return finalResult; | ||
} | ||
catch ( IOException e ) | ||
{ | ||
throw new UncheckedIOException( e ); | ||
} | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeIndexProgressor.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,68 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.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.index.schema; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.util.Collection; | ||
|
||
import org.neo4j.cursor.RawCursor; | ||
import org.neo4j.index.internal.gbptree.Hit; | ||
import org.neo4j.storageengine.api.schema.IndexProgressor; | ||
import org.neo4j.values.storable.Value; | ||
|
||
abstract class NativeIndexProgressor<KEY extends NativeSchemaKey<KEY>, VALUE extends NativeSchemaValue> implements IndexProgressor | ||
{ | ||
final RawCursor<Hit<KEY,VALUE>,IOException> seeker; | ||
final NodeValueClient client; | ||
private final Collection<RawCursor<Hit<KEY,VALUE>,IOException>> toRemoveFromOnClose; | ||
private boolean closed; | ||
|
||
NativeIndexProgressor( RawCursor<Hit<KEY,VALUE>,IOException> seeker, NodeValueClient client, | ||
Collection<RawCursor<Hit<KEY,VALUE>,IOException>> toRemoveFromOnClose ) | ||
{ | ||
this.seeker = seeker; | ||
this.client = client; | ||
this.toRemoveFromOnClose = toRemoveFromOnClose; | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
if ( !closed ) | ||
{ | ||
closed = true; | ||
try | ||
{ | ||
seeker.close(); | ||
toRemoveFromOnClose.remove( seeker ); | ||
} | ||
catch ( IOException e ) | ||
{ | ||
throw new UncheckedIOException( e ); | ||
} | ||
} | ||
} | ||
|
||
Value[] extractValues( KEY key ) | ||
{ | ||
return client.needsValues() ? new Value[]{ key.asValue()} : null; | ||
} | ||
} |
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
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
Oops, something went wrong.