Skip to content

Commit

Permalink
Reuse OperatorName.DISTANCE for Cypher distance(p1, p2) implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
murermader committed Oct 14, 2024
1 parent cffe4c4 commit 901c421
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private void defineCypherMethods() {
defineMethod( OperatorRegistry.get( cypher, OperatorName.CYPHER_REMOVE_PROPERTY ), BuiltInMethod.CYPHER_REMOVE_PROPERTY.method, NullPolicy.NONE );
defineMethod( OperatorRegistry.get( cypher, OperatorName.CYPHER_GRAPH_ONLY_LABEL ), BuiltInMethod.X_MODEL_GRAPH_ONLY_LABEL.method, NullPolicy.NONE );
defineMethod( OperatorRegistry.get( cypher, OperatorName.CYPHER_POINT ), BuiltInMethod.CYPHER_POINT.method, NullPolicy.NONE );
defineMethod( OperatorRegistry.get( cypher, OperatorName.CYPHER_DISTANCE ), BuiltInMethod.CYPHER_DISTANCE.method, NullPolicy.NONE );
defineMethod( OperatorRegistry.get( cypher, OperatorName.DISTANCE ), BuiltInMethod.CYPHER_DISTANCE.method, NullPolicy.NONE );
defineMethod( OperatorRegistry.get( cypher, OperatorName.CYPHER_WITHIN_BBOX ), BuiltInMethod.CYPHER_WITHIN_BBOX.method, NullPolicy.NONE );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1725,8 +1725,6 @@ public enum OperatorName {

CYPHER_POINT( LangFunctionOperator.class ),

CYPHER_DISTANCE ( LangFunctionOperator.class ),

CYPHER_WITHIN_BBOX ( LangFunctionOperator.class ),

// CROSS MODEL FUNCTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ public void createPointTest() {
assert geometry.asPoint().getZ() == 100.0;
}

@Test
public void distanceTest(){
// execute( """
// CREATE (basel:City {name: 'Basel', latitude: 47.5595, longitude: 7.5885}),
// (zurich:City {name: 'Zürich', latitude: 47.3770, longitude: 8.5416});
// """ );
GraphResult res = execute( """
MATCH (basel:City {name: 'Basel'}), (zurich:City {name: 'Zürich'})
WITH basel, zurich,
point({latitude: basel.latitude, longitude: basel.longitude}) AS point1,
point({latitude: zurich.latitude, longitude: zurich.longitude}) AS point2
RETURN basel.name, zurich.name, distance(point1, point2) AS distance;
""" );
System.out.println(res.toString());
}


private PolyGeometry convertJsonToPolyGeometry( String json ) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static void registerOperators() {

register( OperatorName.CYPHER_POINT, new LangFunctionOperator( "CYPHER_POINT", Kind.CYPHER_FUNCTION ) );

register( OperatorName.CYPHER_DISTANCE, new LangFunctionOperator( "CYPHER_DISTANCE", Kind.CYPHER_FUNCTION ) );
register( OperatorName.DISTANCE, new LangFunctionOperator( "DISTANCE", Kind.CYPHER_FUNCTION ) );

register( OperatorName.CYPHER_WITHIN_BBOX, new LangFunctionOperator( "CYPHER_WITHIN_BBOX", Kind.CYPHER_FUNCTION ) );

Expand Down

0 comments on commit 901c421

Please sign in to comment.