-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-53922][Geo][SQL] Introduce physical Geometry and Geography types #52629
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
50 changes: 50 additions & 0 deletions
50
common/unsafe/src/main/java/org/apache/spark/unsafe/types/GeographyVal.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,50 @@ | ||
| /* | ||
| * 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.spark.unsafe.types; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| // This class represents the physical type for the GEOGRAPHY data type. | ||
| public final class GeographyVal implements Comparable<GeographyVal>, Serializable { | ||
|
|
||
| // The GEOGRAPHY type is implemented as a byte array. We provide `getBytes` and `fromBytes` | ||
| // methods for readers and writers to access this underlying array of bytes. | ||
| private final byte[] value; | ||
|
|
||
| // We make the constructor private. We should use `fromBytes` to create new instances. | ||
| private GeographyVal(byte[] value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public byte[] getBytes() { | ||
| return value; | ||
| } | ||
|
|
||
| public static GeographyVal fromBytes(byte[] bytes) { | ||
| if (bytes == null) { | ||
| return null; | ||
| } else { | ||
| return new GeographyVal(bytes); | ||
| } | ||
| } | ||
|
|
||
| // Comparison is not yet supported for GEOGRAPHY. | ||
| public int compareTo(GeographyVal g) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
common/unsafe/src/main/java/org/apache/spark/unsafe/types/GeometryVal.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,50 @@ | ||
| /* | ||
| * 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.spark.unsafe.types; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| // This class represents the physical type for the GEOMETRY data type. | ||
| public final class GeometryVal implements Comparable<GeometryVal>, Serializable { | ||
|
|
||
| // The GEOMETRY type is implemented as a byte array. We provide `getBytes` and `fromBytes` | ||
| // methods for readers and writers to access this underlying array of bytes. | ||
| private final byte[] value; | ||
|
|
||
| // We make the constructor private. We should use `fromBytes` to create new instances. | ||
| private GeometryVal(byte[] value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public byte[] getBytes() { | ||
| return value; | ||
| } | ||
|
|
||
| public static GeometryVal fromBytes(byte[] bytes) { | ||
| if (bytes == null) { | ||
| return null; | ||
| } else { | ||
| return new GeometryVal(bytes); | ||
| } | ||
| } | ||
|
|
||
| // Comparison is not yet supported for GEOMETRY. | ||
| public int compareTo(GeometryVal g) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
common/unsafe/src/test/java/org/apache/spark/unsafe/types/GeographyValSuite.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,57 @@ | ||
| /* | ||
| * 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.spark.unsafe.types; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| public class GeographyValSuite { | ||
|
|
||
| @Test | ||
| public void roundTripBytes() { | ||
| // A simple byte array to test the round trip (`fromBytes` -> `getBytes`). | ||
| byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6 }; | ||
| GeographyVal geographyVal = GeographyVal.fromBytes(bytes); | ||
| assertNotNull(geographyVal); | ||
| assertArrayEquals(bytes, geographyVal.getBytes()); | ||
| } | ||
|
|
||
| @Test | ||
| public void roundNullHandling() { | ||
| // A simple null byte array to test null handling for GEOGRAPHY. | ||
| byte[] bytes = null; | ||
| GeographyVal geographyVal = GeographyVal.fromBytes(bytes); | ||
| assertNull(geographyVal); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCompareTo() { | ||
| // Comparison is not yet supported for GEOGRAPHY. | ||
| byte[] bytes1 = new byte[] { 1, 2, 3 }; | ||
| byte[] bytes2 = new byte[] { 4, 5, 6 }; | ||
| GeographyVal geographyVal1 = GeographyVal.fromBytes(bytes1); | ||
| GeographyVal geographyVal2 = GeographyVal.fromBytes(bytes2); | ||
| try { | ||
| geographyVal1.compareTo(geographyVal2); | ||
| } catch (UnsupportedOperationException e) { | ||
| assert(e.toString().equals("java.lang.UnsupportedOperationException")); | ||
| } | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
common/unsafe/src/test/java/org/apache/spark/unsafe/types/GeometryValSuite.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,57 @@ | ||
| /* | ||
| * 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.spark.unsafe.types; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| public class GeometryValSuite { | ||
|
|
||
| @Test | ||
| public void roundTripBytes() { | ||
| // A simple byte array to test the round trip (`fromBytes` -> `getBytes`). | ||
| byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6 }; | ||
| GeometryVal geometryVal = GeometryVal.fromBytes(bytes); | ||
| assertNotNull(geometryVal); | ||
| assertArrayEquals(bytes, geometryVal.getBytes()); | ||
| } | ||
|
|
||
| @Test | ||
| public void roundNullHandling() { | ||
| // A simple null byte array to test null handling for GEOMETRY. | ||
| byte[] bytes = null; | ||
| GeometryVal geometryVal = GeometryVal.fromBytes(bytes); | ||
| assertNull(geometryVal); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCompareTo() { | ||
| // Comparison is not yet supported for GEOMETRY. | ||
| byte[] bytes1 = new byte[] { 1, 2, 3 }; | ||
| byte[] bytes2 = new byte[] { 4, 5, 6 }; | ||
| GeometryVal geometryVal1 = GeometryVal.fromBytes(bytes1); | ||
| GeometryVal geometryVal2 = GeometryVal.fromBytes(bytes2); | ||
| try { | ||
| geometryVal1.compareTo(geometryVal2); | ||
| } catch (UnsupportedOperationException e) { | ||
| assert(e.toString().equals("java.lang.UnsupportedOperationException")); | ||
| } | ||
| } | ||
| } |
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
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.