Repository navigation
Conversation
ST_KNN(a, b, k, use_spheroid) ranked geometries by a distance on the sphere while the join indexed and partitioned them by their coordinates in degrees. It could return a farther neighbor across the antimeridian and measured every object for each query. ST_KNN now has the three-argument form only and ranks geometries by their distance in the plane. Geography columns rank on the sphere. The distance metric goes from the join as well: the three KNN join nodes, JoinQuery.KNNJoinQuery and JoinParams, KnnJoinIndexJudgement and InMemoryKNNJoinIterator, with the classes DistanceMetric, HaversineItemDistance and SpheroidDistance. The local outlier factor raises an error when useSphere is true.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes Remove use_spheroid from ST_KNN on geometries #3635. Closes ST_KNN with use_spheroid = true can return a farther neighbor across the antimeridian, and its index search measures every object #3634What changes were proposed in this PR?
ST_KNNon geometries loses its fourth argument,use_spheroid. It ranks geometries by their distance in the plane, in the units of the coordinates:With
use_spheroidset totruethe join ranked the neighbors by a distance in meters, while it indexed and partitioned the objects by their coordinates in degrees. It could return a farther neighbor when a nearer one was on the other side of the antimeridian or was written in the other longitude convention, and the search of the index measured every object for each query (#3634). Geography columns rank on the sphere with an index made for it, so that is where a distance on the sphere goes:ST_KNN(ST_GeomToGeography(a), ST_GeomToGeography(b), k)reads two geometry columns as geographies. A geographyST_KNNjoin is a broadcast join.ST_KNN(a, b, k).What is removed:
ST_KNN(a, b, k, false)andST_KNN(a, b, k, true)fail at analysis with "no overloaded function accepts 4 arguments".ST_KNN(a, b, k, useSphere)with columns and with names.KNNJoinExec,BroadcastQuerySideKNNJoinExec,BroadcastObjectSideKNNJoinExec) no longer takeisGeography.JoinQuery.KNNJoinQueryandJoinQuery.JoinParamsno longer take aDistanceMetric, and the classesDistanceMetric,HaversineItemDistanceandSpheroidDistanceare deleted.KnnJoinIndexJudgementandInMemoryKNNJoinIteratormeasure withEuclideanItemDistanceonly.KNNJoinQueryis not in the documentation and has no Python or R wrapper.What follows from it:
useSphereon toST_KNN.ST_LocalOutlierFactor(geometry, k, useSphere),localOutlierFactorandlocal_outlier_factorkeep the parameter and raise anIllegalArgumentExceptionwhen it istrue. The message says to transform the geometries to a projected coordinate reference system first.sjoin_nearestpassedfalseas the fourth argument and now calls the three-argument form.#3630 then adds
include_tie_breakersas the fourth argument for geometries, as for geographies.How was this patch tested?
KnnJoinSuite: a new test thatST_KNN(geom, geom, k, true)andST_KNN(geom, geom, k, false)fail at analysis. The other tests call the three-argument form. The test of the sphere ranking is removed, and the test of empty geometries no longer runs once per metric.KnnJoinGeographySuite: a new test of the replacement. With the points of ST_KNN with use_spheroid = true can return a farther neighbor across the antimeridian, and its index search measures every object #3634 as geometry columns,ST_KNN(ST_GeomToGeography(qgeom), ST_GeomToGeography(ogeom), 2)returns the object that is 22 m away on the other side of the antimeridian and the one that is 111 m away.LocalOutlierFactorTest: a new test thatuseSphere = trueraises an error that names the parameter.KnnJoinQueryTest,KnnShapeBindingTestandBarrierFunctionTestfollow the new signatures.The new rejection test and the outlier factor test fail without the change. The test of the replacement passes without it too. These suites and
GeoStatsSuitepass on Spark 3.5 with Scala 2.12 and on Spark 4.0 with Scala 2.13. The wholespark/commonmodule on Spark 3.5 passes locally except for 12 tests that need the libpostal data directory or Docker. The Python tests were not run locally. The documentation builds, and the new links between the pages resolve in English and in Chinese.Did this PR include necessary documentation updates?
docs/api/sql/NearestNeighbourSearching.mdand its.zh.mdversion, a section indocs/setup/migration-2.0.md,useSphereondocs/api/sql/Clustering-Functions/ST_LocalOutlierFactor.mdand ondocs/api/stats/sql.mdwith its.zh.mdversion, and theST_KNNcalls of the notebookdocs/usecases/03-fire-risk-fusion.ipynb.