Skip to content

Commit

Permalink
Add SpatialIndex tests
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner authored and OliviaYtterbrink committed Feb 14, 2018
1 parent 87f63c0 commit d2e2a59
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
Expand Up @@ -35,6 +35,8 @@
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.test.rule.RandomRule;
import org.neo4j.values.storable.CoordinateReferenceSystem;
import org.neo4j.values.storable.PointValue;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.Values;

Expand Down Expand Up @@ -140,7 +142,17 @@ IndexEntryUpdate<IndexDescriptor>[] someUpdatesWithDuplicateValues()
return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) );
}

private IndexEntryUpdate<IndexDescriptor>[] generateAddUpdatesFor( Number[] values )
IndexEntryUpdate<IndexDescriptor>[] someSpatialUpdatesNoDuplicateValues()
{
return generateAddUpdatesFor( SOME_POINTS );
}

IndexEntryUpdate<IndexDescriptor>[] someSpatialUpdatesWithDuplicateValues()
{
return generateAddUpdatesFor( ArrayUtils.addAll( SOME_POINTS, SOME_POINTS ) );
}

private IndexEntryUpdate<IndexDescriptor>[] generateAddUpdatesFor( Object[] values )
{
@SuppressWarnings( "unchecked" )
IndexEntryUpdate<IndexDescriptor>[] indexEntryUpdates = new IndexEntryUpdate[values.length];
Expand All @@ -151,6 +163,14 @@ private IndexEntryUpdate<IndexDescriptor>[] generateAddUpdatesFor( Number[] valu
return indexEntryUpdates;
}

private static final PointValue[] SOME_POINTS = new PointValue[]
{
Values.pointValue( CoordinateReferenceSystem.WGS84, 12.5, 56.8 ),
Values.pointValue( CoordinateReferenceSystem.WGS84, -38.5, 36.8 ),
Values.pointValue( CoordinateReferenceSystem.WGS84, 30.0, -40.0 ),
Values.pointValue( CoordinateReferenceSystem.WGS84, -50, -25 )
};

private static final Number[] ALL_EXTREME_VALUES = new Number[]
{
Byte.MAX_VALUE,
Expand Down
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2002-2018 "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.index.schema;

import org.neo4j.gis.spatial.index.Envelope;
import org.neo4j.gis.spatial.index.curves.HilbertSpaceFillingCurve2D;
import org.neo4j.gis.spatial.index.curves.SpaceFillingCurve;
import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory;
import org.neo4j.values.storable.CoordinateReferenceSystem;
import org.neo4j.values.storable.PointValue;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.Values;

class SpatialLayoutTestUtil extends LayoutTestUtil<SpatialSchemaKey,NativeSchemaValue>
{
private CoordinateReferenceSystem crs = CoordinateReferenceSystem.WGS84;
private SpaceFillingCurve curve = new HilbertSpaceFillingCurve2D( new Envelope( -180, 180, -90, 90 ) );

SpatialLayoutTestUtil()
{
super( IndexDescriptorFactory.forLabel( 42, 666 ) );
}

@Override
Layout<SpatialSchemaKey,NativeSchemaValue> createLayout()
{
return new SpatialLayoutNonUnique( crs, curve );
}

@Override
IndexEntryUpdate<IndexDescriptor>[] someUpdates()
{
return someSpatialUpdatesWithDuplicateValues();
}

@Override
protected double fractionDuplicates()
{
return 0.1;
}

@Override
IndexQuery rangeQuery( Number from, boolean fromInclusive, Number to, boolean toInclusive )
{
return IndexQuery.range( 0, (PointValue) asValue( from ), fromInclusive, (PointValue) asValue( to ), toInclusive );
}

@Override
Value asValue( Number value )
{
return Values.pointValue( CoordinateReferenceSystem.WGS84, value.doubleValue(), value.doubleValue() );
}

// TODO fix this comparison
@Override
int compareIndexedPropertyValue( SpatialSchemaKey key1, SpatialSchemaKey key2 )
{
int typeCompare = Byte.compare( key1.type, key2.type );
if ( typeCompare == 0 )
{
return Long.compare( key1.rawValueBits, key2.rawValueBits );
}
return typeCompare;
}
}
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2002-2018 "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.index.schema;

public class SpatialNonUniqueSchemaIndexAccessorTest extends SpatialSchemaIndexAccessorTest<SpatialSchemaKey,NativeSchemaValue>
{
@Override
protected LayoutTestUtil<SpatialSchemaKey,NativeSchemaValue> createLayoutTestUtil()
{
return new SpatialLayoutTestUtil();
}
}
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2018 "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.index.schema;

import java.io.IOException;

import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig;

import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE;

public abstract class SpatialSchemaIndexAccessorTest<KEY extends SpatialSchemaKey, VALUE extends NativeSchemaValue>
extends NativeSchemaIndexAccessorTest<KEY,VALUE>
{
NativeSchemaIndexAccessor<KEY,VALUE> makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException
{
return new SpatialSchemaIndexAccessor<>( pageCache, fs, indexFile, layout, IMMEDIATE, monitor, indexDescriptor, indexId, samplingConfig );
}
}

0 comments on commit d2e2a59

Please sign in to comment.