Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Aug 21, 2017
1 parent ced0c0c commit 25e05e5
Show file tree
Hide file tree
Showing 101 changed files with 865 additions and 542 deletions.
Expand Up @@ -137,7 +137,7 @@ public void writeNode( long nodeId, TextArray labels, MapValue properties ) thro
packListHeader( labels.length() ); packListHeader( labels.length() );
for ( int i = 0; i < labels.length(); i++ ) for ( int i = 0; i < labels.length(); i++ )
{ {
labels.valueAt( i ).writeTo( this ); labels.value( i ).writeTo( this );
} }
properties.writeTo( this ); properties.writeTo( this );
} }
Expand Down
Expand Up @@ -26,6 +26,7 @@ import org.neo4j.cypher.internal.compiler.v3_3.spi.GraphStatistics
import org.neo4j.cypher.internal.frontend.v3_3.SemanticTable import org.neo4j.cypher.internal.frontend.v3_3.SemanticTable
import org.neo4j.cypher.internal.frontend.v3_3.ast.IntegerLiteral import org.neo4j.cypher.internal.frontend.v3_3.ast.IntegerLiteral
import org.neo4j.cypher.internal.ir.v3_3._ import org.neo4j.cypher.internal.ir.v3_3._
import org.neo4j.values.storable.NumberValue


class StatisticsBackedCardinalityModel(queryGraphCardinalityModel: QueryGraphCardinalityModel, simpleExpressionEvaluator: ExpressionEvaluator) extends CardinalityModel { class StatisticsBackedCardinalityModel(queryGraphCardinalityModel: QueryGraphCardinalityModel, simpleExpressionEvaluator: ExpressionEvaluator) extends CardinalityModel {


Expand Down Expand Up @@ -56,8 +57,8 @@ class StatisticsBackedCardinalityModel(queryGraphCardinalityModel: QueryGraphCar
else { else {
val evaluatedValue: Option[Any] = simpleExpressionEvaluator.evaluateExpression(limit) val evaluatedValue: Option[Any] = simpleExpressionEvaluator.evaluateExpression(limit)


if (evaluatedValue.isDefined && evaluatedValue.get.isInstanceOf[Number]) if (evaluatedValue.isDefined && evaluatedValue.get.isInstanceOf[NumberValue])
Cardinality(evaluatedValue.get.asInstanceOf[Number].doubleValue()) Cardinality(evaluatedValue.get.asInstanceOf[NumberValue].doubleValue())
else GraphStatistics.DEFAULT_LIMIT_CARDINALITY else GraphStatistics.DEFAULT_LIMIT_CARDINALITY
} }


Expand Down
Expand Up @@ -19,17 +19,22 @@
*/ */
package org.neo4j.cypher.internal.javacompat; package org.neo4j.cypher.internal.javacompat;


import java.lang.reflect.Array;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;


import org.neo4j.graphalgo.impl.util.PathImpl; import org.neo4j.cypher.internal.compatibility.v3_3.runtime.CartesianPoint;
import org.neo4j.graphdb.spatial.CRS; import org.neo4j.cypher.internal.compatibility.v3_3.runtime.GeographicPoint;
import org.neo4j.graphdb.spatial.Coordinate; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.spatial.Point; import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Relationship;
import org.neo4j.helpers.collection.ReverseArrayIterator;
import org.neo4j.kernel.impl.core.NodeManager; import org.neo4j.kernel.impl.core.NodeManager;
import org.neo4j.values.AnyValueWriter; import org.neo4j.values.AnyValueWriter;
import org.neo4j.values.storable.TextArray; import org.neo4j.values.storable.TextArray;
Expand All @@ -39,6 +44,8 @@
import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.MapValue;
import org.neo4j.values.virtual.NodeValue; import org.neo4j.values.virtual.NodeValue;


import static org.neo4j.helpers.collection.Iterators.iteratorsEqual;

public class ValueToObjectSerializer implements AnyValueWriter<RuntimeException> public class ValueToObjectSerializer implements AnyValueWriter<RuntimeException>
{ {
private final NodeManager nodeManager; private final NodeManager nodeManager;
Expand Down Expand Up @@ -117,13 +124,135 @@ public void endList() throws RuntimeException
@Override @Override
public void writePath( NodeValue[] nodes, EdgeValue[] edges ) throws RuntimeException public void writePath( NodeValue[] nodes, EdgeValue[] edges ) throws RuntimeException
{ {
PathImpl.Builder builder = new PathImpl.Builder( nodeManager.newNodeProxyById( nodes[0].id() ) ); assert nodes != null;
for ( EdgeValue edge : edges ) assert nodes.length > 0;
Node[] nodeProxies = new Node[nodes.length];
for ( int i = 0; i < nodes.length; i++ )
{
nodeProxies[i] = nodeManager.newNodeProxyById( nodes[i].id() );
}
Relationship[] relationship = new Relationship[edges.length];
for ( int i = 0; i < edges.length; i++ )
{ {
builder.push( nodeManager.newRelationshipProxyById( edge.id() ) ); relationship[i] = nodeManager.newRelationshipProxyById( edges[i].id() );
} }
writeValue( new Path()
{
@Override
public Node startNode()
{
return nodeProxies[0];
}

@Override
public Node endNode()
{
return nodeProxies[nodeProxies.length - 1];
}

@Override
public Relationship lastRelationship()
{
return relationship[relationship.length - 1];
}

@Override
public Iterable<Relationship> relationships()
{
return Arrays.asList( relationship );
}

@Override
public Iterable<Relationship> reverseRelationships()
{
return () -> new ReverseArrayIterator<>( relationship );
}

@Override
public Iterable<Node> nodes()
{
return Arrays.asList( nodeProxies );
}

@Override
public Iterable<Node> reverseNodes()
{
return () -> new ReverseArrayIterator<>( nodeProxies );
}

@Override
public int length()
{
return relationship.length;
}

@Override
public int hashCode()
{
if ( relationship.length == 0 )
{
return startNode().hashCode();
}
else
{
return Arrays.hashCode( relationship );
}
}

@Override
public boolean equals( Object obj )
{
if ( this == obj )
{
return true;
}
else if ( obj instanceof Path )
{
Path other = (Path) obj;
return startNode().equals( other.startNode() ) &&
iteratorsEqual( this.relationships().iterator(), other.relationships().iterator() );

}
else
{
return false;
}
}


writeValue( builder.build() ); @Override
public Iterator<PropertyContainer> iterator()
{
return new Iterator<PropertyContainer>()
{
Iterator<? extends PropertyContainer> current = nodes().iterator();
Iterator<? extends PropertyContainer> next = relationships().iterator();

public boolean hasNext()
{
return current.hasNext();
}

public PropertyContainer next()
{
try
{
return current.next();
}
finally
{
Iterator<? extends PropertyContainer> temp = current;
current = next;
next = temp;
}
}

public void remove()
{
next.remove();
}
};
}
} );
} }


@Override @Override
Expand Down Expand Up @@ -226,7 +355,7 @@ public void endUTF8() throws RuntimeException
@Override @Override
public void beginArray( int size, ArrayType arrayType ) throws RuntimeException public void beginArray( int size, ArrayType arrayType ) throws RuntimeException
{ {
stack.push( new ArrayWriter( size ) ); stack.push( new ArrayWriter( size, arrayType ) );
} }


@Override @Override
Expand Down Expand Up @@ -301,18 +430,49 @@ public Object value()


class ArrayWriter implements Writer class ArrayWriter implements Writer
{ {
protected final Object[] array; protected final Object array;
private int index; private int index;


ArrayWriter( int size ) ArrayWriter( int size, ArrayType arrayType )
{ {
this.array = new Object[size]; switch ( arrayType )
{
case SHORT:
this.array = Array.newInstance( short.class, size );
break;
case INT:
this.array = Array.newInstance( int.class, size );
break;
case BYTE:
this.array = Array.newInstance( byte.class, size );
break;
case LONG:
this.array = Array.newInstance( long.class, size );
break;
case FLOAT:
this.array = Array.newInstance( float.class, size );
break;
case DOUBLE:
this.array = Array.newInstance( double.class, size );
break;
case BOOLEAN:
this.array = Array.newInstance( boolean.class, size );
break;
case STRING:
this.array = Array.newInstance( String.class, size );
break;
case CHAR:
this.array = Array.newInstance( char.class, size );
break;
default:
this.array = new Object[size];
}
} }


@Override @Override
public void write( Object value ) public void write( Object value )
{ {
array[index++] = value; Array.set( array, index++, value );
} }


@Override @Override
Expand All @@ -322,17 +482,25 @@ public Object value()
} }
} }


class ListWriter extends ArrayWriter class ListWriter implements Writer
{ {
private final List<Object> list;

ListWriter( int size ) ListWriter( int size )
{ {
super( size ); this.list = new ArrayList<>( size );
}

@Override
public void write( Object value )
{
list.add( value );
} }


@Override @Override
public Object value() public Object value()
{ {
return Arrays.asList( array ); return list;
} }
} }


Expand All @@ -357,45 +525,20 @@ public void write( Object value )
@Override @Override
public Object value() public Object value()
{ {
return new Point() if ( crs.code() == CoordinateReferenceSystem.WGS84.code() )
{ {
@Override return new GeographicPoint( coordinates[0], coordinates[1], new org.neo4j.cypher.internal
public String getGeometryType() .compatibility.v3_3.runtime.CRS( crs.name, crs.code, crs.href ) );
{ }
return "Point"; else if ( crs.code() == CoordinateReferenceSystem.Cartesian.code() )
} {

return new CartesianPoint( coordinates[0], coordinates[1], new org.neo4j.cypher.internal
@Override .compatibility.v3_3.runtime.CRS( crs.name, crs.code, crs.href ) );
public List<Coordinate> getCoordinates() }
{ else
return Collections.singletonList( new Coordinate( coordinates ) ); {
} throw new IllegalArgumentException( crs + " is not a supported coordinate reference system" );

}
@Override
public CRS getCRS()
{
return new CRS()
{
@Override
public int getCode()
{
return crs.code();
}

@Override
public String getType()
{
return crs.type();
}

@Override
public String getHref()
{
return crs.href();
}
};
}
};
} }
} }
} }
Expand Up @@ -255,15 +255,15 @@ class ExceptionTranslatingQueryContext(val inner: QueryContext) extends QueryCon
override def getOptRelTypeId(relType: String) = override def getOptRelTypeId(relType: String) =
translateException(inner.getOptRelTypeId(relType)) translateException(inner.getOptRelTypeId(relType))


override def detachDeleteNode(node: Node): Int = override def detachDeleteNode(node: Long): Int =
translateException(inner.detachDeleteNode(node)) translateException(inner.detachDeleteNode(node))


override def assertSchemaWritesAllowed(): Unit = translateException(inner.assertSchemaWritesAllowed()) override def assertSchemaWritesAllowed(): Unit = translateException(inner.assertSchemaWritesAllowed())


class ExceptionTranslatingOperations[T <: PropertyContainer](inner: Operations[T]) class ExceptionTranslatingOperations[T <: PropertyContainer](inner: Operations[T])
extends DelegatingOperations[T](inner) { extends DelegatingOperations[T](inner) {
override def delete(obj: T) = override def delete(id: Long) =
translateException(inner.delete(obj)) translateException(inner.delete(id))


override def setProperty(id: Long, propertyKey: Int, value: Value) = override def setProperty(id: Long, propertyKey: Int, value: Value) =
translateException(inner.setProperty(id, propertyKey, value)) translateException(inner.setProperty(id, propertyKey, value))
Expand Down Expand Up @@ -295,8 +295,8 @@ class ExceptionTranslatingQueryContext(val inner: QueryContext) extends QueryCon
override def allPrimitive: PrimitiveLongIterator = override def allPrimitive: PrimitiveLongIterator =
translateException(inner.allPrimitive) translateException(inner.allPrimitive)


override def isDeletedInThisTx(obj: T): Boolean = override def isDeletedInThisTx(id: Long): Boolean =
translateException(inner.isDeletedInThisTx(obj)) translateException(inner.isDeletedInThisTx(id))
} }


class ExceptionTranslatingTransactionalContext(inner: QueryTransactionalContext) extends DelegatingQueryTransactionalContext(inner) { class ExceptionTranslatingTransactionalContext(inner: QueryTransactionalContext) extends DelegatingQueryTransactionalContext(inner) {
Expand Down

0 comments on commit 25e05e5

Please sign in to comment.