This is an automated email from the ASF dual-hosted git repository.
ayushsaxena pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 5bf845422da HIVE-29323: st_convexhull shouldn't return multipolygon
(#6201)
5bf845422da is described below
commit 5bf845422dabce8b3d5d2806d6a47e458c636278
Author: Ayush Saxena <[email protected]>
AuthorDate: Wed Nov 19 23:19:28 2025 +0530
HIVE-29323: st_convexhull shouldn't return multipolygon (#6201)
---
.../hadoop/hive/ql/udf/esri/GeometryUtils.java | 10 ++++-
.../test/queries/clientpositive/geospatial_udfs.q | 24 ++++++-----
.../clientpositive/llap/geospatial_udfs.q.out | 49 +++++++++++++++++++++-
3 files changed, 70 insertions(+), 13 deletions(-)
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/esri/GeometryUtils.java
b/ql/src/java/org/apache/hadoop/hive/ql/udf/esri/GeometryUtils.java
index a18785c9a35..fc7279e3655 100755
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/esri/GeometryUtils.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/esri/GeometryUtils.java
@@ -21,6 +21,7 @@
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.MapGeometry;
import com.esri.core.geometry.OperatorImportFromESRIShape;
+import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.geometry.ogc.OGCGeometry;
import com.google.common.cache.Cache;
@@ -194,7 +195,14 @@ public static void setWKID(BytesWritable geomref, int
wkid) {
public static OGCType getInferredOGCType(Geometry geom) {
switch (geom.getType()) {
case Polygon:
- return OGCType.ST_MULTIPOLYGON;
+ Polygon poly = (Polygon) geom;
+ // Number of outer rings defines single vs multi
+ int ringCount = poly.getExteriorRingCount();
+ if (ringCount == 1) {
+ return OGCType.ST_POLYGON;
+ } else {
+ return OGCType.ST_MULTIPOLYGON;
+ }
case Polyline:
return OGCType.ST_MULTILINESTRING;
case MultiPoint:
diff --git a/ql/src/test/queries/clientpositive/geospatial_udfs.q
b/ql/src/test/queries/clientpositive/geospatial_udfs.q
index 1f7d055fb27..7eee2a72505 100644
--- a/ql/src/test/queries/clientpositive/geospatial_udfs.q
+++ b/ql/src/test/queries/clientpositive/geospatial_udfs.q
@@ -148,16 +148,18 @@ select ST_Relate(geom, ST_Polygon(1, 1, 1, 4, 4, 4, 4,
1), '****T****'),
from geom_binary
where id = 25;
+select ST_AsText(ST_ConvexHull(ST_GeomFromText('multipoint ((0 0), (2 0), (2
2), (0 2), (1 1))')));
+SELECT ST_AsText(
+ ST_Union(
+ ST_GeomFromText('polygon ((0 0, 2 0, 2 2, 0 2, 0 0))'),
+ ST_GeomFromText('polygon ((10 10, 12 10, 12 12, 10 12, 10 10))')
+ )
+);
-
-
-
-
-
-
-
-
-
-
-
+SELECT ST_AsText(
+ ST_Union(
+ ST_GeomFromText('polygon ((0 0, 5 0, 5 5, 0 5, 0 0))'),
+ ST_GeomFromText('point (2 2)')
+ )
+);
\ No newline at end of file
diff --git a/ql/src/test/results/clientpositive/llap/geospatial_udfs.q.out
b/ql/src/test/results/clientpositive/llap/geospatial_udfs.q.out
index 8184bd6c607..7e44c58cba0 100644
--- a/ql/src/test/results/clientpositive/llap/geospatial_udfs.q.out
+++ b/ql/src/test/results/clientpositive/llap/geospatial_udfs.q.out
@@ -379,7 +379,7 @@ where id = 14
POSTHOOK: type: QUERY
POSTHOOK: Input: default@geom_binary
#### A masked pattern was here ####
-MULTIPOLYGON (((5 6, 0 1, 1 1, 5 6)))
+POLYGON ((5 6, 0 1, 1 1, 5 6))
PREHOOK: query: select ST_IsClosed(geom)
from geom_binary
where id = 16 OR id = 17 OR id =18
@@ -469,3 +469,50 @@ POSTHOOK: type: QUERY
POSTHOOK: Input: default@geom_binary
#### A masked pattern was here ####
true false
+PREHOOK: query: select ST_AsText(ST_ConvexHull(ST_GeomFromText('multipoint ((0
0), (2 0), (2 2), (0 2), (1 1))')))
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: select ST_AsText(ST_ConvexHull(ST_GeomFromText('multipoint
((0 0), (2 0), (2 2), (0 2), (1 1))')))
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))
+PREHOOK: query: SELECT ST_AsText(
+ ST_Union(
+ ST_GeomFromText('polygon ((0 0, 2 0, 2 2, 0 2, 0 0))'),
+ ST_GeomFromText('polygon ((10 10, 12 10, 12 12, 10 12, 10 10))')
+ )
+)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT ST_AsText(
+ ST_Union(
+ ST_GeomFromText('polygon ((0 0, 2 0, 2 2, 0 2, 0 0))'),
+ ST_GeomFromText('polygon ((10 10, 12 10, 12 12, 10 12, 10 10))')
+ )
+)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+MULTIPOLYGON (((0 0, 2 0, 2 2, 0 2, 0 0)), ((10 10, 12 10, 12 12, 10 12, 10
10)))
+PREHOOK: query: SELECT ST_AsText(
+ ST_Union(
+ ST_GeomFromText('polygon ((0 0, 5 0, 5 5, 0 5, 0 0))'),
+ ST_GeomFromText('point (2 2)')
+ )
+)
+PREHOOK: type: QUERY
+PREHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT ST_AsText(
+ ST_Union(
+ ST_GeomFromText('polygon ((0 0, 5 0, 5 5, 0 5, 0 0))'),
+ ST_GeomFromText('point (2 2)')
+ )
+)
+POSTHOOK: type: QUERY
+POSTHOOK: Input: _dummy_database@_dummy_table
+#### A masked pattern was here ####
+POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))