Skip to content

Commit 7e8f48a

Browse files
Krishna Paifacebook-github-bot
authored andcommitted
Backout ST_NumPoints function
Summary: Backing out the St_NumPoints function to fix unrecognized geometry fuzzer errors: https://github.com/facebookincubator/velox/actions/runs/16604171017/job/46974781558 . Differential Revision: D79218935
1 parent 13de155 commit 7e8f48a

File tree

4 files changed

+0
-147
lines changed

4 files changed

+0
-147
lines changed

velox/docs/functions/presto/geospatial.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ Accessors
211211
Returns an array of points in a geometry. Empty or null inputs
212212
return null.
213213

214-
.. function:: ST_NumPoints(geometry: Geometry) -> points: integer
215-
216-
Returns the number of points in a geometry. This is an extension
217-
to the SQL/MM ``ST_NumPoints`` function which only applies to
218-
point and linestring.
219-
220214
.. function:: geometry_nearest_points(geometry1: Geometry, geometry2: Geometry) -> points: array(geometry)
221215

222216
Returns the points on each geometry nearest the other. If either geometry

velox/functions/prestosql/GeometryFunctions.h

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,101 +1359,4 @@ struct StEnvelopeAsPtsFunction {
13591359
geos::geom::GeometryFactory::Ptr factory_;
13601360
};
13611361

1362-
template <typename T>
1363-
struct StNumPointsFunction {
1364-
VELOX_DEFINE_FUNCTION_TYPES(T);
1365-
1366-
FOLLY_ALWAYS_INLINE void call(
1367-
out_type<int32_t>& result,
1368-
const arg_type<Geometry>& geometry) {
1369-
auto geosGeometry = geospatial::GeometryDeserializer::deserialize(geometry);
1370-
1371-
result = pointCount(*geosGeometry);
1372-
}
1373-
1374-
private:
1375-
int32_t pointCount(const geos::geom::Geometry& geometry) {
1376-
if (geometry.isEmpty()) {
1377-
return 0;
1378-
}
1379-
if (geometry.getGeometryTypeId() ==
1380-
geos::geom::GeometryTypeId::GEOS_POINT) {
1381-
return 1;
1382-
}
1383-
if (geometry.getGeometryTypeId() ==
1384-
geos::geom::GeometryTypeId::GEOS_LINESTRING) {
1385-
return static_cast<int32_t>(geometry.getNumPoints());
1386-
}
1387-
if (geospatial::isMultiType(geometry)) {
1388-
auto numGeometries = geometry.getNumGeometries();
1389-
auto multiTypePointCount = 0;
1390-
for (int i = 0; i < numGeometries; i++) {
1391-
auto entry = geometry.getGeometryN(i);
1392-
multiTypePointCount += pointCount(*entry);
1393-
}
1394-
return multiTypePointCount;
1395-
}
1396-
if (geometry.getGeometryTypeId() ==
1397-
geos::geom::GeometryTypeId::GEOS_POLYGON) {
1398-
auto polygon = static_cast<const geos::geom::Polygon*>(&geometry);
1399-
// Subtract 1 to remove closing point, since we don't count the closing
1400-
// point in Java.
1401-
auto polygonPointCount = polygon->getExteriorRing()->getNumPoints() - 1;
1402-
for (int i = 0; i < polygon->getNumInteriorRing(); i++) {
1403-
auto interiorRing = polygon->getInteriorRingN(i);
1404-
polygonPointCount += interiorRing->getNumPoints() - 1;
1405-
}
1406-
return static_cast<int32_t>(polygonPointCount);
1407-
}
1408-
VELOX_FAIL(fmt::format(
1409-
"Unexpected failure in ST_NumPoints: geometry type {}",
1410-
geometry.getGeometryType()));
1411-
}
1412-
};
1413-
1414-
template <typename T>
1415-
struct GeometryNearestPointsFunction {
1416-
VELOX_DEFINE_FUNCTION_TYPES(T);
1417-
1418-
GeometryNearestPointsFunction() {
1419-
factory_ = geos::geom::GeometryFactory::create();
1420-
}
1421-
1422-
FOLLY_ALWAYS_INLINE bool call(
1423-
out_type<Array<Geometry>>& result,
1424-
const arg_type<Geometry>& leftGeometry,
1425-
const arg_type<Geometry>& rightGeometry) {
1426-
auto left = geospatial::GeometryDeserializer::deserialize(leftGeometry);
1427-
auto right = geospatial::GeometryDeserializer::deserialize(rightGeometry);
1428-
1429-
if (left->isEmpty() || right->isEmpty()) {
1430-
return false;
1431-
}
1432-
1433-
GEOS_RETHROW(
1434-
{
1435-
std::unique_ptr<geos::geom::CoordinateSequence> nearestCoordinates =
1436-
geos::operation::distance::DistanceOp::nearestPoints(
1437-
left.get(), right.get());
1438-
1439-
auto pointA =
1440-
std::unique_ptr<geos::geom::Point>(factory_->createPoint(
1441-
geos::geom::Coordinate(nearestCoordinates->getAt(0))));
1442-
auto pointB =
1443-
std::unique_ptr<geos::geom::Point>(factory_->createPoint(
1444-
geos::geom::Coordinate(nearestCoordinates->getAt(1))));
1445-
1446-
result.reserve(2);
1447-
geospatial::GeometrySerializer::serialize(*pointA, result.add_item());
1448-
geospatial::GeometrySerializer::serialize(*pointB, result.add_item());
1449-
},
1450-
"Failed to compute nearest points between geometries");
1451-
1452-
return true;
1453-
}
1454-
1455-
private:
1456-
geos::geom::GeometryFactory::Ptr factory_;
1457-
};
1458-
14591362
} // namespace facebook::velox::functions

velox/functions/prestosql/registration/GeometryFunctionsRegistration.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,6 @@ void registerAccessors(const std::string& prefix) {
136136
std::make_unique<StCoordDimFunction>());
137137
registerFunction<StPointsFunction, Array<Geometry>, Geometry>(
138138
{{prefix + "ST_Points"}});
139-
registerFunction<StNumPointsFunction, int32_t, Geometry>(
140-
{{prefix + "ST_NumPoints"}});
141-
registerFunction<
142-
GeometryNearestPointsFunction,
143-
Array<Geometry>,
144-
Geometry,
145-
Geometry>({{prefix + "geometry_nearest_points"}});
146139
}
147140

148141
} // namespace

velox/functions/prestosql/tests/GeometryFunctionsTest.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,43 +2476,6 @@ TEST_F(GeometryFunctionsTest, testStEnvelopeAsPts) {
24762476
testStEnvelopeAsPtsNullAndEmptyFunc(std::nullopt);
24772477
}
24782478

2479-
TEST_F(GeometryFunctionsTest, testStNumPoints) {
2480-
const auto testStNumPointsFunc = [&](const std::optional<std::string>& wkt,
2481-
const std::optional<int32_t>& expected) {
2482-
std::optional<int32_t> result =
2483-
evaluateOnce<int32_t>("ST_NumPoints(ST_GeometryFromText(c0))", wkt);
2484-
2485-
if (expected.has_value()) {
2486-
ASSERT_TRUE(result.has_value());
2487-
ASSERT_EQ(result.value(), expected.value());
2488-
} else {
2489-
ASSERT_FALSE(result.has_value());
2490-
}
2491-
};
2492-
2493-
testStNumPointsFunc("POINT EMPTY", 0);
2494-
testStNumPointsFunc("MULTIPOINT EMPTY", 0);
2495-
testStNumPointsFunc("LINESTRING EMPTY", 0);
2496-
testStNumPointsFunc("MULTILINESTRING EMPTY", 0);
2497-
testStNumPointsFunc("POLYGON EMPTY", 0);
2498-
testStNumPointsFunc("MULTIPOLYGON EMPTY", 0);
2499-
testStNumPointsFunc("GEOMETRYCOLLECTION EMPTY", 0);
2500-
2501-
testStNumPointsFunc("POINT (1 2)", 1);
2502-
testStNumPointsFunc("MULTIPOINT (1 2, 2 4, 3 6, 4 8)", 4);
2503-
testStNumPointsFunc("LINESTRING (8 4, 5 7)", 2);
2504-
testStNumPointsFunc("MULTILINESTRING ((1 1, 5 1), (2 4, 4 4))", 4);
2505-
testStNumPointsFunc("POLYGON ((0 0, 8 0, 0 8, 0 0))", 3);
2506-
testStNumPointsFunc(
2507-
"POLYGON ((0 0, 8 0, 0 8, 0 0), (1 1, 1 5, 5 1, 1 1))", 6);
2508-
testStNumPointsFunc(
2509-
"MULTIPOLYGON (((1 1, 1 3, 3 3, 3 1, 1 1)), ((2 4, 2 6, 6 6, 6 4, 2 4)))",
2510-
8);
2511-
testStNumPointsFunc(
2512-
"GEOMETRYCOLLECTION (POINT (1 1), GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1), GEOMETRYCOLLECTION (POLYGON ((2 2, 2 3, 3 3, 3 2, 2 2)))))",
2513-
7);
2514-
}
2515-
25162479
TEST_F(GeometryFunctionsTest, testGeometryNearestPoints) {
25172480
const auto testGeometryNearestPointsFunc = [&](const std::optional<
25182481
std::string>& wkt1,

0 commit comments

Comments
 (0)