Hello Jason Fehr, Balazs Hevele, Impala Public Jenkins,
I'd like you to reexamine a change. Please visit
https://gerrit.cloudera.org/24540
to look at the new patch set (#19).
Change subject: POC IMPALA-15164: Port native C++ geospatial functions to WKB
mode
......................................................................
POC IMPALA-15164: Port native C++ geospatial functions to WKB mode
Implement native C++ ST_ geospatial functions for WKB_EXPERIMENTAL mode
so they no longer fall back to the Java (ESRI) implementations. Builds on
the WKB serialization foundation (common.h / wkb-format.h /
wkb-serialization.*) added by IMPALA-15165. Kept as a single commit; it
can be split further later if desired.
Adds:
- geometry-wrapper-wkb.{h,cc}: GeometryWrapperWkb -- deserializes WKB into
boost::geometry types and back, and hosts the geometry property methods
(Area/Length/Distance/Centroid/...).
- relation-wrapper-wkb.{h,cc} (+ relation-wrapper-wkb-test.cc): native
relation predicates (Contains/Crosses/Disjoint/Equals/Intersects/
Overlaps/Touches/Within), with C++ unit coverage.
- geospatial-functions-wkb-ir.cc: the _WKB IR entry points -- accessors,
constructors, predicates, transformations, binning and properties.
- wkt.h: WKT read helpers; bin-utils.h: ST_Bin binning helpers.
- The switch over OGCType exists once, in GeometryWrapperWkb::Visit();
Dispatch<XAccessor>() is sugar over it for the stateless accessors, one
ACCESSOR() line each, and the relation predicates get their 6x6 dispatch
from two nested Visit() calls.
- GeospatialBuiltins.addWkbNatives(): registers the natives in
WKB_EXPERIMENTAL mode; functions not registered fall back to Java.
- impala-ir.cc include + scalar-expr-evaluator force-refs so the IR is
compiled into the codegen module and not stripped.
New geo files use the bg:: alias (= boost::geometry) to match common.h.
Invalid coordinate lists passed to the varargs constructors (odd length,
or fewer than 3 points for a polygon) return NULL rather than raising an
error, matching the ESRI UDFs, which only log a warning.
boost::geometry can throw: bg::read_wkt on malformed WKT, bg::centroid on an
empty geometry, bg::distance on an empty operand, bg::is_simple on a
degenerate linestring. Its turn based algorithms also collect intersections
into containers sized by the input, so they can raise std::bad_alloc for a
pathological geometry. Every boost call is therefore made from a translation
unit that is NOT cross compiled to LLVM IR, and caught there: the IR module is
compiled with -DBOOST_NO_EXCEPTIONS, where BOOST_THROW_EXCEPTION does not
throw but aborts via LOG(FATAL), so a try/catch in
geospatial-functions-wkb-ir.cc would silently never run. wkt.cc exists only to
keep wktToPoint() out of line for that reason.
Empty points: WKB cannot represent POINT EMPTY, since a WKB point is
exactly one coordinate tuple, so it is NaN encoded -- the convention
PostGIS and GeoPackage use, and which other WKB readers understand. boost
cannot recognize it, as bg::is_empty() is always_not_empty for point_tag
and bg::num_points() structurally counts 1, so IsEmptyPoint() checks it
explicitly. ST_IsEmpty, ST_NumPoints, ST_AsText and ST_Centroid of an empty
point therefore match both OGC and the HIVE_ESRI mode.
The coordinates of an empty point, and the bounding box of any empty
geometry, are NULL instead: ST_X, ST_Y, ST_MinX, ST_MinY, ST_MaxX, ST_MaxY
and ST_Envelope, following OGC and PostGIS. This is a deliberate divergence
from HIVE_ESRI, which returns the ESRI shape format's "no data" value, so
these cases are tested per mode instead of in the shared test file.
Tests:
- relation-wrapper-wkb-test.cc: C++ coverage of the relation predicates
and of the boost::geometry gaps they work around.
- The existing geospatial tests now exercise the native path in the
default WKB_EXPERIMENTAL mode, including geospatial-relations-table
over functional.geom_relations_wkt (test_geospatial_functions.py).
- test_geospatial_library.py is reorganized into one class per
--geospatial_library mode.
- Empty point cases: the ones both modes agree on (ST_IsEmpty,
ST_NumPoints, ST_AsText, ST_Centroid) in the shared geospatial-esri.test,
the WKB specific ones (NULL coordinates and bounding box) in
geometry-type.test.
Change-Id: I0047acebd4aaa774bf6bb8ec0618515d38ad6aae
Assisted-by: Claude Opus 4.8 (Claude Code)
---
M be/src/codegen/impala-ir.cc
M be/src/exprs/geo/CMakeLists.txt
A be/src/exprs/geo/bin-utils.h
M be/src/exprs/geo/boost-common.h
M be/src/exprs/geo/common.h
A be/src/exprs/geo/geometry-wrapper-wkb.cc
A be/src/exprs/geo/geometry-wrapper-wkb.h
A be/src/exprs/geo/geospatial-functions-wkb-ir.cc
M be/src/exprs/geo/geospatial-functions.h
A be/src/exprs/geo/relation-wrapper-wkb-test.cc
A be/src/exprs/geo/relation-wrapper-wkb.cc
A be/src/exprs/geo/relation-wrapper-wkb.h
M be/src/exprs/geo/wkb-format.h
A be/src/exprs/geo/wkt.cc
A be/src/exprs/geo/wkt.h
M be/src/exprs/scalar-expr-evaluator.cc
M fe/src/compat-hive-3/java/org/apache/impala/compat/GeospatialBuiltins.java
M testdata/workloads/functional-query/queries/QueryTest/geometry-type.test
M testdata/workloads/functional-query/queries/QueryTest/geospatial-esri.test
M tests/custom_cluster/test_geospatial_library.py
20 files changed, 2,564 insertions(+), 74 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/40/24540/19
--
To view, visit https://gerrit.cloudera.org/24540
To unsubscribe, visit https://gerrit.cloudera.org/settings
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I0047acebd4aaa774bf6bb8ec0618515d38ad6aae
Gerrit-Change-Number: 24540
Gerrit-PatchSet: 19
Gerrit-Owner: Csaba Ringhofer <[email protected]>
Gerrit-Reviewer: Balazs Hevele <[email protected]>
Gerrit-Reviewer: Csaba Ringhofer <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Jason Fehr <[email protected]>