Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.5k
API: Single-value binary serialization for geometry and geography#16607
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10 api/src/main/java/org/apache/iceberg/types/Conversions.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
51 changes: 51 additions & 0 deletions
51 api/src/test/java/org/apache/iceberg/types/TestConversions.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 |
|---|---|---|
| @@ -26,13 +26,18 @@ | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.UUID; | ||
| import org.apache.iceberg.expressions.Literal; | ||
| import org.apache.iceberg.geospatial.GeospatialBound; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.primitives.Bytes; | ||
| import org.apache.iceberg.types.Types.BinaryType; | ||
| import org.apache.iceberg.types.Types.BooleanType; | ||
| import org.apache.iceberg.types.Types.DateType; | ||
| import org.apache.iceberg.types.Types.DecimalType; | ||
| import org.apache.iceberg.types.Types.DoubleType; | ||
| import org.apache.iceberg.types.Types.FixedType; | ||
| import org.apache.iceberg.types.Types.FloatType; | ||
| import org.apache.iceberg.types.Types.GeographyType; | ||
| import org.apache.iceberg.types.Types.GeometryType; | ||
| import org.apache.iceberg.types.Types.IntegerType; | ||
| import org.apache.iceberg.types.Types.LongType; | ||
| import org.apache.iceberg.types.Types.StringType; | ||
| @@ -191,6 +196,52 @@ public void testByteBufferConversions() { | ||
| .isEqualTo(new byte[] {11}); | ||
| } | ||
| @Test | ||
| public void testByteBufferConversionsForGeometry() { | ||
| // geometry/geography bounds are a single point encoded as 8-byte little-endian IEEE 754 | ||
| // doubles in X, Y[, Z][, M] order: | ||
| // x:y (16B) when z and m are unset | ||
| // x:y:z (24B) when only m is unset | ||
| // x:y:NaN:m (32B) when only z is unset -- z slot is filled with NaN | ||
| // x:y:z:m (32B) when all are set | ||
| byte[] xBytes = {0, 0, 0, 0, 0, 0, 36, 64}; // 10.0 | ||
| byte[] yBytes = {0, 0, 0, 0, 0, 0, 42, 64}; // 13.0 | ||
| byte[] zBytes = {0, 0, 0, 0, 0, 0, 46, 64}; // 15.0 | ||
| byte[] mBytes = {0, 0, 0, 0, 0, 0, 52, 64}; // 20.0 | ||
| byte[] nanBytes = {0, 0, 0, 0, 0, 0, -8, 127}; | ||
| for (Type type : ImmutableList.of(GeometryType.crs84(), GeographyType.crs84())) { | ||
| assertConversion(GeospatialBound.createXY(10.0, 13.0), type, Bytes.concat(xBytes, yBytes)); | ||
| assertConversion( | ||
| GeospatialBound.createXYZ(10.0, 13.0, 15.0), type, Bytes.concat(xBytes, yBytes, zBytes)); | ||
| assertConversion( | ||
| GeospatialBound.createXYM(10.0, 13.0, 20.0), | ||
| type, | ||
| Bytes.concat(xBytes, yBytes, nanBytes, mBytes)); | ||
| assertConversion( | ||
| GeospatialBound.createXYZM(10.0, 13.0, 15.0, 20.0), | ||
| type, | ||
| Bytes.concat(xBytes, yBytes, zBytes, mBytes)); | ||
| } | ||
| // a non-default CRS must not change the binary encoding | ||
| assertConversion( | ||
| GeospatialBound.createXY(10.0, 13.0), | ||
| GeometryType.of("EPSG:3857"), | ||
| Bytes.concat(xBytes, yBytes)); | ||
| } | ||
| @Test | ||
| public void testNullByteBufferConversionsForGeometry() { | ||
| // Null is handled by the shared guards in toByteBuffer / fromByteBuffer before the type switch, | ||
| // so this pins the null contract for geo types rather than exercising the GEOMETRY / GEOGRAPHY | ||
| // arms (those are covered by testByteBufferConversionsForGeometry). | ||
| assertThat(Conversions.toByteBuffer(GeometryType.crs84(), null)).isNull(); | ||
| assertThat(Conversions.toByteBuffer(GeographyType.crs84(), null)).isNull(); | ||
| assertThat((Object) Conversions.fromByteBuffer(GeometryType.crs84(), null)).isNull(); | ||
| assertThat((Object) Conversions.fromByteBuffer(GeographyType.crs84(), null)).isNull(); | ||
| } | ||
huan233usc marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| private <T> void assertConversion(T value, Type type, byte[] expectedBinary) { | ||
| ByteBuffer byteBuffer = Conversions.toByteBuffer(type, value); | ||
| assertThat(byteBuffer.array()).isEqualTo(expectedBinary); | ||
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.