Skip to content

Commit

Permalink
Support PointArray and fixed spatial test
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner authored and MishaDemianenko committed Nov 27, 2017
1 parent 8aa5385 commit e151c21
Show file tree
Hide file tree
Showing 18 changed files with 321 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
*/
package org.neo4j.cypher.internal.javacompat;

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

public class ValueToObjectSerializer extends BaseToObjectValueWriter<RuntimeException>
{
Expand All @@ -51,6 +51,6 @@ protected Relationship newRelationshipProxyById( long id )
@Override
protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate )
{
return Points.fromValue( crs, coordinate );
return Values.pointValue( crs, coordinate );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
*/
package org.neo4j.cypher.internal.javacompat;

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

public class ValueToObjectSerializer extends BaseToObjectValueWriter<RuntimeException>
{
Expand All @@ -51,6 +51,6 @@ protected Relationship newRelationshipProxyById( long id )
@Override
protected Point newPoint( CoordinateReferenceSystem crs, double[] coordinate )
{
return Points.fromValue( crs, coordinate );
return Values.pointValue( crs, coordinate );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,21 @@ public void writeString( char value )
@Override
public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) throws RuntimeException
{
throw new UnsupportedOperationException( "Arrays of points are not yet supported." );
// Possible implementation:
// builder.append( (double) crs.code() );
// for ( double c : coordinate )
// {
// builder.append( "," );
// builder.append( c );
// }
// builder.append( '|' );
builder.append( crs.table.tableId );
builder.append( ':' );
builder.append( crs.code );
builder.append( ':' );
int index = 0;
for ( double c : coordinate )
{
if ( index > 0 )
{
builder.append( ';' );
}
builder.append( c );
index++;
}
builder.append( '|' );
}

@Override
Expand Down Expand Up @@ -182,6 +188,7 @@ private char typeChar( ArrayType arrayType )
case DOUBLE: return 'D';
case CHAR: return 'L';
case STRING: return 'L';
case POINT: return 'P';
default: throw new UnsupportedOperationException( "Not supported array type: " + arrayType );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public int calculateNumberOfBlocksUsedForGeometry( long firstBlock )
}
};

public final int gtype;
private final int gtype;

GeometryType( int gtype )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

import java.util.function.Function;

import org.neo4j.graphdb.spatial.Point;
import org.neo4j.helpers.ArrayUtil;
import org.neo4j.test.Race;
import org.neo4j.test.rule.concurrent.ThreadingRule;
import org.neo4j.values.storable.CoordinateReferenceSystem;
import org.neo4j.values.storable.PointValue;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.Values;

Expand Down Expand Up @@ -91,6 +94,10 @@ public void shouldEncodeArrays() throws Exception
assertEncoding( "Ztrue|false|", new boolean[]{true, false} );
assertEncoding( "LYWxp|YXJl|eW91|b2s=|", new String[]{"ali", "are", "you", "ok"} );
assertEncoding( "", new String[]{} );
PointValue a = Values.pointValue( CoordinateReferenceSystem.WGS84, 1.234, 2.567 );
PointValue b = Values.pointValue( CoordinateReferenceSystem.WGS84, 2.345, 5.678 );
PointValue c = Values.pointValue( CoordinateReferenceSystem.Cartesian, 3, 4, 5 );
assertEncoding( "P1:4326:1.234;2.567|1:4326:2.345;5.678|2:7203:3.0;4.0;5.0|", new Point[]{a, b, c} );
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Arrays;

import org.neo4j.graphdb.spatial.Geometry;
import org.neo4j.values.AnyValue;
import org.neo4j.values.SequenceValue;

Expand Down Expand Up @@ -101,6 +102,12 @@ public boolean equals( String[] x )
return false;
}

@Override
public boolean equals( Geometry[] x )
{
return false;
}

@Override
public int computeHash()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Arrays;

import org.neo4j.graphdb.spatial.Geometry;
import org.neo4j.values.AnyValue;
import org.neo4j.values.SequenceValue;

Expand Down Expand Up @@ -55,6 +56,12 @@ public boolean equals( String[] x )
return PrimitiveArrayValues.equals( value(), x );
}

@Override
public boolean equals( Geometry[] x )
{
return false;
}

@Override
public final boolean eq( Object other )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.values.storable;

import org.neo4j.values.AnyValue;
import org.neo4j.graphdb.spatial.Geometry;

/**
* Not a value.
Expand Down Expand Up @@ -144,6 +145,12 @@ public boolean equals( String[] x )
return false;
}

@Override
public boolean equals( Geometry[] x )
{
return false;
}

@Override
public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.values.storable;

import org.neo4j.graphdb.spatial.Geometry;

abstract class NumberArray extends ArrayValue
{
abstract int compareTo( IntegralArray other );
Expand All @@ -43,6 +45,12 @@ public boolean equals( String[] x )
return false;
}

@Override
public boolean equals( Geometry[] x )
{
return false;
}

@Override
public ValueGroup valueGroup()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.values.storable;

import java.util.Arrays;

import org.neo4j.graphdb.spatial.Geometry;
import org.neo4j.graphdb.spatial.Point;
import org.neo4j.values.AnyValue;
import org.neo4j.values.SequenceValue;

import static java.lang.String.format;

public abstract class PointArray extends ArrayValue
{
abstract Point[] value();

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

@Override
public boolean equals( Geometry[] x )
{
return Arrays.equals( value(), x );
}

@Override
public boolean equals( Value other )
{
return false;
}

@Override
public boolean equals( byte[] x )
{
return false;
}

@Override
public boolean equals( short[] x )
{
return false;
}

@Override
public boolean equals( int[] x )
{
return false;
}

@Override
public boolean equals( long[] x )
{
return false;
}

@Override
public boolean equals( float[] x )
{
return false;
}

@Override
public boolean equals( double[] x )
{
return false;
}

@Override
public boolean equals( boolean[] x )
{
return false;
}

@Override
public boolean equals( char[] x )
{
return false;
}

@Override
public boolean equals( String[] x )
{
return false;
}

@Override
public ValueGroup valueGroup()
{
return ValueGroup.GEOMETRY_ARRAY;
}

@Override
public NumberType numberType()
{
return NumberType.NO_NUMBER;
}

@Override
public final boolean eq( Object other )
{
if ( other == null )
{
return false;
}

if ( other instanceof SequenceValue )
{
return this.equals( (SequenceValue) other );
}
return other instanceof Value && equals( (Value) other );
}

@Override
public int computeHash()
{
return Arrays.hashCode( value() );
}

@Override
public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
{
PrimitiveArrayWriting.writeTo( writer, value() );
}

@Override
public Object asObjectCopy()
{
return value().clone();
}

@Override
@Deprecated
public Object asObject()
{
return value();
}

@Override
public String prettyPrint()
{
return Arrays.toString( value() );
}

static final class Direct extends PointArray
{
final Point[] value;

Direct( Point[] value )
{
assert value != null;
this.value = value;
}

@Override
Point[] value()
{
return value;
}

@Override
public String toString()
{
return format( "PointArray%s", Arrays.toString( value() ) );
}

@Override
public AnyValue value( int offset )
{
return Values.point( value[offset] );
}
}
}

0 comments on commit e151c21

Please sign in to comment.