Skip to content

Commit

Permalink
Fixed point type conversion for BaseToObjectValueWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner authored and MishaDemianenko committed Nov 27, 2017
1 parent f1129bd commit a2ff0a9
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 61 deletions.
Expand Up @@ -31,6 +31,7 @@
import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.values.AnyValue; import org.neo4j.values.AnyValue;
import org.neo4j.values.utils.PrettyPrinter; import org.neo4j.values.utils.PrettyPrinter;
import org.neo4j.values.virtual.CoordinateReferenceSystem;
import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.MapValue;


import static org.neo4j.bolt.v1.messaging.BoltResponseMessage.FAILURE; import static org.neo4j.bolt.v1.messaging.BoltResponseMessage.FAILURE;
Expand Down Expand Up @@ -157,13 +158,7 @@ protected Relationship newRelationshipProxyById( long id )
} }


@Override @Override
protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate )
{
throw exception;
}

@Override
protected Point newCartesianPoint( double x, double y, String name, int code, String href )
{ {
throw exception; throw exception;
} }
Expand Down
Expand Up @@ -655,13 +655,7 @@ protected Relationship newRelationshipProxyById( long id )
} }


@Override @Override
protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate )
{
throw new UnsupportedOperationException( "Cannot unpack points" );
}

@Override
protected Point newCartesianPoint( double x, double y, String name, int code, String href )
{ {
throw new UnsupportedOperationException( "Cannot unpack points" ); throw new UnsupportedOperationException( "Cannot unpack points" );
} }
Expand Down
Expand Up @@ -59,6 +59,7 @@
import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.impl.util.HexPrinter; import org.neo4j.kernel.impl.util.HexPrinter;
import org.neo4j.values.AnyValue; import org.neo4j.values.AnyValue;
import org.neo4j.values.virtual.CoordinateReferenceSystem;
import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.MapValue;


import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.containsString;
Expand Down Expand Up @@ -103,13 +104,7 @@ protected Relationship newRelationshipProxyById( long id )
} }


@Override @Override
protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate )
{
return null;
}

@Override
protected Point newCartesianPoint( double x, double y, String name, int code, String href )
{ {
return null; return null;
} }
Expand Down
Expand Up @@ -25,6 +25,7 @@ import org.mockito.{ArgumentMatchers, Mockito}
import org.neo4j.cypher.internal.runtime.QueryContext import org.neo4j.cypher.internal.runtime.QueryContext
import org.neo4j.cypher.internal.runtime.interpreted.TransactionBoundQueryContext.IndexSearchMonitor import org.neo4j.cypher.internal.runtime.interpreted.TransactionBoundQueryContext.IndexSearchMonitor
import org.neo4j.cypher.internal.runtime.interpreted.pipes.{ExternalCSVResource, NullPipeDecorator, PipeDecorator, QueryState} import org.neo4j.cypher.internal.runtime.interpreted.pipes.{ExternalCSVResource, NullPipeDecorator, PipeDecorator, QueryState}
import org.neo4j.graphdb.spatial.Point
import org.neo4j.graphdb.{Node, Relationship} import org.neo4j.graphdb.{Node, Relationship}
import org.neo4j.kernel.GraphDatabaseQueryService import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.impl.coreapi.{InternalTransaction, PropertyContainerLocker} import org.neo4j.kernel.impl.coreapi.{InternalTransaction, PropertyContainerLocker}
Expand All @@ -33,8 +34,8 @@ import org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo
import org.neo4j.kernel.impl.util.BaseToObjectValueWriter import org.neo4j.kernel.impl.util.BaseToObjectValueWriter
import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors} import org.neo4j.kernel.monitoring.{Monitors => KernelMonitors}
import org.neo4j.values.AnyValue import org.neo4j.values.AnyValue
import org.neo4j.values.virtual.MapValue
import org.neo4j.values.virtual.VirtualValues.EMPTY_MAP import org.neo4j.values.virtual.VirtualValues.EMPTY_MAP
import org.neo4j.values.virtual.{CoordinateReferenceSystem, MapValue}


import scala.collection.mutable import scala.collection.mutable


Expand Down Expand Up @@ -87,6 +88,7 @@ object QueryStateHelper {
val writer = new BaseToObjectValueWriter[RuntimeException] { val writer = new BaseToObjectValueWriter[RuntimeException] {
override protected def newNodeProxyById(id: Long): Node = ??? override protected def newNodeProxyById(id: Long): Node = ???
override protected def newRelationshipProxyById(id: Long): Relationship = ??? override protected def newRelationshipProxyById(id: Long): Relationship = ???
override protected def newPoint(crs: CoordinateReferenceSystem, coordinate: Array[Double]): Point = ???
} }
any.writeTo(writer) any.writeTo(writer)
writer.value() writer.value()
Expand Down
Expand Up @@ -19,13 +19,13 @@
*/ */
package org.neo4j.cypher.internal.javacompat; package org.neo4j.cypher.internal.javacompat;


import org.neo4j.cypher.internal.runtime.CartesianPoint; import org.neo4j.cypher.internal.runtime.Points;
import org.neo4j.cypher.internal.runtime.GeographicPoint;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.spatial.Point; import org.neo4j.graphdb.spatial.Point;
import org.neo4j.kernel.impl.core.NodeManager; import org.neo4j.kernel.impl.core.NodeManager;
import org.neo4j.kernel.impl.util.BaseToObjectValueWriter; import org.neo4j.kernel.impl.util.BaseToObjectValueWriter;
import org.neo4j.values.virtual.CoordinateReferenceSystem;


public class ValueToObjectSerializer extends BaseToObjectValueWriter<RuntimeException> public class ValueToObjectSerializer extends BaseToObjectValueWriter<RuntimeException>
{ {
Expand All @@ -49,16 +49,9 @@ protected Relationship newRelationshipProxyById( long id )
} }


@Override @Override
protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate )
{ {
return new GeographicPoint( longitude, latitude, // TODO: Is this necessary, perhaps PointValue is sufficient for use in Cypher-land
new org.neo4j.cypher.internal.runtime.CRS( name, code, href ) ); return Points.fromValue( crs, coordinate );
}

@Override
protected Point newCartesianPoint( double x, double y, String name, int code, String href )
{
return new CartesianPoint( x, y,
new org.neo4j.cypher.internal.runtime.CRS( name, code, href ) );
} }
} }
Expand Up @@ -24,6 +24,7 @@ import java.util.Collections
import org.neo4j.cypher.internal.util.v3_4.{CypherTypeException, InvalidArgumentException} import org.neo4j.cypher.internal.util.v3_4.{CypherTypeException, InvalidArgumentException}
import org.neo4j.graphdb.spatial import org.neo4j.graphdb.spatial
import org.neo4j.graphdb.spatial.{Coordinate, Point} import org.neo4j.graphdb.spatial.{Coordinate, Point}
import org.neo4j.values.virtual.CoordinateReferenceSystem


import scala.beans.BeanProperty import scala.beans.BeanProperty


Expand Down Expand Up @@ -82,6 +83,15 @@ object CRS {
} }


object Points { object Points {
// TODO: Is this necessary, perhaps PointValue is sufficient for use in Cypher-land
def fromValue(crsValue: CoordinateReferenceSystem, coordinate: Array[Double]) = {
val crs = CRS.fromName(crsValue.name)
if (crs == CRS.WGS84) {
new GeographicPoint(coordinate(0), coordinate(1), crs)
} else {
new CartesianPoint(coordinate(0), coordinate(1), crs)
}
}
private def safeToDouble(value: Any) = value match { private def safeToDouble(value: Any) = value match {
case n: Number => n.doubleValue() case n: Number => n.doubleValue()
case other => throw new CypherTypeException(other.getClass.getSimpleName + " is not a valid coordinate type.") case other => throw new CypherTypeException(other.getClass.getSimpleName + " is not a valid coordinate type.")
Expand Down
Expand Up @@ -69,6 +69,8 @@ public BaseToObjectValueWriter()


protected abstract Relationship newRelationshipProxyById( long id ); protected abstract Relationship newRelationshipProxyById( long id );


protected abstract Point newPoint( CoordinateReferenceSystem crs, double[] coordinate );

public Object value() public Object value()
{ {
assert stack.size() == 1; assert stack.size() == 1;
Expand Down Expand Up @@ -313,12 +315,11 @@ public String toString()
} ); } );
} }


// TODO undefault and implement in subclasses?
@Override @Override
public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) throws E public final void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) throws E
{ {
throw new UnsupportedOperationException(); writeValue( newPoint( crs, coordinate ) );
}; }


@Override @Override
public void writeNull() throws RuntimeException public void writeNull() throws RuntimeException
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.neo4j.kernel.api.query.QuerySnapshot; import org.neo4j.kernel.api.query.QuerySnapshot;
import org.neo4j.kernel.impl.core.NodeManager; import org.neo4j.kernel.impl.core.NodeManager;
import org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo; import org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo;
import org.neo4j.values.virtual.CoordinateReferenceSystem;
import org.neo4j.kernel.impl.util.BaseToObjectValueWriter; import org.neo4j.kernel.impl.util.BaseToObjectValueWriter;
import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.MapValue;


Expand Down Expand Up @@ -153,19 +154,9 @@ protected Relationship newRelationshipProxyById( long id )
} }


@Override @Override
protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate )
{
return point( longitude, latitude, name, code, href );
}

@Override
protected Point newCartesianPoint( double x, double y, String name, int code, String href )
{
return point( x, y, name, code, href );
}

private Point point( double x, double y, String name, int code, String href )
{ {
//TODO: Is this required perhaps PointValue is sufficient without mapping to public?
return new Point() return new Point()
{ {
@Override @Override
Expand All @@ -177,7 +168,7 @@ public String getGeometryType()
@Override @Override
public List<Coordinate> getCoordinates() public List<Coordinate> getCoordinates()
{ {
return singletonList( new Coordinate( x, y ) ); return singletonList( new Coordinate( coordinate ) );
} }


@Override @Override
Expand All @@ -188,19 +179,19 @@ public CRS getCRS()
@Override @Override
public int getCode() public int getCode()
{ {
return code; return crs.code;
} }


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


@Override @Override
public String getHref() public String getHref()
{ {
return href; return crs.href;
} }
}; };
} }
Expand Down
Expand Up @@ -74,6 +74,7 @@
import org.neo4j.test.rule.concurrent.ThreadingRule; import org.neo4j.test.rule.concurrent.ThreadingRule;
import org.neo4j.values.AnyValue; import org.neo4j.values.AnyValue;
import org.neo4j.values.storable.TextValue; import org.neo4j.values.storable.TextValue;
import org.neo4j.values.virtual.CoordinateReferenceSystem;
import org.neo4j.values.virtual.ListValue; import org.neo4j.values.virtual.ListValue;
import org.neo4j.values.virtual.MapValue; import org.neo4j.values.virtual.MapValue;


Expand Down Expand Up @@ -938,13 +939,7 @@ protected Relationship newRelationshipProxyById( long id )
} }


@Override @Override
protected Point newGeographicPoint( double longitude, double latitude, String name, int code, String href ) protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate )
{
return null;
}

@Override
protected Point newCartesianPoint( double x, double y, String name, int code, String href )
{ {
return null; return null;
} }
Expand Down

0 comments on commit a2ff0a9

Please sign in to comment.