Skip to content

[feature](geo) Add st_xmax/st_xmin/st_ymax/st_ymin functions - #66814

Open
MiYuyuyuyu wants to merge 10 commits into
apache:masterfrom
MiYuyuyuyu:feat-st-xmax
Open

[feature](geo) Add st_xmax/st_xmin/st_ymax/st_ymin functions#66814
MiYuyuyuyu wants to merge 10 commits into
apache:masterfrom
MiYuyuyuyu:feat-st-xmax

Conversation

@MiYuyuyuyu

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: close #48203

Related PR: #xxx

Problem Summary:
Add four Trino compatible bounding box accessor functions:
st_xmax / st_xmin / st_ymax / st_ymin.

BE:

  • Add GeoShape::bounding_box() (BoundingBox struct) and implement it for
    GeoPoint, GeoLine, GeoPolygon, GeoMultiPolygon and GeoCircle (treated as
    its center point).
  • Add the four function structs in functions_geo.cpp, decoding the input
    geometry via GeoShape::from_encoded and returning NULL for invalid input.

FE:

  • Add the four Nereids scalar function signatures and register them in
    BuiltinScalarFunctions and ScalarFunctionVisitor.

Tests:

  • Regression test suite nereids_scalar_fn_st_bounding_box (14 cases,
    auto-generated .out).
  • BE unit tests GeoTypesTest.bounding_box_* (28 tests passed).

Release note

Add st_xmax / st_xmin / st_ymax / st_ymin functions.

Check List (For Author)

### What problem does this PR solve?

Issue Number: close apache#48203

Problem Summary:
Add a virtual bounding_box() accessor to GeoShape so that the Trino
compatible ST_XMax/ST_XMin/ST_YMax/ST_YMin functions can be implemented
on top of it. Implemented for GeoPoint, GeoLine, GeoPolygon,
GeoMultiPolygon and GeoCircle (circle treated as its center point).

### Release note

None

### Check List (For Author)

- Test: No need to test (accessor only, functions come in later commits)
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: close apache#48203

Problem Summary:
Add the four Trino compatible bounding box accessor functions. Each
function decodes the input geometry via GeoShape::from_encoded and
returns the corresponding field of GeoShape::bounding_box(); NULL is
returned for invalid input or shape types without a bounding box.

### Release note

Add st_xmax/st_xmin/st_ymax/st_ymin functions.

### Check List (For Author)

- Test: No need to test (regression tests come in a later commit)
- Behavior changed: Yes
- Does this need documentation: Yes (doc PR will be linked)
…ymin

### What problem does this PR solve?

Issue Number: close apache#48203

Problem Summary:
Add the Nereids scalar function signature classes, following the StX
pattern. Each accepts one VARCHAR/String argument and returns DOUBLE.

### Release note

None

### Check List (For Author)

- Test: No need to test (registration and tests come in later commits)
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: close apache#48203

Problem Summary:
Register the four new scalar functions in BuiltinScalarFunctions and
add the corresponding visit methods in ScalarFunctionVisitor.

### Release note

None

### Check List (For Author)

- Test: No need to test (regression tests come in the next commit)
- Behavior changed: No
- Does this need documentation: No
…t_ymin

### What problem does this PR solve?

Issue Number: close apache#48203

Problem Summary:
Add regression test cases covering points (fn_test), polygons, literal
linestrings, invalid input (NULL result) and NULL input, following the
existing st_x/st_y test style in nereids_scalar_fn_S.

### Release note

None

### Check List (For Author)

- Test: Regression test (nereids_function_p0, S.groovy)
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: close apache#48203

Problem Summary:
The bounding_box() overrides were defined out-of-line in geo_types.cpp
but never declared in the GeoPoint/GeoLine/GeoPolygon/GeoMultiPolygon/
GeoCircle class bodies, which is ill-formed and fails to compile
("out-of-line definition does not match any declaration"). Add the
missing override declarations.

### Release note

None

### Check List (For Author)

- Test: No need to test (compile fix; regression tests already added)
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: close apache#48203

Problem Summary:
Add BE unit tests covering the bounding_box accessor for GeoPoint,
GeoLine and GeoPolygon, backing st_xmax/st_xmin/st_ymax/st_ymin.

### Release note

None

### Check List (For Author)

- Test: Unit test (GeoTypesTest)
- Behavior changed: No
- Does this need documentation: No
…dicated suite

### What problem does this PR solve?

Issue Number: close apache#48203

Problem Summary:
Move the bounding box accessor test cases from nereids_scalar_fn_S into
a dedicated st_bounding_box suite, so the suite owns a fresh auto-generated
.out file and the shared S.out is left untouched.

### Release note

None

### Check List (For Author)

- Test: Regression test (nereids_scalar_fn_st_bounding_box, passed)
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?

Issue Number: close apache#48203

Problem Summary:
clang-tidy (modernize-use-designated-initializers) requires designated
initializers for aggregate BoundingBox construction in GeoPoint and
GeoCircle bounding_box().

### Release note

None

### Check List (For Author)

- Test: No need to test (style fix, no behavior change)
- Behavior changed: No
- Does this need documentation: No
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@MiYuyuyuyu

Copy link
Copy Markdown
Author

Thank you for the guidance. Here is a clear description of this PR:

What problem was fixed

Doris does not provide the Trino-compatible bounding box accessor
functions st_xmax / st_xmin / st_ymax / st_ymin, which are
listed as open tasks in #48203 (Part III. Trino&Presto GEO FUNCTIONS).
Users migrating from Trino/Presto cannot run queries like
SELECT ST_XMax(geom) on Doris.

How it was fixed

  • BE: added a BoundingBox struct and a virtual GeoShape::bounding_box()
    accessor, implemented for GeoPoint, GeoLine, GeoPolygon,
    GeoMultiPolygon and GeoCircle (treated as its center point, since the
    exact bounding box depends on the projection). The four function
    structs (StXMax etc.) were added in functions_geo.cpp, decoding
    the input via GeoShape::from_encoded and returning NULL for invalid
    input.
  • FE: added the four Nereids scalar function signature classes
    (StXMax.java etc.) and registered them in BuiltinScalarFunctions
    and ScalarFunctionVisitor.
  • Tests: regression suite nereids_scalar_fn_st_bounding_box (14 cases)
    and BE unit tests GeoTypesTest.bounding_box_* (28 tests passed).

Which behaviors were modified

Before: the four functions did not exist; calling them produced a
"Can not found function" error. After: they return the bounding box
max/min X (longitude) / Y (latitude) of a geometry, and NULL for invalid
input or NULL input. No existing behavior is changed — all changes are
additive.

What features were added and why

Four new SQL functions compatible with Trino's geospatial functions
(see https://trino.io/docs/current/functions/geospatial.html), to ease
migration from Trino/Presto, as requested in #48203.

Refactoring / optimization

No existing code was refactored. The only shared change is the new
GeoShape::bounding_box() virtual accessor, designed as a single method
returning a BoundingBox struct to avoid duplicating the min/max
computation across the four functions.

Documentation PR: apache/doris-website#4065

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.

[Good First Issue] Support All SQL Functions in Other SQL System

2 participants