Skip to content

Commit

Permalink
Made single value 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 73f3255 commit 6393fb3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
Expand Up @@ -93,6 +93,7 @@ public void shouldReportInitialStateAsFailedIfPopulationFailed() throws Exceptio

// WHEN
p.markAsFailed( failure );
p.close( false );

// THEN
assertEquals( FAILED, indexProvider.getInitialState( descriptor ) );
Expand Down Expand Up @@ -266,7 +267,7 @@ public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception
{
NodeValueIterator nodes = new NodeValueIterator();
reader.query( nodes, IndexOrder.NONE, IndexQuery.exact( propertyKeyId, entry.value ) );
assertEquals( asSet( entry.nodeId, entry.nodeId + offset ), PrimitiveLongCollections.toSet( nodes ) );
assertEquals( entry.value.toString(), asSet( entry.nodeId, entry.nodeId + offset ), PrimitiveLongCollections.toSet( nodes ) );
}
}
}
Expand Down
Expand Up @@ -217,9 +217,8 @@ abstract class Adapter<KEY, VALUE> implements Layout<KEY,VALUE>
@Override
public String toString()
{
return format( "%s[version:%d.%d, identifier:%d, keySize:%d, valueSize:%d, fixedSize:%b]",
getClass().getSimpleName(), majorVersion(), minorVersion(), identifier(),
keySize( null ), valueSize( null ), fixedSize() );
return format( "%s[version:%d.%d, identifier:%d, fixedSize:%b]",
getClass().getSimpleName(), majorVersion(), minorVersion(), identifier(), fixedSize() );
}

@Override
Expand Down
Expand Up @@ -20,6 +20,8 @@

import static org.neo4j.kernel.impl.index.schema.DurationIndexKey.AVG_DAY_SECONDS;
import static org.neo4j.kernel.impl.index.schema.DurationIndexKey.AVG_MONTH_SECONDS;
import static org.neo4j.kernel.impl.index.schema.GenericLayout.HIGHEST_TYPE_BY_VALUE_GROUP;
import static org.neo4j.kernel.impl.index.schema.GenericLayout.LOWEST_TYPE_BY_VALUE_GROUP;
import static org.neo4j.kernel.impl.index.schema.StringIndexKey.unsignedByteArrayCompare;
import static org.neo4j.values.storable.Values.NO_VALUE;

Expand Down Expand Up @@ -100,7 +102,7 @@ Value asValue()
@Override
void initValueAsLowest( ValueGroup valueGroup )
{
type = GenericLayout.TYPE_BY_GROUP[valueGroup.ordinal()];
type = valueGroup == ValueGroup.UNKNOWN ? LOWEST_TYPE_BY_VALUE_GROUP : GenericLayout.TYPE_BY_GROUP[valueGroup.ordinal()];
long0 = Long.MIN_VALUE;
long1 = Long.MIN_VALUE;
long2 = Long.MIN_VALUE;
Expand All @@ -111,7 +113,7 @@ void initValueAsLowest( ValueGroup valueGroup )
@Override
void initValueAsHighest( ValueGroup valueGroup )
{
type = GenericLayout.TYPE_BY_GROUP[valueGroup.ordinal()];
type = valueGroup == ValueGroup.UNKNOWN ? HIGHEST_TYPE_BY_VALUE_GROUP : GenericLayout.TYPE_BY_GROUP[valueGroup.ordinal()];
long0 = Long.MAX_VALUE;
long1 = Long.MAX_VALUE;
long2 = Long.MAX_VALUE;
Expand All @@ -122,7 +124,12 @@ void initValueAsHighest( ValueGroup valueGroup )
@Override
int compareValueTo( GenericKey other )
{
// TODO compare type
int typeComparison = GenericLayout.TYPE_COMPARATOR.compare( type, other.type );
if ( typeComparison != 0 )
{
return typeComparison;
}

switch ( type )
{
case ZONED_DATE_TIME:
Expand All @@ -148,10 +155,17 @@ int compareValueTo( GenericKey other )
}
}

void copyByteArray( GenericKey key, int targetLength )
void copyByteArrayFromIfExists( GenericKey key, int targetLength )
{
setBytesLength( targetLength );
System.arraycopy( key.byteArray, 0, byteArray, 0, targetLength );
if ( key.type == Type.TEXT )
{
setBytesLength( targetLength );
System.arraycopy( key.byteArray, 0, byteArray, 0, targetLength );
}
else
{
byteArray = null;
}
}

void setBytesLength( int length )
Expand Down Expand Up @@ -179,32 +193,37 @@ void initAsPrefixLow( String prefix )
@Override
protected void writeDate( long epochDay ) throws RuntimeException
{
type = Type.DATE;
long0 = epochDay;
}

@Override
protected void writeLocalTime( long nanoOfDay ) throws RuntimeException
{
type = Type.LOCAL_TIME;
long0 = nanoOfDay;
}

@Override
protected void writeTime( long nanosOfDayUTC, int offsetSeconds ) throws RuntimeException
{
type = Type.ZONED_TIME;
long0 = nanosOfDayUTC;
long1 = offsetSeconds;
}

@Override
protected void writeLocalDateTime( long epochSecond, int nano ) throws RuntimeException
{
type = Type.LOCAL_DATE_TIME;
long0 = nano;
long1 = epochSecond;
}

@Override
protected void writeDateTime( long epochSecondUTC, int nano, int offsetSeconds ) throws RuntimeException
{
type = Type.ZONED_DATE_TIME;
long0 = epochSecondUTC;
long1 = nano;
long2 = -1;
Expand All @@ -214,6 +233,7 @@ protected void writeDateTime( long epochSecondUTC, int nano, int offsetSeconds )
@Override
protected void writeDateTime( long epochSecondUTC, int nano, String zoneId ) throws RuntimeException
{
type = Type.ZONED_DATE_TIME;
long0 = epochSecondUTC;
long1 = nano;
long2 = TimeZones.map( zoneId );
Expand All @@ -223,54 +243,62 @@ protected void writeDateTime( long epochSecondUTC, int nano, String zoneId ) thr
@Override
public void writeBoolean( boolean value ) throws RuntimeException
{
type = Type.BOOLEAN;
long0 = value ? TRUE : FALSE;
}

@Override
public void writeInteger( byte value )
{
type = Type.NUMBER;
long0 = value;
long1 = RawBits.BYTE;
}

@Override
public void writeInteger( short value )
{
type = Type.NUMBER;
long0 = value;
long1 = RawBits.SHORT;
}

@Override
public void writeInteger( int value )
{
type = Type.NUMBER;
long0 = value;
long1 = RawBits.INT;
}

@Override
public void writeInteger( long value )
{
type = Type.NUMBER;
long0 = value;
long1 = RawBits.LONG;
}

@Override
public void writeFloatingPoint( float value )
{
type = Type.NUMBER;
long0 = Float.floatToIntBits( value );
long1 = RawBits.FLOAT;
}

@Override
public void writeFloatingPoint( double value )
{
type = Type.NUMBER;
long0 = Double.doubleToLongBits( value );
long1 = RawBits.DOUBLE;
}

@Override
public void writeString( String value ) throws RuntimeException
{
type = Type.TEXT;
byteArray = UTF8.encode( value );
long0 = byteArray.length;
long1 = FALSE;
Expand All @@ -285,6 +313,7 @@ public void writeString( char value ) throws RuntimeException
@Override
public void writeDuration( long months, long days, long seconds, int nanos )
{
type = Type.DURATION;
long0 = months * AVG_MONTH_SECONDS + days * AVG_DAY_SECONDS + seconds;
long1 = nanos;
long2 = months;
Expand Down
@@ -1,8 +1,13 @@
package org.neo4j.kernel.impl.index.schema;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.values.storable.ValueGroup;

import static java.util.Comparator.comparing;
import static org.neo4j.kernel.impl.index.schema.StringIndexKey.ENTITY_ID_SIZE;
import static org.neo4j.kernel.impl.index.schema.ZonedDateTimeLayout.ZONE_ID_FLAG;
import static org.neo4j.kernel.impl.index.schema.ZonedDateTimeLayout.ZONE_ID_MASK;
Expand All @@ -13,6 +18,7 @@
public class GenericLayout extends IndexLayout<GenericKey>
{
private static final int KEY_HEADER_SIZE = Byte.BYTES;
static final Comparator<Type> TYPE_COMPARATOR = comparing( t -> t.valueGroup );

enum Type
{
Expand All @@ -34,10 +40,17 @@ enum Type
this.valueGroup = valueGroup;
this.typeId = typeId;
}

ValueGroup valueGroup()
{
return valueGroup;
}
}

private static final Type[] TYPES = Type.values();
private static final Type[] TYPE_BY_ID = new Type[TYPES.length];
static final Type LOWEST_TYPE_BY_VALUE_GROUP = Collections.min( Arrays.asList( TYPES ), TYPE_COMPARATOR );
static final Type HIGHEST_TYPE_BY_VALUE_GROUP = Collections.max( Arrays.asList( TYPES ), TYPE_COMPARATOR );
static final Type[] TYPE_BY_GROUP = new Type[ValueGroup.values().length];
static
{
Expand Down Expand Up @@ -72,7 +85,7 @@ public GenericKey copyKey( GenericKey key, GenericKey into )
into.long1 = key.long1;
into.long2 = key.long2;
into.long3 = key.long3;
into.copyByteArray( key, (int) key.long0 );
into.copyByteArrayFromIfExists( key, (int) key.long0 );
return into;
}

Expand Down Expand Up @@ -223,6 +236,7 @@ public void readKey( PageCursor cursor, GenericKey into, int keySize )
return;
}

into.type = TYPE_BY_ID[typeId];
switch ( into.type )
{
case ZONED_DATE_TIME:
Expand Down

0 comments on commit 6393fb3

Please sign in to comment.