Skip to content

Commit

Permalink
Take fractionDuplicate as constructor argument instead of subclasses …
Browse files Browse the repository at this point in the history
…overriding method
  • Loading branch information
burqen committed Oct 3, 2018
1 parent d392cdd commit 9ae7f1b
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class DateTimeValueCreatorUtil extends ValueCreatorUtil<ZonedDateTimeIndexKey,NativeIndexValue>
{
DateTimeValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor )
DateTimeValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor, double fractionDuplicates )
{
super( schemaIndexDescriptor, RandomValues.typesOfGroup( ValueGroup.ZONED_DATE_TIME ) );
super( schemaIndexDescriptor, RandomValues.typesOfGroup( ValueGroup.ZONED_DATE_TIME ), fractionDuplicates );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class DateValueCreatorUtil extends ValueCreatorUtil<DateIndexKey,NativeIndexValue>
{
DateValueCreatorUtil( StoreIndexDescriptor indexDescriptor )
DateValueCreatorUtil( StoreIndexDescriptor indexDescriptor, double fractionDuplicates )
{
super( indexDescriptor, RandomValues.typesOfGroup( ValueGroup.DATE ) );
super( indexDescriptor, RandomValues.typesOfGroup( ValueGroup.DATE ), fractionDuplicates );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class DurationValueCreatorUtil extends ValueCreatorUtil<DurationIndexKey,NativeIndexValue>
{
DurationValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor )
DurationValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor, double fractionDuplicates )
{
super( schemaIndexDescriptor, RandomValues.typesOfGroup( ValueGroup.DURATION ) );
super( schemaIndexDescriptor, RandomValues.typesOfGroup( ValueGroup.DURATION ), fractionDuplicates );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,13 @@
*/
package org.neo4j.kernel.impl.index.schema;

import java.util.HashMap;

import org.neo4j.gis.spatial.index.curves.StandardConfiguration;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.index.schema.config.ConfiguredSpaceFillingCurveSettingsCache;
import org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettingsCache;
import org.neo4j.storageengine.api.schema.StoreIndexDescriptor;
import org.neo4j.values.storable.RandomValues;

class GenericValueCreatorUtil extends ValueCreatorUtil<CompositeGenericKey,NativeIndexValue>
{
private IndexSpecificSpaceFillingCurveSettingsCache spaceFillingCurveSettings =
new IndexSpecificSpaceFillingCurveSettingsCache( new ConfiguredSpaceFillingCurveSettingsCache( Config.defaults() ), new HashMap<>() );
StandardConfiguration configuration = new StandardConfiguration();

GenericValueCreatorUtil( StoreIndexDescriptor indexDescriptor )
GenericValueCreatorUtil( StoreIndexDescriptor indexDescriptor, double fractionDuplicates )
{
super( indexDescriptor, RandomValues.Type.values() );
super( indexDescriptor, RandomValues.Type.values(), fractionDuplicates );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class LocalDateTimeValueCreatorUtil extends ValueCreatorUtil<LocalDateTimeIndexKey,NativeIndexValue>
{
LocalDateTimeValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor )
LocalDateTimeValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor, double fractionDuplicates )
{
super( schemaIndexDescriptor, RandomValues.typesOfGroup( ValueGroup.LOCAL_DATE_TIME ) );
super( schemaIndexDescriptor, RandomValues.typesOfGroup( ValueGroup.LOCAL_DATE_TIME ), fractionDuplicates );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class LocalTimeValueCreatorUtil extends ValueCreatorUtil<LocalTimeIndexKey,NativeIndexValue>
{
LocalTimeValueCreatorUtil( StoreIndexDescriptor indexDescriptor )
LocalTimeValueCreatorUtil( StoreIndexDescriptor indexDescriptor, double fractionDuplicates )
{
super( indexDescriptor, RandomValues.typesOfGroup( ValueGroup.LOCAL_TIME ) );
super( indexDescriptor, RandomValues.typesOfGroup( ValueGroup.LOCAL_TIME ), fractionDuplicates );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ NativeIndexAccessor<KEY,VALUE> makeAccessor() throws IOException
@Override
ValueCreatorUtil<KEY,VALUE> createValueCreatorUtil()
{
return valueCreatorUtilFactory.create( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ) );
return valueCreatorUtilFactory.create( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ), ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ NativeIndexPopulator<KEY,VALUE> createPopulator() throws IOException
@Override
ValueCreatorUtil<KEY,VALUE> createValueCreatorUtil()
{
return new UniqueValueCreatorUtil<>( valueCreatorUtilFactory.create( uniqueDescriptor ) );
return valueCreatorUtilFactory.create( uniqueDescriptor, ValueCreatorUtil.FRACTION_DUPLICATE_UNIQUE );
}

@Override
Expand Down Expand Up @@ -204,7 +204,7 @@ NativeIndexPopulator<KEY,VALUE> createPopulator() throws IOException
@Override
ValueCreatorUtil<KEY,VALUE> createValueCreatorUtil()
{
return valueCreatorUtilFactory.create( nonUniqueDescriptor );
return valueCreatorUtilFactory.create( nonUniqueDescriptor, ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void buildTree( Value[] values ) throws IOException
@Override
protected ValueCreatorUtil<NumberIndexKey,NativeIndexValue> createValueCreatorUtil()
{
return new NumberValueCreatorUtil( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ) );
return new NumberValueCreatorUtil( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ), ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,8 @@

class NumberValueCreatorUtil extends ValueCreatorUtil<NumberIndexKey,NativeIndexValue>
{
NumberValueCreatorUtil( StoreIndexDescriptor indexDescriptor )
NumberValueCreatorUtil( StoreIndexDescriptor indexDescriptor, double fractionDuplicates )
{
super( indexDescriptor, RandomValues.typesOfGroup( ValueGroup.NUMBER ) );
}

@Override
int compareIndexedPropertyValue( NumberIndexKey key1, NumberIndexKey key2 )
{
int typeCompare = Byte.compare( key1.type, key2.type );
if ( typeCompare == 0 )
{
return Long.compare( key1.rawValueBits, key2.rawValueBits );
}
return typeCompare;
super( indexDescriptor, RandomValues.typesOfGroup( ValueGroup.NUMBER ), fractionDuplicates );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ NativeIndexAccessor<SpatialIndexKey,NativeIndexValue> makeAccessor() throws IOEx
@Override
protected ValueCreatorUtil<SpatialIndexKey,NativeIndexValue> createValueCreatorUtil()
{
return new SpatialValueCreatorUtil( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ) );
return new SpatialValueCreatorUtil( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ), ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private IndexSamplingConfig samplingConfig()
private SpatialValueCreatorUtil createLayoutTestUtil( long indexId, int labelId )
{
StoreIndexDescriptor descriptor = TestIndexDescriptorFactory.forLabel( labelId, 666 ).withId( indexId );
return new SpatialValueCreatorUtil( descriptor );
return new SpatialValueCreatorUtil( descriptor, ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE );
}

private SpatialIndexProvider newSpatialIndexProvider( Config config )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public File getIndexFile()
@Override
protected ValueCreatorUtil<SpatialIndexKey,NativeIndexValue> createValueCreatorUtil()
{
return new SpatialValueCreatorUtil( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ) );
return new SpatialValueCreatorUtil( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ), ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public File getIndexFile()
@Override
protected ValueCreatorUtil<SpatialIndexKey,NativeIndexValue> createValueCreatorUtil()
{
return new UniqueValueCreatorUtil<>( new SpatialValueCreatorUtil( TestIndexDescriptorFactory.uniqueForLabel( 42, 666 ).withId( 0 ) ) );
return new SpatialValueCreatorUtil( TestIndexDescriptorFactory.uniqueForLabel( 42, 666 ).withId( 0 ), ValueCreatorUtil.FRACTION_DUPLICATE_UNIQUE );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,19 @@
*/
package org.neo4j.kernel.impl.index.schema;

import org.apache.commons.lang3.ArrayUtils;

import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.storageengine.api.schema.IndexDescriptor;
import org.neo4j.storageengine.api.schema.StoreIndexDescriptor;
import org.neo4j.test.rule.RandomRule;
import org.neo4j.values.storable.PointValue;
import org.neo4j.values.storable.RandomValues;
import org.neo4j.values.storable.Values;

import static org.neo4j.values.storable.CoordinateReferenceSystem.WGS84;

class SpatialValueCreatorUtil extends ValueCreatorUtil<SpatialIndexKey,NativeIndexValue>
{
private static final PointValue[] ALL_EXTREME_VALUES = new PointValue[]
{
Values.pointValue( WGS84, -180, -90 ),
Values.pointValue( WGS84, -180, 90 ),
Values.pointValue( WGS84, -1, -1 ),
Values.pointValue( WGS84, 0, 0 ),
Values.pointValue( WGS84, 180, -90 ),
Values.pointValue( WGS84, 180, 90 ),
};

SpatialValueCreatorUtil( StoreIndexDescriptor descriptor )
{
super( descriptor, new RandomValues.Type[]{RandomValues.Type.GEOGRAPHIC_POINT} );
}

@Override
IndexEntryUpdate<IndexDescriptor>[] someUpdates( RandomRule randomRule )
SpatialValueCreatorUtil( StoreIndexDescriptor descriptor, double fractionDuplicates )
{
return someUpdatesWithDuplicateValues( randomRule );
super( descriptor, new RandomValues.Type[]{RandomValues.Type.GEOGRAPHIC_POINT}, fractionDuplicates );
}

@Override
int compareIndexedPropertyValue( SpatialIndexKey key1, SpatialIndexKey key2 )
{
return Long.compare( key1.rawValueBits, key2.rawValueBits );
}

@Override
IndexEntryUpdate<IndexDescriptor>[] someUpdatesWithDuplicateValues( RandomRule randomRule )
{
return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

class StringValueCreatorUtil extends ValueCreatorUtil<StringIndexKey,NativeIndexValue>
{
StringValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor )
StringValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor, double fractionDuplicates )
{
super( schemaIndexDescriptor, RandomValues.typesOfGroup( ValueGroup.TEXT ) );
super( schemaIndexDescriptor, RandomValues.typesOfGroup( ValueGroup.TEXT ), fractionDuplicates );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

public class TimeValueCreatorUtil extends ValueCreatorUtil<ZonedTimeIndexKey,NativeIndexValue>
{
static long MAX_NANOS_PER_DAY = 86399999999999L;

TimeValueCreatorUtil( StoreIndexDescriptor indexDescriptor )
TimeValueCreatorUtil( StoreIndexDescriptor indexDescriptor, double fractionDuplicates )
{
super( indexDescriptor, RandomValues.typesOfGroup( ValueGroup.ZONED_TIME ) );
super( indexDescriptor, RandomValues.typesOfGroup( ValueGroup.ZONED_TIME ), fractionDuplicates );
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,26 @@

abstract class ValueCreatorUtil<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
{
static final double FRACTION_DUPLICATE_UNIQUE = 0;
static final double FRACTION_DUPLICATE_NON_UNIQUE = 0.1;
private static final Comparator<IndexEntryUpdate<IndexDescriptor>> UPDATE_COMPARATOR = ( u1, u2 ) ->
Values.COMPARATOR.compare( u1.values()[0], u2.values()[0] );
private static final int N_VALUES = 10;

final StoreIndexDescriptor indexDescriptor;
private final RandomValues.Type[] supportedTypes;
private final double fractionDuplication;

ValueCreatorUtil( ValueCreatorUtil delegate )
{
this( delegate.indexDescriptor, delegate.supportedTypes );
this( delegate.indexDescriptor, delegate.supportedTypes, delegate.fractionDuplication );
}

ValueCreatorUtil( StoreIndexDescriptor indexDescriptor, RandomValues.Type[] supportedTypes )
ValueCreatorUtil( StoreIndexDescriptor indexDescriptor, RandomValues.Type[] supportedTypes, double fractionDuplication )
{
this.indexDescriptor = indexDescriptor;
this.supportedTypes = supportedTypes;
this.fractionDuplication = fractionDuplication;
}

int compareIndexedPropertyValue( KEY key1, KEY key2 )
Expand All @@ -71,9 +75,9 @@ RandomValues.Type[] supportedTypes()
return supportedTypes;
}

protected double fractionDuplicates()
double fractionDuplicates()
{
return 0.1;
return fractionDuplication;
}

IndexQuery rangeQuery( Value from, boolean fromInclusive, Value to, boolean toInclusive )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
@FunctionalInterface
interface ValueCreatorUtilFactory<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
{
ValueCreatorUtil<KEY,VALUE> create( StoreIndexDescriptor descriptor );
ValueCreatorUtil<KEY,VALUE> create( StoreIndexDescriptor descriptor, double fractionDuplicates );
}

0 comments on commit 9ae7f1b

Please sign in to comment.