Skip to content

Commit 3debc3b

Browse files
Patrick Sullivanmeta-codesync[bot]
authored andcommitted
fix: Use envelope serde in ST_Envelope (#15349)
Summary: Pull Request resolved: #15349 This led to a discrepency between java and C++ where java would happily build an envelope from an invalid polygon and C++ would fail. Reviewed By: kgpai, jagill Differential Revision: D85973036 fbshipit-source-id: fca3d81fec0722c15ed10ec1281ae90088251050
1 parent d2a6822 commit 3debc3b

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

velox/functions/prestosql/GeometryFunctions.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,22 +1249,10 @@ struct StEnvelopeFunction {
12491249

12501250
FOLLY_ALWAYS_INLINE Status
12511251
call(out_type<Geometry>& result, const arg_type<Geometry>& geometry) {
1252-
std::unique_ptr<const geos::geom::Geometry> geosGeometry =
1253-
geospatial::GeometryDeserializer::deserialize(geometry);
1254-
1255-
auto env = geosGeometry->getEnvelope();
1256-
1257-
if (env->isEmpty()) {
1258-
GEOS_TRY(
1259-
{
1260-
auto polygon =
1261-
std::unique_ptr<geos::geom::Polygon>(factory_->createPolygon());
1262-
geospatial::GeometrySerializer::serialize(*polygon, result);
1263-
},
1264-
"Failed to create empty polygon in ST_Envelope");
1265-
}
1252+
std::unique_ptr<geos::geom::Envelope> env =
1253+
geospatial::GeometryDeserializer::deserializeEnvelope(geometry);
12661254

1267-
geospatial::GeometrySerializer::serialize(*env, result);
1255+
geospatial::GeometrySerializer::serializeEnvelope(*env, result);
12681256

12691257
return Status::OK();
12701258
}

velox/functions/prestosql/tests/GeometryFunctionsTest.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@ TEST_F(GeometryFunctionsTest, testStEnvelope) {
23022302
[&](const std::optional<std::string>& wkt,
23032303
const std::optional<std::string>& expected) {
23042304
std::optional<std::string> result = evaluateOnce<std::string>(
2305-
"ST_AsText(ST_Envelope(ST_GeometryFromText(c0)))", wkt);
2305+
"ST_AsText(st_envelope(ST_GeometryFromText(c0)))", wkt);
23062306

23072307
if (expected.has_value()) {
23082308
ASSERT_TRUE(result.has_value());
@@ -2314,7 +2314,6 @@ TEST_F(GeometryFunctionsTest, testStEnvelope) {
23142314

23152315
testStEnvelopeFunc(
23162316
"MULTIPOINT (1 2, 2 4, 3 6, 4 8)", "POLYGON ((1 2, 1 8, 4 8, 4 2, 1 2))");
2317-
testStEnvelopeFunc("LINESTRING EMPTY", "POLYGON EMPTY");
23182317
testStEnvelopeFunc(
23192318
"LINESTRING (1 1, 2 2, 1 3)", "POLYGON ((1 1, 1 3, 2 3, 2 1, 1 1))");
23202319
testStEnvelopeFunc(
@@ -2330,6 +2329,17 @@ TEST_F(GeometryFunctionsTest, testStEnvelope) {
23302329
testStEnvelopeFunc(
23312330
"GEOMETRYCOLLECTION (POINT (5 1), LINESTRING (3 4, 4 4))",
23322331
"POLYGON ((3 1, 3 4, 5 4, 5 1, 3 1))");
2332+
testStEnvelopeFunc(
2333+
"MULTIPOLYGON (((119.094024 -27.2871725, 119.094024 -27.2846569, 119.094024 -27.2868119, 119.094024 -27.2871725)))",
2334+
"POLYGON ((119.094024 -27.2871725, 119.094024 -27.2846569, 119.094024 -27.2846569, 119.094024 -27.2871725, 119.094024 -27.2871725))");
2335+
2336+
testStEnvelopeFunc("POLYGON EMPTY", "POLYGON EMPTY");
2337+
testStEnvelopeFunc("MULTIPOLYGON EMPTY", "POLYGON EMPTY");
2338+
testStEnvelopeFunc("GEOMETRYCOLLECTION EMPTY", "POLYGON EMPTY");
2339+
testStEnvelopeFunc("POINT EMPTY", "POLYGON EMPTY");
2340+
testStEnvelopeFunc("MULTIPOINT EMPTY", "POLYGON EMPTY");
2341+
testStEnvelopeFunc("LINESTRING EMPTY", "POLYGON EMPTY");
2342+
testStEnvelopeFunc("MULTILINESTRING EMPTY", "POLYGON EMPTY");
23332343
}
23342344

23352345
TEST_F(GeometryFunctionsTest, testStPoints) {

0 commit comments

Comments
 (0)