Skip to content

Commit

Permalink
Minor fixes, typos etc from review
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYtterbrink committed Feb 14, 2018
1 parent 9256945 commit 32381ec
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 44 deletions.
Expand Up @@ -877,7 +877,9 @@ public PrimitiveLongResourceIterator indexQuery( KernelStatement state, IndexDes
case rangeGeometric:
assertSinglePredicate( predicates );
IndexQuery.GeometryRangePredicate geomPred = (IndexQuery.GeometryRangePredicate) firstPredicate;
return filterIndexStateChangesForRangeSeekByGeometry( state, index, geomPred, exactMatches );
return filterIndexStateChangesForRangeSeekByGeometry(
state, index, geomPred.from(), geomPred.fromInclusive(), geomPred.to(),
geomPred.toInclusive(), exactMatches );

case rangeString:
{
Expand Down Expand Up @@ -989,26 +991,25 @@ private PrimitiveLongResourceIterator filterIndexStateChangesForRangeSeekByNumbe
return nodes.augmentWithRemovals( labelPropertyChangesForNumber.augment( nodeIds ) );
}
return nodeIds;

}

private PrimitiveLongResourceIterator filterIndexStateChangesForRangeSeekByGeometry( KernelStatement state,
IndexDescriptor index,
IndexQuery.GeometryRangePredicate geometryRangePredicate,
PointValue lower, boolean includeLower,
PointValue upper, boolean includeUpper,
PrimitiveLongResourceIterator nodeIds )
{
if ( state.hasTxStateWithChanges() )
{
TransactionState txState = state.txState();
PrimitiveLongReadableDiffSets labelPropertyChangesForGeometry =
txState.indexUpdatesForRangeSeekByGeometry( index, geometryRangePredicate );
txState.indexUpdatesForRangeSeekByGeometry( index, lower, includeLower, upper, includeUpper );
ReadableDiffSets<Long> nodes = txState.addedAndRemovedNodes();

// Apply to actual index lookup
return nodes.augmentWithRemovals( labelPropertyChangesForGeometry.augment( nodeIds ) );
}
return nodeIds;

}

private PrimitiveLongResourceIterator filterIndexStateChangesForRangeSeekByString( KernelStatement state,
Expand All @@ -1028,7 +1029,6 @@ private PrimitiveLongResourceIterator filterIndexStateChangesForRangeSeekByStrin
return nodes.augmentWithRemovals( labelPropertyChangesForString.augment( nodeIds ) );
}
return nodeIds;

}

private PrimitiveLongResourceIterator filterIndexStateChangesForRangeSeekByPrefix( KernelStatement state,
Expand Down
Expand Up @@ -1014,16 +1014,6 @@ public PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByNumber( IndexDesc
return EmptyPrimitiveLongReadableDiffSets.INSTANCE;
}

if ( geometryRangePredicate.from() == null && geometryRangePredicate.to() == null )
{
throw new IllegalArgumentException( "Cannot access TxState with invalid GeometryRangePredicate" );
}

PointValue lower = geometryRangePredicate.from();
PointValue upper = geometryRangePredicate.to();
boolean includeLower = geometryRangePredicate.fromInclusive();
boolean includeUpper = geometryRangePredicate.toInclusive();

ValueTuple selectedLower;
boolean selectedIncludeLower;

Expand Down Expand Up @@ -1057,14 +1047,20 @@ public PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByNumber( IndexDesc

@Override
public PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByGeometry( IndexDescriptor descriptor,
IndexQuery.GeometryRangePredicate geometryRangePredicate )
PointValue lower, boolean includeLower,
PointValue upper, boolean includeUpper )
{
TreeMap<ValueTuple, PrimitiveLongDiffSets> sortedUpdates = getSortedIndexUpdates( descriptor.schema() );
if ( sortedUpdates == null )
{
return EmptyPrimitiveLongReadableDiffSets.INSTANCE;
}

if ( lower == null && upper == null )
{
throw new IllegalArgumentException( "Cannot access TxState with invalid GeometryRangePredicate" );
}

ValueTuple selectedLower;
boolean selectedIncludeLower;

Expand Down
Expand Up @@ -72,7 +72,8 @@ public interface Factory
private SpaceFillingCurve curve;

/**
* Create a representation of a spatial index for a specific coordinate reference system. This constructure should be used for first time creation.
* Create a representation of a spatial index for a specific coordinate reference system.
* This constructor should be used for first time creation.
*/
public SpatialKnownIndex( IndexDirectoryStructure directoryStructure, CoordinateReferenceSystem crs, long indexId, PageCache pageCache,
FileSystemAbstraction fs, SchemaIndexProvider.Monitor monitor, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector )
Expand All @@ -87,7 +88,8 @@ public SpatialKnownIndex( IndexDirectoryStructure directoryStructure, Coordinate
// Depends on crs
SchemaIndexProvider.Descriptor crsDescriptor =
new SchemaIndexProvider.Descriptor( Integer.toString( crs.getTable().getTableId() ), Integer.toString( crs.getCode() ) );
IndexDirectoryStructure indexDir = IndexDirectoryStructure.directoriesBySubProvider( directoryStructure ).forProvider( crsDescriptor );
IndexDirectoryStructure indexDir =
IndexDirectoryStructure.directoriesBySubProvider( directoryStructure ).forProvider( crsDescriptor );
indexFile = new File( indexDir.directoryForIndex( indexId ), indexFileName( indexId ) );
curve = new HilbertSpaceFillingCurve2D( envelopeFromCRS( crs ), 8 );
}
Expand Down Expand Up @@ -119,7 +121,7 @@ public boolean indexExists()
return fs.fileExists( indexFile );
}

public String readPopupationFailure() throws IOException
public String readPopulationFailure() throws IOException
{
NativeSchemaIndexHeaderReader headerReader = new NativeSchemaIndexHeaderReader();
GBPTree.readHeader( pageCache, indexFile, new SpatialFusionSchemaIndexProvider.ReadOnlyMetaNumberLayout(), headerReader );
Expand Down
Expand Up @@ -25,14 +25,14 @@
import org.neo4j.values.storable.CoordinateReferenceSystem;

/**
* {@link Layout} for numbers where numbers doesn't need to be unique.
* {@link Layout} for PointValues where they don't need to be unique.
*/
public abstract class SpatialLayout extends Layout.Adapter<SpatialSchemaKey,NativeSchemaValue>
abstract class SpatialLayout extends Layout.Adapter<SpatialSchemaKey,NativeSchemaValue>
{
private SpaceFillingCurve curve;
CoordinateReferenceSystem crs;
SpaceFillingCurve curve;

public SpatialLayout( CoordinateReferenceSystem crs, SpaceFillingCurve curve )
SpatialLayout( CoordinateReferenceSystem crs, SpaceFillingCurve curve )
{
this.crs = crs;
this.curve = curve;
Expand All @@ -50,8 +50,7 @@ public SpatialSchemaKey newKey()
}

@Override
public SpatialSchemaKey copyKey( SpatialSchemaKey key,
SpatialSchemaKey into )
public SpatialSchemaKey copyKey( SpatialSchemaKey key, SpatialSchemaKey into )
{
into.rawValueBits = key.rawValueBits;
into.setEntityId( key.getEntityId() );
Expand Down
Expand Up @@ -23,14 +23,17 @@
import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.values.storable.CoordinateReferenceSystem;

/**
* {@link Layout} for PointValues where they don't need to be unique.
*/
public class SpatialLayoutNonUnique extends SpatialLayout
{
private static final String IDENTIFIER_NAME = "NUNI";
private static final String IDENTIFIER_NAME = "NUPI";
public static final int MAJOR_VERSION = 0;
public static final int MINOR_VERSION = 1;
public static long IDENTIFIER = Layout.namedIdentifier( IDENTIFIER_NAME, NativeSchemaValue.SIZE );

public SpatialLayoutNonUnique( CoordinateReferenceSystem crs, SpaceFillingCurve curve )
SpatialLayoutNonUnique( CoordinateReferenceSystem crs, SpaceFillingCurve curve )
{
super( crs, curve );
}
Expand Down
Expand Up @@ -24,16 +24,16 @@
import org.neo4j.values.storable.CoordinateReferenceSystem;

/**
* {@link Layout} for numbers where numbers need to be unique.
* {@link Layout} for PointValues where they don't need to be unique.
*/
public class SpatialLayoutUnique extends SpatialLayout
{
private static final String IDENTIFIER_NAME = "UNI";
private static final String IDENTIFIER_NAME = "UPI";
public static final int MAJOR_VERSION = 0;
public static final int MINOR_VERSION = 1;
public static long IDENTIFIER = Layout.namedIdentifier( IDENTIFIER_NAME, NativeSchemaValue.SIZE );

public SpatialLayoutUnique( CoordinateReferenceSystem crs, SpaceFillingCurve curve )
SpatialLayoutUnique( CoordinateReferenceSystem crs, SpaceFillingCurve curve )
{
super( crs, curve );
}
Expand Down
Expand Up @@ -76,6 +76,7 @@ void initializeRangeForQuery( KEY treeKeyFrom, KEY treeKeyTo, IndexQuery[] predi
throw new UnsupportedOperationException( "Cannot initialize 1D range in multidimensional spatial index reader" );
}

@Override
public void query( IndexProgressor.NodeValueClient cursor, IndexOrder indexOrder, IndexQuery... predicates )
{
validateQuery( indexOrder, predicates );
Expand Down
Expand Up @@ -33,7 +33,6 @@
/**
* Includes value and entity id (to be able to handle non-unique values).
* A value can be any {@link PointValue} and is represented as a {@code long} to store the 1D mapped version
* and a type describing the geomtry type and number of dimensions.
*/
class SpatialSchemaKey implements NativeSchemaKey
{
Expand Down Expand Up @@ -81,7 +80,7 @@ public void setEntityId( long entityId )
@Override
public void from( long entityId, Value... values )
{
extractRawBitsAndType( assertValidValue( values ) );
extractRawBits( assertValidValue( values ) );
this.entityId = entityId;
entityIdIsSpecialTieBreaker = false;
}
Expand All @@ -108,7 +107,7 @@ public void initAsLowest()
//TODO: Get dimension
double[] limit = new double[2];
Arrays.fill(limit, Double.NEGATIVE_INFINITY);
writePoint( crs, limit );
writePoint( limit );
entityId = Long.MIN_VALUE;
entityIdIsSpecialTieBreaker = true;
}
Expand All @@ -119,7 +118,7 @@ public void initAsHighest()
//TODO: Get dimension
// These coords will generate the largest value on the spacial curve
double[] limit = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY};
writePoint( crs, limit );
writePoint( limit );
entityId = Long.MAX_VALUE;
entityIdIsSpecialTieBreaker = true;
}
Expand Down Expand Up @@ -160,15 +159,15 @@ private PointValue assertValidValue( Value... values )
return (PointValue) values[0];
}

private void extractRawBitsAndType( PointValue value )
private void extractRawBits( PointValue value )
{
writePoint( value.getCoordinateReferenceSystem(), value.coordinate() );
writePoint( value.coordinate() );
}

/**
* Extracts raw bits and type from a {@link PointValue} and store as state of this {@link SpatialSchemaKey} instance.
* Extracts raw bits from a {@link PointValue} and store as state of this {@link SpatialSchemaKey} instance.
*/
private void writePoint( CoordinateReferenceSystem crs, double[] coordinate )
private void writePoint( double[] coordinate )
{
rawValueBits = curve.derivedValueFor( coordinate );
}
Expand Down
Expand Up @@ -105,7 +105,7 @@ public String getPopulationFailure( long indexId ) throws IllegalStateException
// We find the first failed index failure message
for ( SpatialKnownIndex index : indexesFor( indexId ).values() )
{
String indexFailure = index.readPopupationFailure();
String indexFailure = index.readPopulationFailure();
if ( indexFailure != null )
{
return indexFailure;
Expand Down
Expand Up @@ -262,7 +262,9 @@ private void geometricRangeQuery( IndexDescriptor descriptor, IndexQuery.Geometr
{
if ( read.hasTxStateWithChanges() )
{
changes = read.txState().indexUpdatesForRangeSeekByGeometry( descriptor, predicate );
changes = read.txState().indexUpdatesForRangeSeekByGeometry(
descriptor, predicate.from(), predicate.fromInclusive(), predicate.to(),
predicate.toInclusive() );
added = changes.augment( emptyIterator() );
}
}
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.neo4j.storageengine.api.PropertyItem;
import org.neo4j.storageengine.api.RelationshipItem;
import org.neo4j.storageengine.api.StorageProperty;
import org.neo4j.values.storable.PointValue;
import org.neo4j.values.storable.ValueTuple;

/**
Expand Down Expand Up @@ -145,7 +146,8 @@ PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByNumber( IndexDescriptor
Number upper, boolean includeUpper );

PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByGeometry( IndexDescriptor index,
IndexQuery.GeometryRangePredicate geometryRangePredicate );
PointValue lower, boolean includeLower,
PointValue upper, boolean includeUpper );

PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByString( IndexDescriptor index,
String lower, boolean includeLower,
Expand Down
Expand Up @@ -77,7 +77,7 @@ IndexQuery rangeQuery( Number from, boolean fromInclusive, Number to, boolean to
@Override
Value asValue( Number value )
{
// multiply value with 5 to make sure the points aren't too close together, avoiding false positives that will be filtered in higher level later
// multiply value to make sure the points aren't too close together, avoiding false positives that will be filtered in higher level later
return Values.pointValue( CoordinateReferenceSystem.WGS84, 3 * value.doubleValue(), 3 * value.doubleValue() );
}

Expand Down
Expand Up @@ -99,7 +99,7 @@ public void getPopulationFailureMustThrowIfNoFailure() throws Exception
// ... no failure
for ( SpatialKnownIndex index : indexMap.values() )
{
when( index.readPopupationFailure() ).thenReturn( null );
when( index.readPopulationFailure() ).thenReturn( null );
}
// then
try
Expand Down

0 comments on commit 32381ec

Please sign in to comment.