Skip to content

Commit

Permalink
Make sure min/max range based on same CRS
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner authored and OliviaYtterbrink committed Feb 14, 2018
1 parent 2a920db commit 87f63c0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,7 @@ public PrimitiveLongResourceIterator indexQuery( KernelStatement state, IndexDes
case rangeGeometric:
assertSinglePredicate( predicates );
IndexQuery.GeometryRangePredicate geomPred = (IndexQuery.GeometryRangePredicate) firstPredicate;
return filterIndexStateChangesForRangeSeekByGeometry( state, index, geomPred.from(),
geomPred.fromInclusive(), geomPred.to(), geomPred.toInclusive(), exactMatches );
return filterIndexStateChangesForRangeSeekByGeometry( state, index, geomPred, exactMatches );

case rangeString:
{
Expand Down Expand Up @@ -995,15 +994,14 @@ private PrimitiveLongResourceIterator filterIndexStateChangesForRangeSeekByNumbe

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

// Apply to actual index lookup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptorPredicates;
import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor;
import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException;
import org.neo4j.kernel.api.schema.constaints.IndexBackedConstraintDescriptor;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
Expand Down Expand Up @@ -1013,6 +1014,16 @@ 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 @@ -1056,8 +1067,7 @@ public PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByNumber( IndexDesc

@Override
public PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByGeometry( IndexDescriptor descriptor,
PointValue lower, boolean includeLower,
PointValue upper, boolean includeUpper )
IndexQuery.GeometryRangePredicate geometryRangePredicate )
{
TreeMap<ValueTuple, PrimitiveLongDiffSets> sortedUpdates = getSortedIndexUpdates( descriptor.schema() );
if ( sortedUpdates == null )
Expand All @@ -1073,8 +1083,7 @@ public PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByGeometry( IndexDe

if ( lower == null )
{
//TODO define min and max with correct CRS from lower or upper
selectedLower = ValueTuple.of( Values.MIN_POINT );
selectedLower = ValueTuple.of( Values.minPointValue( upper ) );
selectedIncludeLower = true;
}
else
Expand All @@ -1085,7 +1094,7 @@ public PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByGeometry( IndexDe

if ( upper == null )
{
selectedUpper = ValueTuple.of( Values.MAX_POINT );
selectedUpper = ValueTuple.of( Values.maxPointValue( lower ) );
selectedIncludeUpper = true;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.collection.primitive.PrimitiveLongResourceIterator;
import org.neo4j.cursor.Cursor;
import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.constraints.ConstraintDescriptor;
Expand All @@ -37,7 +38,6 @@
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,8 +145,7 @@ PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByNumber( IndexDescriptor
Number upper, boolean includeUpper );

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

PrimitiveLongReadableDiffSets indexUpdatesForRangeSeekByString( IndexDescriptor index,
String lower, boolean includeLower,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ public final class Values
{
public static final Value MIN_NUMBER = Values.doubleValue( Double.NEGATIVE_INFINITY );
public static final Value MAX_NUMBER = Values.doubleValue( Double.NaN );
// min point and max point are defined to catch all points by using different crs
public static final Value MIN_POINT = Values.pointValue( CoordinateReferenceSystem.WGS84, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY );
public static final Value MAX_POINT = Values.pointValue( CoordinateReferenceSystem.Cartesian, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY );
public static final Value ZERO_FLOAT = Values.doubleValue( 0.0 );
public static final Value ZERO_INT = Values.longValue( 0 );
public static final Value MIN_STRING = StringValue.EMTPY;
Expand Down Expand Up @@ -317,6 +314,20 @@ public static PointValue point( Point point )
return new PointValue( crs( point.getCRS() ), coords );
}

public static PointValue minPointValue( PointValue reference )
{
double[] coordinates = new double[reference.coordinate().length];
Arrays.fill( coordinates, Double.NEGATIVE_INFINITY );
return pointValue( reference.getCoordinateReferenceSystem(), coordinates );
}

public static PointValue maxPointValue( PointValue reference )
{
double[] coordinates = new double[reference.coordinate().length];
Arrays.fill( coordinates, Double.POSITIVE_INFINITY);
return pointValue( reference.getCoordinateReferenceSystem(), coordinates );
}

public static PointArray pointArray( Point[] points )
{
PointValue[] values = new PointValue[points.length];
Expand Down

0 comments on commit 87f63c0

Please sign in to comment.