Copilot commented on code in PR #2854:
URL: https://github.com/apache/sedona/pull/2854#discussion_r3125554667
##########
spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala:
##########
@@ -247,7 +247,9 @@ private[apache] case class ST_Expand(inputExpressions:
Seq[Expression])
* @param inputExpressions
*/
private[apache] case class ST_Length(inputExpressions: Seq[Expression])
- extends InferredExpression(Functions.length _) {
+ extends InferredExpression(
+ inferrableFunction1(Functions.length),
+
inferrableFunction1(org.apache.sedona.common.geography.Functions.length)) {
Review Comment:
The Scaladoc for ST_Length still says it returns the length of a Geometry,
but this expression now also dual-dispatches to Geography. Update the comment
to reflect the Geography behavior (geodesic length on WGS84 spheroid, meters)
so Spark SQL users aren’t misled by the inline docs.
##########
spark/common/src/test/scala/org/apache/sedona/sql/geography/GeographyFunctionTest.scala:
##########
@@ -89,10 +89,26 @@ class GeographyFunctionTest extends TestBaseScala {
}
}
- // ─── Level 2: ST_Distance ──────────────────────────────────────────────
+ // ─── Level 2: ST_Length, ST_Distance ───────────────────────────────────
describe("Level 2: Geodesic metrics") {
Review Comment:
The class-level comment says Level 2 is represented by ST_Distance, but this
test suite now also covers ST_Length. Please update the header comment/docs to
include ST_Length as a Level 2 representative to keep the test documentation
accurate.
##########
docs/api/sql/geography/Geography-Functions/ST_Length.md:
##########
@@ -0,0 +1,44 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+# ST_Length
+
+Introduction: Returns the geodesic length of a geography object in meters,
calculated on the WGS84 spheroid using GeographicLib. Only linestring and
multilinestring geographies have non-zero length. Returns 0 for points and
polygons.
Review Comment:
The introduction claims only LineString/MultiLineString geographies have
non-zero length, but Geography also supports GEOMETRYCOLLECTION and ST_Length
will return the sum of linear components for collections containing lines.
Update the wording to include geography collections (or clarify that the rule
applies to non-collection types) to avoid incorrect docs.
```suggestion
Introduction: Returns the geodesic length of a geography object in meters,
calculated on the WGS84 spheroid using GeographicLib. Linestring and
multilinestring geographies have non-zero length, and geometrycollection
geographies return the sum of the lengths of their linear components. Returns 0
for points and polygons.
```
##########
common/src/main/java/org/apache/sedona/common/geography/Functions.java:
##########
@@ -87,6 +88,12 @@ public static int nPoints(Geography g) {
// ─── Level 2: JTS + S2 geodesic metrics ──────────────────────────────────
+ /** Geodesic length in meters (WGS84 spheroid). Returns 0 for non-linear
geographies. */
+ public static double length(Geography g) {
+ if (g == null) return 0.0;
+ return Spheroid.length(toJTS(g));
+ }
Review Comment:
The section header says “JTS + S2 geodesic metrics”, but the new length()
implementation uses the WGS84 spheroid (GeographicLib via Spheroid), not S2.
Consider renaming this section header (or adding a brief note) so it doesn’t
imply ST_Length is S2-based.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]