Skip to content

[GH-2798] Add ST_ShortestLine function#2806

Draft
jiayuasu wants to merge 1 commit intoapache:masterfrom
jiayuasu:feature/st-shortest-line
Draft

[GH-2798] Add ST_ShortestLine function#2806
jiayuasu wants to merge 1 commit intoapache:masterfrom
jiayuasu:feature/st-shortest-line

Conversation

@jiayuasu
Copy link
Copy Markdown
Member

@jiayuasu jiayuasu commented Mar 29, 2026

Summary

  • Add ST_ShortestLine(geom1, geom2) function that returns the shortest LineString connecting two geometries
  • Uses JTS DistanceOp.nearestPoints() internally — same approach as the existing ST_ClosestPoint but returns both endpoints as a LineString instead of a single Point
  • Returns null for empty geometries

Closes #2798

Changes

Implementation (6 layers)

  • Java core (Functions.java): shortestLine(Geometry, Geometry) using DistanceOp
  • Scala Expression (Functions.scala): ST_ShortestLine case class
  • Catalog (Catalog.scala): Function registration
  • Scala API (st_functions.scala): Column/String wrappers
  • Python API (st_functions.py): Python wrapper
  • Flink (Functions.java, Catalog.java): Flink scalar function + registration

Tests

  • Java unit tests (5 cases: point-to-point, point-to-linestring, polygon-to-polygon, empty geometry, same geometry)
  • Scala SQL tests + DataFrame API test
  • SRID preservation test
  • Python SQL test + DataFrame API test
  • Flink test

Documentation

  • SQL, Flink, and Snowflake docs with examples

Test plan

  • Java unit tests pass (mvn test -pl common -Dtest="FunctionsTest#shortestLine*")
  • Python SQL tests pass
  • Python DataFrame API tests pass
  • CI full test suite

@jiayuasu jiayuasu marked this pull request as draft March 29, 2026 08:08
@jiayuasu jiayuasu force-pushed the feature/st-shortest-line branch 2 times, most recently from c24dcaf to 8f82a05 Compare March 29, 2026 08:13
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.

Add ST_ShortestLine function

1 participant