-
Notifications
You must be signed in to change notification settings - Fork 760
[GH-2830] Add broadcast spatial-join support for the Geography type with ST_Contains #2864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zhangfengcdt
merged 4 commits into
apache:master
from
zhangfengcdt:feature/geography.spatialjoin.bc
Apr 29, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
731ed3f
[GH-2830] Add broadcast spatial-join support for the Geography type w…
zhangfengcdt f1418eb
add test without using bc hint
zhangfengcdt 1c057af
Merge remote-tracking branch 'origin/master' into feature/geography.s…
zhangfengcdt 881e3f3
address copilot comments
zhangfengcdt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
101 changes: 101 additions & 0 deletions
101
common/src/test/java/org/apache/sedona/common/S2Geography/WkbContainsRoundtripTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.apache.sedona.common.S2Geography; | ||
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import org.apache.sedona.common.geography.Constructors; | ||
| import org.apache.sedona.common.geography.Functions; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Localises a Geography ST_Contains correctness bug seen when arguments come from a DataFrame (i.e. | ||
| * after a GeographyWKBSerializer round-trip). The WKBGeography fast path (getShapeIndexGeography → | ||
| * WkbS2Shape) returns the wrong answer for some polygon-point pairs; the slow path through | ||
| * S2Polygon (and direct ST_GeogFromWKT in a SELECT) is correct. | ||
| */ | ||
| public class WkbContainsRoundtripTest { | ||
|
|
||
| /** | ||
| * Direct Functions.contains call, no round-trip. Should return false: (10, 10) is far outside the | ||
| * small polygon at (2..3, 2..3). | ||
| */ | ||
| @Test | ||
| public void containsIsFalseWithoutRoundTrip() throws Exception { | ||
| Geography poly = Constructors.geogFromWKT("POLYGON((2 2, 3 2, 3 3, 2 3, 2 2))", 4326); | ||
| Geography pt = Constructors.geogFromWKT("POINT(10 10)", 4326); | ||
| assertFalse(Functions.contains(poly, pt)); | ||
| assertTrue(Functions.contains(poly, Constructors.geogFromWKT("POINT(2.5 2.5)", 4326))); | ||
| } | ||
|
|
||
| /** Control test mirroring GeographyFunctionTest's "ST_Contains point outside polygon". */ | ||
| @Test | ||
| public void controlPolygonAtOrigin() throws Exception { | ||
| Geography poly = Constructors.geogFromWKT("POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", 4326); | ||
| Geography ptOutside = Constructors.geogFromWKT("POINT(2 2)", 4326); | ||
| Geography ptInside = Constructors.geogFromWKT("POINT(0.5 0.5)", 4326); | ||
| assertFalse("polygon at origin must NOT contain (2, 2)", Functions.contains(poly, ptOutside)); | ||
| assertTrue("polygon at origin must contain (0.5, 0.5)", Functions.contains(poly, ptInside)); | ||
| } | ||
|
|
||
| /** | ||
| * Bypass WkbS2Shape and feed the polygon through PolygonGeography directly. If this passes while | ||
| * the equivalent WKBGeography case fails, the bug is localised to WkbS2Shape (or to the | ||
| * `result.shapeIndex.add(new WkbS2Shape(...))` path in WKBGeography.getShapeIndexGeography). | ||
| */ | ||
| @Test | ||
| public void bypassWkbS2ShapeViaPolygonGeography() throws Exception { | ||
| // Force the slow path: parse via WKTReader then DON'T wrap in WKBGeography. | ||
| Geography poly = new WKTReader().read("POLYGON((2 2, 3 2, 3 3, 2 3, 2 2))"); | ||
| poly.setSRID(4326); | ||
| Geography ptOutside = new WKTReader().read("POINT(10 10)"); | ||
| ptOutside.setSRID(4326); | ||
| Geography ptInside = new WKTReader().read("POINT(2.5 2.5)"); | ||
| ptInside.setSRID(4326); | ||
| assertFalse( | ||
| "[slow path] polygon at (2..3,2..3) must NOT contain (10, 10)", | ||
| Functions.contains(poly, ptOutside)); | ||
| assertTrue( | ||
| "[slow path] polygon at (2..3,2..3) must contain (2.5, 2.5)", | ||
| Functions.contains(poly, ptInside)); | ||
| } | ||
|
|
||
| /** | ||
| * Same logical inputs, but each Geography goes through the WKB serializer round-trip first — | ||
| * which is what happens whenever a GeographyUDT column is read back from a DataFrame. | ||
| */ | ||
| @Test | ||
| public void containsIsFalseAfterWkbRoundTrip() throws Exception { | ||
| Geography poly = | ||
| GeographyWKBSerializer.deserialize( | ||
| GeographyWKBSerializer.serialize( | ||
| Constructors.geogFromWKT("POLYGON((2 2, 3 2, 3 3, 2 3, 2 2))", 4326))); | ||
| Geography ptOutside = | ||
| GeographyWKBSerializer.deserialize( | ||
| GeographyWKBSerializer.serialize(Constructors.geogFromWKT("POINT(10 10)", 4326))); | ||
| Geography ptInside = | ||
| GeographyWKBSerializer.deserialize( | ||
| GeographyWKBSerializer.serialize(Constructors.geogFromWKT("POINT(2.5 2.5)", 4326))); | ||
| assertFalse( | ||
| "polygon at (2..3,2..3) must NOT contain (10, 10)", Functions.contains(poly, ptOutside)); | ||
| assertTrue( | ||
| "polygon at (2..3,2..3) must contain (2.5, 2.5)", Functions.contains(poly, ptInside)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.