jiayuasu opened a new pull request, #2899:
URL: https://github.com/apache/sedona/pull/2899

   ## Did you read the Contributor Guide?
   
   - Yes, I have read the [Contributor 
Rules](https://sedona.apache.org/latest/community/rule/) and [Contributor 
Development Guide](https://sedona.apache.org/latest/community/develop/)
   
   ## Is this PR related to a ticket?
   
   - Yes, and the PR name follows the format \`[GH-XXX] my subject\`. Closes 
#2885
   
   ## What changes were proposed in this PR?
   
   Two related conversions on \`Box2D\`:
   
   ### 1. \`ST_GeomFromBox2D(box2d) -> Polygon\`
   
   Converts a \`Box2D\` to a closed rectangular polygon. Equivalent to PostGIS 
\`box2d::geometry\`.
   
   \`\`\`sql
   SELECT ST_AsText(ST_GeomFromBox2D(ST_MakeBox2D(ST_Point(1, 2), ST_Point(4, 
5))));
   -- POLYGON ((1 2, 1 5, 4 5, 4 2, 1 2))
   \`\`\`
   
   **Why a function instead of an implicit cast.** PostGIS uses 
\`box2d::geometry\` cast syntax. Spark Catalyst supports UDT-to-UDT implicit 
casts but registering one requires extending Catalyst's \`Cast\` resolution 
rule, which is a real piece of work and orthogonal to the bbox feature itself. 
Sedona's existing \`ST_GeomFrom*\` family (\`ST_GeomFromWKT\`, 
\`ST_GeomFromGeoJSON\`, etc.) is the natural home for an explicit constructor. 
NULL input → NULL output.
   
   ### 2. \`ST_AsText(box2d) -> 'BOX(xmin ymin, xmax ymax)'\`
   
   Overloads the existing \`ST_AsText\` (which already handles \`Geometry\` and 
\`Geography\`) to accept a \`Box2D\` and return PostGIS-format text:
   
   \`\`\`sql
   SELECT ST_AsText(ST_Box2D(ST_GeomFromText('POLYGON((1 2, 1 5, 4 5, 4 2, 1 
2))')));
   -- BOX(1.0 2.0, 4.0 5.0)
   \`\`\`
   
   NULL on null input.
   
   ## How was this patch tested?
   
   \`constructorTestScala\`:
   - \"Passed ST_GeomFromBox2D\" — round-trip through \`ST_MakeBox2D\` → 
\`ST_GeomFromBox2D\` → \`ST_AsText\`, and NULL propagation.
   
   \`functionTestScala\`:
   - \"Passed ST_AsText for Box2D\" — happy-path format \`BOX(1.0 2.0, 4.0 
5.0)\`, and NULL propagation.
   
   ## Did this PR include necessary documentation updates?
   
   - No, this PR does not affect any public SQL API documentation surface in 
isolation. Documentation for the Phase 1 Box2D surface (#2877) lands as a 
single coherent docs update once the cross-language bindings (#2887, #2888) are 
in. Scala DataFrame API wrappers tracked separately in #2891.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to