Skip to content

Commit

Permalink
Double and large Long property values
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Jun 25, 2017
1 parent 5a6d48c commit b3ee473
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,44 @@ class PropertyCursor extends org.neo4j.impl.store.prototype.PropertyCursor<ReadS
@Override
public boolean next()
{
while ( block >= -1 && block < 3 )
int nextBlock = block + blocksUsedByCurrent();
while ( nextBlock >= 0 && nextBlock < 4 )
{
block++;
block = nextBlock;
if ( typeIdentifier() != 0 )
{
return true;
}
nextBlock = block + blocksUsedByCurrent();
}
// TODO: move to next record if needed
close();
return false;
}

private int blocksUsedByCurrent()
{
if ( block == -1 )
{
return 1;
}
long valueBytes = block( this.block );
long typeId = (valueBytes & 0x0F00_0000L) >> 24;
if ( typeId == DOUBLE ||
(typeId == LONG && ( valueBytes & 0x0000_0000_1000_0000 ) == 0 ) )
{
if ( moreBlocksInRecord() )
{
return 2;
}
else
{
throw new UnsupportedOperationException( "not implemented" ); // long bytes in next record
}
}
return 1;
}

@Override
protected void closeImpl()
{
Expand Down Expand Up @@ -186,14 +211,21 @@ public Value propertyValue()
long valueBytes = block( this.block );
if ( ( valueBytes & 0x0000_0000_1000_0000 ) == 0 )
{
throw new UnsupportedOperationException( "not implemented" ); // long bytes in next block
if ( moreBlocksInRecord() )
{
return block( this.block + 1 );
}
else
{
throw new UnsupportedOperationException( "not implemented" ); // long bytes in next record
}
}
return Values.longValue( (valueBytes & 0xFFFF_FFFF_E000_0000L) >> 29 );
case FLOAT:
return Values.floatValue(
Float.intBitsToFloat((int)((block( this.block ) & 0x0FFF_FFFF_F000_0000L) >> 28) ) );
case DOUBLE:
throw new UnsupportedOperationException( "not implemented" );
return Double.longBitsToDouble( block( this.block + 1 ) );
case STRING_REFERENCE:
throw new UnsupportedOperationException( "not implemented" );
case ARRAY_REFERENCE:
Expand All @@ -207,6 +239,11 @@ public Value propertyValue()
}
}

private boolean moreBlocksInRecord()
{
return block < 3;
}

@Override
public <E extends Exception> void writeTo( ValueWriter<E> target )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected void create( GraphDatabaseService graphDb )
shortProp = createNodeWithProperty( graphDb, "shortProp", (short)13 );
intProp = createNodeWithProperty( graphDb, "intProp", 13 );
inlineLongProp = createNodeWithProperty( graphDb, "inlineLongProp", 13L );
longProp = createNodeWithProperty( graphDb, "longProp", Long.MAX_VALUE );

floatProp = createNodeWithProperty( graphDb, "floatProp", 13.0f );
doubleProp = createNodeWithProperty( graphDb, "doubleProp", 13.0 );
Expand Down Expand Up @@ -101,7 +102,9 @@ public void shouldAccessIntProperty() throws Exception
assertAccessSingleProperty( shortProp, (short)13 );
assertAccessSingleProperty( intProp, 13 );
assertAccessSingleProperty( inlineLongProp, 13L );
assertAccessSingleProperty( longProp, Long.MAX_VALUE );
assertAccessSingleProperty( floatProp, 13.0f );
assertAccessSingleProperty( doubleProp, 13.0 );
assertAccessSingleProperty( trueProp, true );
assertAccessSingleProperty( falseProp, false );
}
Expand Down

0 comments on commit b3ee473

Please sign in to comment.