Skip to content

Commit

Permalink
Fixes single-key read issues introduced in previous composite work
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint authored and burqen committed Jul 27, 2018
1 parent da80087 commit ddea2af
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public PrimitiveLongResourceIterator query( IndexQuery... predicates )
KEY treeKeyFrom = layout.newKey();
KEY treeKeyTo = layout.newKey();

treeKeyFrom.initialize( Long.MIN_VALUE );
treeKeyTo.initialize( Long.MAX_VALUE );

boolean needFilter = initializeRangeForQuery( treeKeyFrom, treeKeyTo, predicates );
if ( isBackwardsSeek( treeKeyFrom, treeKeyTo ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Value[] asValues()
return array( asValue() );
}

void from( long entityId, Value value )
void from( Value value )
{
assertCorrectType( value );
value.writeTo( this );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ boolean initializeRangeForQuery( NumberIndexKey treeKeyFrom, NumberIndexKey tree
break;
case exact:
ExactPredicate exactPredicate = (ExactPredicate) predicate;
treeKeyFrom.from( Long.MIN_VALUE, exactPredicate.value() );
treeKeyTo.from( Long.MAX_VALUE, exactPredicate.value() );
treeKeyFrom.from( exactPredicate.value() );
treeKeyTo.from( exactPredicate.value() );
break;
case range:
RangePredicate<?> rangePredicate = (RangePredicate<?>) predicate;
Expand All @@ -85,7 +85,8 @@ private void initToForRange( RangePredicate<?> rangePredicate, NumberIndexKey tr
}
else
{
treeKeyTo.from( rangePredicate.toInclusive() ? Long.MAX_VALUE : Long.MIN_VALUE, toValue );
treeKeyTo.initialize( rangePredicate.toInclusive() ? Long.MAX_VALUE : Long.MIN_VALUE );
treeKeyTo.from( toValue );
treeKeyTo.setCompareId( true );
}
}
Expand All @@ -99,7 +100,8 @@ private void initFromForRange( RangePredicate<?> rangePredicate, NumberIndexKey
}
else
{
treeKeyFrom.from( rangePredicate.fromInclusive() ? Long.MIN_VALUE : Long.MAX_VALUE, fromValue );
treeKeyFrom.initialize( rangePredicate.fromInclusive() ? Long.MIN_VALUE : Long.MAX_VALUE );
treeKeyFrom.from( fromValue );
treeKeyFrom.setCompareId( true );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,18 @@ public void query( IndexProgressor.NodeValueClient cursor, IndexOrder indexOrder
{
validateQuery( indexOrder, predicates );
IndexQuery predicate = predicates[0];

SpatialIndexKey treeKeyFrom = layout.newKey();
SpatialIndexKey treeKeyTo = layout.newKey();
initializeKeys( treeKeyFrom, treeKeyTo );

switch ( predicate.type() )
{
case exists:
startSeekForExists( cursor, predicate );
startSeekForExists( treeKeyFrom, treeKeyTo, cursor, predicate );
break;
case exact:
startSeekForExact( cursor, ((ExactPredicate) predicate).value(), predicate );
startSeekForExact( treeKeyFrom, treeKeyTo, cursor, ((ExactPredicate) predicate).value(), predicate );
break;
case range:
GeometryRangePredicate rangePredicate = (GeometryRangePredicate) predicate;
Expand All @@ -107,21 +112,17 @@ public void query( IndexProgressor.NodeValueClient cursor, IndexOrder indexOrder
}
}

private void startSeekForExists( IndexProgressor.NodeValueClient client, IndexQuery... predicates )
private void startSeekForExists( SpatialIndexKey treeKeyFrom, SpatialIndexKey treeKeyTo, IndexProgressor.NodeValueClient client, IndexQuery... predicates )
{
SpatialIndexKey treeKeyFrom = layout.newKey();
SpatialIndexKey treeKeyTo = layout.newKey();
treeKeyFrom.initValueAsLowest( ValueGroup.GEOMETRY );
treeKeyTo.initValueAsHighest( ValueGroup.GEOMETRY );
startSeekForInitializedRange( client, treeKeyFrom, treeKeyTo, predicates, false );
}

private void startSeekForExact( IndexProgressor.NodeValueClient client, Value value, IndexQuery... predicates )
private void startSeekForExact( SpatialIndexKey treeKeyFrom, SpatialIndexKey treeKeyTo, IndexProgressor.NodeValueClient client, Value value, IndexQuery... predicates )
{
SpatialIndexKey treeKeyFrom = layout.newKey();
SpatialIndexKey treeKeyTo = layout.newKey();
treeKeyFrom.from( Long.MIN_VALUE, value );
treeKeyTo.from( Long.MAX_VALUE, value );
treeKeyFrom.from( value );
treeKeyTo.from( value );
startSeekForInitializedRange( client, treeKeyFrom, treeKeyTo, predicates, false );
}

Expand All @@ -139,6 +140,7 @@ private void startSeekForRange( IndexProgressor.NodeValueClient client, Geometry
{
SpatialIndexKey treeKeyFrom = layout.newKey();
SpatialIndexKey treeKeyTo = layout.newKey();
initializeKeys( treeKeyFrom, treeKeyTo );
treeKeyFrom.fromDerivedValue( Long.MIN_VALUE, range.min );
treeKeyTo.fromDerivedValue( Long.MAX_VALUE, range.max + 1 );
RawCursor<Hit<SpatialIndexKey,VALUE>,IOException> seeker = makeIndexSeeker( treeKeyFrom, treeKeyTo );
Expand Down Expand Up @@ -183,4 +185,10 @@ public boolean hasFullValuePrecision( IndexQuery... predicates )
{
return false;
}

private void initializeKeys( SpatialIndexKey treeKeyFrom, SpatialIndexKey treeKeyTo )
{
treeKeyFrom.initialize( Long.MIN_VALUE );
treeKeyTo.initialize( Long.MAX_VALUE );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ boolean initializeRangeForQuery( StringIndexKey treeKeyFrom, StringIndexKey tree
return false;
case exact:
ExactPredicate exactPredicate = (ExactPredicate) predicate;
treeKeyFrom.from( Long.MIN_VALUE, exactPredicate.value() );
treeKeyTo.from( Long.MAX_VALUE, exactPredicate.value() );
treeKeyFrom.from( exactPredicate.value() );
treeKeyTo.from( exactPredicate.value() );
return false;
case range:
RangePredicate<?> rangePredicate = (RangePredicate<?>)predicate;
Expand Down Expand Up @@ -96,7 +96,8 @@ private void initFromForRange( RangePredicate<?> rangePredicate, StringIndexKey
}
else
{
treeKeyFrom.from( rangePredicate.fromInclusive() ? Long.MIN_VALUE : Long.MAX_VALUE, fromValue );
treeKeyFrom.initialize( rangePredicate.fromInclusive() ? Long.MIN_VALUE : Long.MAX_VALUE );
treeKeyFrom.from( fromValue );
treeKeyFrom.setCompareId( true );
}
}
Expand All @@ -110,7 +111,8 @@ private void initToForRange( RangePredicate<?> rangePredicate, StringIndexKey tr
}
else
{
treeKeyTo.from( rangePredicate.toInclusive() ? Long.MAX_VALUE : Long.MIN_VALUE, toValue );
treeKeyTo.initialize( rangePredicate.toInclusive() ? Long.MAX_VALUE : Long.MIN_VALUE );
treeKeyTo.from( toValue );
treeKeyTo.setCompareId( true );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ protected boolean initializeRangeForQuery( KEY treeKeyFrom, KEY treeKeyTo, Index

case exact:
IndexQuery.ExactPredicate exactPredicate = (IndexQuery.ExactPredicate) predicate;
treeKeyFrom.from( Long.MIN_VALUE, exactPredicate.value() );
treeKeyTo.from( Long.MAX_VALUE, exactPredicate.value() );
treeKeyFrom.from( exactPredicate.value() );
treeKeyTo.from( exactPredicate.value() );
break;

case range:
Expand All @@ -88,7 +88,8 @@ private void initFromForRange( IndexQuery.RangePredicate<?> rangePredicate, KEY
}
else
{
treeKeyFrom.from( rangePredicate.fromInclusive() ? Long.MIN_VALUE : Long.MAX_VALUE, fromValue );
treeKeyFrom.initialize( rangePredicate.fromInclusive() ? Long.MIN_VALUE : Long.MAX_VALUE );
treeKeyFrom.from( fromValue );
treeKeyFrom.setCompareId( true );
}
}
Expand All @@ -102,7 +103,8 @@ private void initToForRange( IndexQuery.RangePredicate<?> rangePredicate, KEY tr
}
else
{
treeKeyTo.from( rangePredicate.toInclusive() ? Long.MAX_VALUE : Long.MIN_VALUE, toValue );
treeKeyTo.initialize( rangePredicate.toInclusive() ? Long.MAX_VALUE : Long.MIN_VALUE );
treeKeyTo.from( toValue );
treeKeyTo.setCompareId( true );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -220,7 +219,7 @@ private List<NumberIndexKey> asNumberIndexKeys( List<Value> values )
for ( Value value : values )
{
NumberIndexKey key = new NumberIndexKey();
key.from( 0, value );
key.from( value );
numberIndexKeys.add( key );
}
return numberIndexKeys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public void close()
public Hit<StringIndexKey,NativeIndexValue> get()
{
StringIndexKey key = new StringIndexKey();
key.from( pos, stringValue( current ) );
key.initialize( pos );
key.from( stringValue( current ) );
return new SimpleHit<>( key, NativeIndexValue.INSTANCE );
}
}

0 comments on commit ddea2af

Please sign in to comment.