Skip to content

TUR-302: Cypher: implement point.distance and point.withinBBox - #1335

Merged
rjb32 merged 3 commits into
mainfrom
remyboutonnet/tur-302-3-spatial-functions
Nov 6, 2026
Merged

rjb32 merged 3 commits into
mainfrom
remyboutonnet/tur-302-3-spatial-functions

Conversation

@rjb32

@rjb32 rjb32 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Implement point.distance and point.withinBBox.

@rjb32

rjb32 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

AI-generated summary.

Summary

Goal. Implement point.distance(a, b) and point.withinBBox(p, lowerLeft, upperRight), so the ticket's query runs: MATCH (a:City {name: 'London'}), (b:City) WHERE point.distance(a.location, b.location) < 50000 RETURN b.name.

Approach. Both functions are declared in a new point function namespace. Each is one db op (db.point_distance, db.point_within_bbox), lowered as db.replace is: each argument becomes a row-aligned nullable point chunk or a column of tagged cells, read per row by a point reader. The result is always nullable, because points in different CRSs have no distance and no box. Distance is Euclidean for cartesian points and haversine metres for wgs-84, on the IUGG mean radius of 6,371,008.8 m rather than Neo4j's 6,378,140 m, and 3D wgs-84 follows Neo4j's formula. A box whose lower left lies east of its upper right crosses the 180th meridian. docs/points.md describes the whole type.

Where to look.

  • storage/metadata/Point.cpp:547 Point::distance
  • storage/metadata/Point.cpp:570 Point::withinBBox
  • query/ir/lowering/DBLowering.cpp:2928 lowerPointFunction: one lowering for both ops
  • query/ir/exec/NLExecutor.cpp:10413 selectPointArgumentRead: the argument shapes it reads
point.distance(paris, london)                   = 343530.34 m   checked against an independent Python haversine
point.distance(cartesian, wgs-84)               = null
point.withinBBox(179.5, ll 179, ur -179)        = true    crosses the 180th meridian

Evidence

  • Before: point.distance and point.withinBBox are not declared.
    After:
    test_query_ir_point_spatial_functions   [  PASSED  ] 17 tests.
    answersTheTicketQuery: London 0.0, Croydon 14708.388652
    

Merge Danger

Door: two-way

Blast Radius: query

Distances are 0.11% shorter than Neo4j's, because of the radius.

@rjb32
rjb32 added this pull request to stack #1347 November 5, 2026 22:38
@rjb32
rjb32 force-pushed the remyboutonnet/tur-302-2-point-components branch from 0c25503 to 710e354 Compare November 6, 2026 09:22
@rjb32
rjb32 force-pushed the remyboutonnet/tur-302-3-spatial-functions branch from e91050b to 9cf3554 Compare November 6, 2026 09:22
@rjb32
rjb32 force-pushed the remyboutonnet/tur-302-2-point-components branch from 710e354 to ba77ea3 Compare November 6, 2026 15:59
@rjb32
rjb32 force-pushed the remyboutonnet/tur-302-3-spatial-functions branch from 9cf3554 to b03b1ba Compare November 6, 2026 15:59
@rjb32
rjb32 force-pushed the remyboutonnet/tur-302-3-spatial-functions branch from b03b1ba to ad4bc29 Compare November 6, 2026 19:19
@rjb32
rjb32 force-pushed the remyboutonnet/tur-302-2-point-components branch from ba77ea3 to 27aab73 Compare November 6, 2026 19:19
@rjb32
rjb32 removed this pull request from stack #1347 November 6, 2026 19:36
@rjb32
rjb32 changed the base branch from remyboutonnet/tur-302-2-point-components to main November 6, 2026 19:37
@rjb32
rjb32 merged commit ad4bc29 into main Nov 6, 2026
4 checks passed
@rjb32
rjb32 deleted the remyboutonnet/tur-302-3-spatial-functions branch November 6, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant