Skip to content

HIVE-29698: Replace ESRI geometry library with JTS in geospatial plugin#6581

Open
ayushtkn wants to merge 1 commit into
apache:masterfrom
ayushtkn:HIVE-29698
Open

HIVE-29698: Replace ESRI geometry library with JTS in geospatial plugin#6581
ayushtkn wants to merge 1 commit into
apache:masterfrom
ayushtkn:HIVE-29698

Conversation

@ayushtkn

@ayushtkn ayushtkn commented Jul 6, 2026

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

Migrate the geospatial plugin from ESRI geometry-api-java to JTS (Java Topology Suite) as the core geometry library

Why are the changes needed?

JTS is more widely used, better maintained, and provides the foundation for upcoming Iceberg geometry type support.

Does this PR introduce any user-facing change?

No

How was this patch tested?

CI & Manually on docker

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates Hive’s geospatial (Esri-json / ST_* UDF) implementation to use JTS (Java Topology Suite) as the primary geometry model, while retaining Esri JSON/shape interoperability where required. It updates serialization/deserialization, rewires many UDFs to JTS operations, and adjusts tests/results to match JTS output.

Changes:

  • Replace many com.esri.* geometry usages in UDFs/SerDes with org.locationtech.jts.* equivalents, including prepared-geometry acceleration for relational predicates.
  • Introduce JTS-based Esri JSON conversion (EsriJsonConverter) and adjust Esri JSON factory/feature-class mapping.
  • Update Maven dependencies (add JTS) and refresh golden test outputs for geospatial UDFs.

Reviewed changes

Copilot reviewed 111 out of 111 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
serde/src/java/org/apache/hadoop/hive/serde2/esriJson/serializer/SpatialReferenceJsonSerializer.java Serialize WKID as JSON spatialReference object for JTS-based model.
serde/src/java/org/apache/hadoop/hive/serde2/esriJson/serializer/GeometryTypeJsonSerializer.java Serialize Esri geometryType as a canonical esriGeometry* string.
serde/src/java/org/apache/hadoop/hive/serde2/esriJson/serializer/GeometryJsonSerializer.java Serialize JTS Geometry to Esri JSON via WKB round-trip through Esri engine.
serde/src/java/org/apache/hadoop/hive/serde2/esriJson/deserializer/SpatialReferenceJsonDeserializer.java Parse spatialReference object into integer WKID.
serde/src/java/org/apache/hadoop/hive/serde2/esriJson/deserializer/GeometryTypeJsonDeserializer.java Parse geometryType JSON string into canonical esriGeometry* string.
serde/src/java/org/apache/hadoop/hive/serde2/esriJson/deserializer/GeometryJsonDeserializer.java Parse Esri JSON to JTS Geometry via Esri parser + WKB conversion.
serde/pom.xml Add jts-core dependency for serde module.
ql/src/test/results/clientpositive/llap/geospatial_udfs.q.out Update expected outputs due to JTS numeric formatting / geometry differences.
ql/src/test/queries/clientpositive/geospatial_udfs.q Add output normalization for floating-point stability across JDKs.
ql/src/test/org/apache/hadoop/hive/ql/udf/esri/TestStGeomFromShape.java Update tests to assert JTS geometry properties/SRID instead of Esri geometry equality.
ql/src/test/org/apache/hadoop/hive/ql/udf/esri/TestStCentroid.java Update centroid assertions to compare numeric coordinates rather than Esri Point.
ql/src/test/org/apache/hadoop/hive/ql/udf/esri/serde/TestGeoJsonSerDe.java Update SerDe tests to construct expected geometries using JTS.
ql/src/test/org/apache/hadoop/hive/ql/udf/esri/serde/TestEsriJsonSerDe.java Update Esri JSON SerDe tests to use JTS geometry creation.
ql/src/test/org/apache/hadoop/hive/ql/udf/esri/serde/JsonSerDeTestingBase.java Update SerDe test helpers to validate JTS geometry outputs.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Z.java Switch Z-accessor to JTS coordinate Z handling.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Y.java Switch Y-accessor to JTS point Y.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_X.java Switch X-accessor to JTS point X.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Within.java Implement within using JTS (and prepared geometry path).
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Union.java Implement union using JTS UnaryUnionOp.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Touches.java Implement touches using JTS (and prepared geometry path).
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_SymmetricDiff.java Implement symmetric difference using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_StartPoint.java Implement start point extraction using JTS LineString.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Relate.java Implement DE-9IM relate using JTS relate.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Polygon.java Construct/parse polygon via JTS WKT reader and type checks.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_PolyFromWKB.java Parse polygon from WKB using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_PointZ.java Construct Z/M point using JTS coordinate variants.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_PointN.java Extract Nth point from line/multipoint using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_PointFromWKB.java Parse point from WKB using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Point.java Construct/parse point using JTS coordinates and WKT reader.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Overlaps.java Implement overlaps using JTS (and prepared geometry path).
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_NumPoints.java Use JTS getNumPoints().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_NumInteriorRing.java Use JTS polygon interior ring count.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_NumGeometries.java Use JTS getNumGeometries() for multi-geometries.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MultiPolygon.java Parse MultiPolygon via JTS WKT reader.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MultiPoint.java Construct/parse MultiPoint via JTS geometry factory / WKT reader.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MultiLineString.java Construct/parse MultiLineString via JTS geometry factory / WKT reader.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MPolyFromWKB.java Parse multi-polygon from WKB using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MPointFromWKB.java Parse multi-point from WKB using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MLineFromWKB.java Parse multi-line from WKB using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MinZ.java Compute min Z by iterating coordinates in JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MinY.java Use JTS envelope minY; handle empty geometry.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MinX.java Use JTS envelope minX; handle empty geometry.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MinM.java Compute min M by iterating coordinates in JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MaxZ.java Compute max Z by iterating coordinates in JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MaxY.java Use JTS envelope maxY; handle empty geometry.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MaxX.java Use JTS envelope maxX; handle empty geometry.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MaxM.java Compute max M by iterating coordinates in JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_M.java Read M ordinate from JTS point coordinate.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_LineString.java Construct/parse LineString using JTS geometry factory / WKT reader.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_LineFromWKB.java Parse LineString from WKB using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Length.java Use JTS getLength().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_IsSimple.java Use JTS isSimple().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_IsRing.java Implement ring check using JTS LineString.isClosed/isSimple.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_IsMeasured.java Implement measured check using JTS coordinate ordinates.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_IsEmpty.java Use JTS isEmpty().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_IsClosed.java Implement closed check for LineString/MultiLineString using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Is3D.java Implement 3D check using JTS coordinate ordinates.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Intersects.java Implement intersects using JTS (and prepared geometry path).
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Intersection.java Implement intersection using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_InteriorRingN.java Extract polygon hole ring using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeomFromWKB.java Parse arbitrary geometry from WKB using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeomFromText.java Parse WKT into JTS geometry and set SRID.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeomFromShape.java Convert Esri shape bytes to JTS geometry via converter.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeomFromJson.java Parse Esri JSON to JTS via converter and add cleanup on close.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeomFromGeoJson.java Parse GeoJSON to JTS via GeoJSON reader and add cleanup on close.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeometryRelational.java Replace Esri acceleration with JTS PreparedGeometry.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeometryN.java Implement geometryN extraction via JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeomCollection.java Parse geometry collections via JTS WKT reader.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeodesicLengthWGS84.java Reimplement geodesic length using JTS coordinate sequences + Haversine.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_ExteriorRing.java Return exterior ring as LineString using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Equals.java Implement topological equality via JTS equalsTopo.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_EnvIntersects.java Implement envelope intersects via JTS envelopes.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Envelope.java Return envelope geometry using JTS getEnvelope().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_EndPoint.java Implement end point extraction using JTS LineString.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_DistanceSphere.java Compute great-circle distance using JTS points + Haversine.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Distance.java Implement distance using JTS distance().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Disjoint.java Implement disjoint using JTS (and prepared geometry path).
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Dimension.java Use JTS getDimension().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Difference.java Implement difference using JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Crosses.java Implement crosses using JTS (and prepared geometry path).
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_CoordDim.java Infer coordinate dimension using JTS coordinate Z/M.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_ConvexHull.java Implement convex hull using JTS (with GeometryCollection fallback).
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Contains.java Implement contains using JTS (and prepared geometry path).
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Centroid.java Implement centroid using JTS getCentroid().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Buffer.java Implement buffer using JTS buffer().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Boundary.java Implement boundary using JTS and normalize LinearRing to LineString.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_BinEnvelope.java Use JTS Envelope and return polygon geometry for bins.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Bin.java Use JTS Point to compute bin IDs.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_AsText.java Output WKT via JTS writers and normalize dimension spacing.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_AsShape.java Convert JTS geometry to Esri shape bytes via converter.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_AsJson.java Convert JTS geometry to Esri JSON via converter.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_AsGeoJson.java Output GeoJSON using JTS GeoJSON writer.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_AsBinary.java Output WKB using dimension-aware JTS writer.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Area.java Use JTS getArea().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Aggr_Union.java Aggregate union using JTS UnaryUnionOp.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Aggr_Intersection.java Aggregate intersection using iterative JTS intersections.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Aggr_ConvexHull.java Aggregate convex hull using JTS GeometryCollection.convexHull().
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/serde/GeoJsonSerDe.java Update GeoJSON SerDe to use JTS readers/writers.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/serde/EsriJsonSerDe.java Update Esri JSON SerDe to use EsriJsonConverter for parsing/serialization.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/serde/BaseJsonSerDe.java Generalize SerDe base from OGCGeometry to JTS Geometry.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/HiveGeometryOIHelper.java Update OI helper to return JTS Geometry/Point and parse WKT via JTS.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/Haversine.java Switch distance helper from Esri OGCPoint to JTS Point.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/EsriJsonConverter.java Add standalone JTS <-> Esri JSON conversion without ESRI geometry library dependency.
ql/src/java/org/apache/hadoop/hive/ql/udf/esri/BinUtils.java Switch bin envelope type to JTS Envelope and adjust query methods to return envelopes.
ql/src/java/org/apache/hadoop/hive/ql/io/esriJson/EsriJsonFactory.java Register only Geometry (JTS) serializers/deserializers; move other mappings to field annotations.
ql/src/java/org/apache/hadoop/hive/ql/io/esriJson/EsriFeatureClass.java Update feature-class schema to use String geometryType + int WKID with field-level (de)serializers.
ql/src/java/org/apache/hadoop/hive/ql/io/esriJson/EsriFeature.java Switch feature geometry field to JTS Geometry.
ql/pom.xml Replace ESRI dependency with JTS core + io-common in ql module and shade includes.
pom.xml Add jts.version property.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_PointFromWKB.java Outdated
Comment thread ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_LineFromWKB.java Outdated
Comment thread ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeomFromWKB.java Outdated
Comment thread ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_GeomFromShape.java Outdated
Comment thread ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_Is3D.java Outdated
Comment thread ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MLineFromWKB.java Outdated
Comment thread ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MPointFromWKB.java Outdated
Comment thread ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_MPolyFromWKB.java Outdated
Comment thread ql/src/java/org/apache/hadoop/hive/ql/udf/esri/ST_PolyFromWKB.java Outdated
@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants