Skip to content

[GH-2882] Overload ST_XMin/XMax/YMin/YMax for Box2D#2895

Merged
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/box2d-accessors
May 3, 2026
Merged

[GH-2882] Overload ST_XMin/XMax/YMin/YMax for Box2D#2895
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/box2d-accessors

Conversation

@jiayuasu
Copy link
Copy Markdown
Member

@jiayuasu jiayuasu commented May 3, 2026

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

Overloads the four 2D coordinate accessors (ST_XMin, ST_XMax, ST_YMin, ST_YMax) to accept a Box2D argument in addition to the existing Geometry argument. PostGIS-compatible.

SELECT ST_XMin(ST_Box2D(geom)), ST_YMax(ST_Box2D(geom)) FROM ...
  • common/.../Functions.java — new xMin/xMax/yMin/yMax(Box2D) overloads (each is a NULL-safe field accessor).
  • spark/common/.../expressions/Functions.scala — the four ST_* case classes now extend InferredExpression with two overloaded function references (Geometry + Box2D). FunctionResolver picks the right backing function based on the input type at planning time.
  • spark/common/.../expressions/implicits.scalatoBox2D(input: InternalRow) extractor that handles the struct UDT representation.
  • spark/common/.../expressions/InferredExpression.scalatypeOf[Box2D] branch in buildArgumentExtractor.

The output-side plumbing (InferrableType[Box2D], struct serializer, Spark return-type mapping) was added in #2890. This PR adds the symmetrical input-side plumbing. Future Box2D-consuming functions (cast to geometry, ST_AsText, future predicates) plug in by reusing this scaffolding.

How was this patch tested?

functionTestScala (added "Passed ST_XMin / XMax / YMin / YMax for Box2D"):

  • Polygon → Box2D → all four accessors return the expected axis bounds.
  • NULL Box2D input → all four accessors return NULL.

The existing Geometry-input tests continue to exercise the original overloads.

Did this PR include necessary documentation updates?

Adds Box2D variants of the four 2D accessors so users can read axis
bounds directly off a bbox value, e.g. ST_XMin(ST_Box2D(geom)).
PostGIS-compatible.

Also adds the Box2D input-side plumbing in InferredExpression: the
toBox2D extractor in implicits, and the typeOf[Box2D] branch in
buildArgumentExtractor. Future Box2D-consuming functions (cast,
ST_AsText, predicates) plug in by reusing this scaffolding.

Closes apache#2882.
Copy link
Copy Markdown
Member

@zhangfengcdt zhangfengcdt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone May 3, 2026
@jiayuasu jiayuasu merged commit dca2035 into apache:master May 3, 2026
45 checks passed
jiayuasu added a commit to jiayuasu/sedona that referenced this pull request May 5, 2026
Mirrors the Phase 1 SQL surface added in apache#2890, apache#2895, apache#2897, apache#2898,
apache#2899 in PySpark wrappers:

- ST_Box2D in st_functions
- ST_MakeBox2D and ST_GeomFromBox2D in st_constructors
- ST_Extent in st_aggregates

Accessor overloads (ST_XMin/XMax/YMin/YMax) and ST_AsText already
worked with Box2D inputs through their existing wrappers; SQL
overload resolution happens on the JVM side.

The Python Box2DType UDT and Box2D value class were merged in apache#2878,
so collected results materialize as Box2D Python objects with
xmin/ymin/xmax/ymax attributes.

Closes apache#2887.
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.

Overload ST_XMin/XMax/YMin/YMax for Box2D

2 participants