-
Notifications
You must be signed in to change notification settings - Fork 764
[GH-2973] Box3D constructors: ST_Box3D and ST_3DMakeBox #2984
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
Merged
Changes from all commits
Commits
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
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
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
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
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
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
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
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
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
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
84 changes: 84 additions & 0 deletions
84
spark/common/src/test/scala/org/apache/sedona/sql/Box3DConstructorSuite.scala
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,84 @@ | ||
| /* | ||
| * 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.sql | ||
|
|
||
| import org.apache.sedona.common.geometryObjects.Box3D | ||
|
|
||
| class Box3DConstructorSuite extends TestBaseScala { | ||
|
|
||
| describe("Box3D constructors") { | ||
|
|
||
| it("ST_Box3D returns the 3D bbox, defaulting Z=0 for XY input") { | ||
| val row = sparkSession | ||
| .sql("SELECT ST_Box3D(ST_GeomFromText('LINESTRING(0 0, 10 20)')) AS box3d_xy, " + | ||
| "ST_Box3D(ST_GeomFromWKT('LINESTRING Z(0 0 -3, 5 10 7)')) AS box3d_xyz") | ||
| .collect()(0) | ||
| assert(row.getAs[Box3D]("box3d_xy") == new Box3D(0, 0, 0, 10, 20, 0)) | ||
| assert(row.getAs[Box3D]("box3d_xyz") == new Box3D(0, 0, -3, 5, 10, 7)) | ||
| } | ||
|
|
||
| it("ST_Box3D returns NULL for null and empty input") { | ||
| val row = sparkSession | ||
| .sql("SELECT ST_Box3D(ST_GeomFromText(NULL)) AS b_null, " + | ||
| "ST_Box3D(ST_GeomFromText('LINESTRING EMPTY')) AS b_empty") | ||
| .collect()(0) | ||
| assert(row.isNullAt(0)) | ||
| assert(row.isNullAt(1)) | ||
| } | ||
|
|
||
| it("ST_3DMakeBox builds a Box3D from two POINTZ corners") { | ||
| val row = sparkSession | ||
| .sql("SELECT ST_3DMakeBox(ST_PointZ(0, 0, 0), ST_PointZ(2, 4, 6)) AS b") | ||
| .collect()(0) | ||
| assert(row.getAs[Box3D]("b") == new Box3D(0, 0, 0, 2, 4, 6)) | ||
| } | ||
|
|
||
| it("ST_3DMakeBox treats missing Z as 0") { | ||
| val row = sparkSession | ||
| .sql("SELECT ST_3DMakeBox(ST_Point(0, 0), ST_Point(2, 4)) AS b") | ||
| .collect()(0) | ||
| assert(row.getAs[Box3D]("b") == new Box3D(0, 0, 0, 2, 4, 0)) | ||
| } | ||
|
|
||
| it("ST_3DMakeBox returns NULL for null point input") { | ||
| val row = sparkSession | ||
| .sql("SELECT ST_3DMakeBox(ST_GeomFromText(NULL), ST_PointZ(2, 4, 6)) AS b") | ||
| .collect()(0) | ||
| assert(row.isNullAt(0)) | ||
| } | ||
|
|
||
| it("ST_3DMakeBox returns NULL for empty point input") { | ||
| val row = sparkSession | ||
| .sql("SELECT ST_3DMakeBox(ST_GeomFromText('POINT EMPTY'), ST_PointZ(2, 4, 6)) AS b") | ||
| .collect()(0) | ||
| assert(row.isNullAt(0)) | ||
| } | ||
|
|
||
| it("ST_3DMakeBox throws for non-POINT input") { | ||
| val thrown = intercept[Exception] { | ||
| sparkSession | ||
| .sql("SELECT ST_3DMakeBox(ST_GeomFromText('LINESTRING(0 0, 1 1)'), ST_PointZ(2, 4, 6))") | ||
| .collect() | ||
| } | ||
| val messages = | ||
| Iterator.iterate[Throwable](thrown)(_.getCause).takeWhile(_ != null).map(_.getMessage) | ||
| assert(messages.exists(m => m != null && m.contains("requires two POINT geometries"))) | ||
| } | ||
| } | ||
| } | ||
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
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.