-
Notifications
You must be signed in to change notification settings - Fork 40
Geospatial datatype support #988
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
sreekanth-db
merged 18 commits into
databricks:main
from
sreekanth-db:geospatial-datatype
Oct 24, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ab7556e
Geospatial datatype support
sreekanth-db 6d2cd46
changelog
sreekanth-db c1b8ce2
additional unit tests
sreekanth-db 6d02081
Merge remote-tracking branch 'origin/main' into geospatial-datatype
sreekanth-db e93c3f8
addressing review comments
sreekanth-db e911082
addressing review comments - 2
sreekanth-db 2a7e20a
thread safe wkt converter
sreekanth-db 5178087
Merge remote-tracking branch 'upstream/main' into geospatial-datatype
sreekanth-db 4aad99d
geospatial fake service test
sreekanth-db b01f240
addressing review comments - 3
sreekanth-db 61bfff4
addressing review comments - 4
sreekanth-db f080ff6
addressing review comments - 5
sreekanth-db 28d493f
Merge remote-tracking branch 'upstream/main' into geospatial-datatype
sreekanth-db 761bdee
addressing review comments - 6
sreekanth-db 585f9fc
improving test coverage
sreekanth-db ea2f8fa
moving interface out of impl
sreekanth-db c90bc62
Merge branch 'main' into geospatial-datatype
sreekanth-db 50f27cc
skipping thrift server fake service test (doesn't support geospatial …
sreekanth-db 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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/databricks/jdbc/api/IDatabricksGeospatial.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,60 @@ | ||
| package com.databricks.jdbc.api; | ||
|
|
||
| import com.databricks.jdbc.exception.DatabricksValidationException; | ||
|
|
||
| /** | ||
| * Interface for geospatial data types in Databricks JDBC driver. | ||
| * | ||
| * <p>This interface provides common functionality for both GEOMETRY and GEOGRAPHY types, allowing | ||
| * access to Well-Known Text (WKT), Well-Known Binary (WKB) representation and Spatial Reference | ||
| * System Identifier (SRID). | ||
| * | ||
| * <p>Following the established patterns of DatabricksStruct, DatabricksArray, and DatabricksMap, | ||
| * this interface enables consistent handling of geospatial data across the JDBC driver. | ||
| */ | ||
| public interface IDatabricksGeospatial { | ||
|
sreekanth-db marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Returns the Well-Known Binary (WKB) representation of the geospatial object. | ||
| * | ||
| * <p>WKB is a binary format for representing geometry data that is compact and suitable for | ||
| * storage and transmission. This method converts the internal representation to WKB format on | ||
| * demand. | ||
| * | ||
| * @return the WKB representation as a byte array | ||
| * @throws DatabricksValidationException if WKT to WKB conversion fails | ||
| */ | ||
| byte[] getWKB() throws DatabricksValidationException; | ||
|
|
||
| /** | ||
| * Returns the Spatial Reference System Identifier (SRID) of the geospatial object. | ||
| * | ||
| * <p>SRID identifies the coordinate system used by the geometry. Common values include: | ||
| * | ||
| * <ul> | ||
| * <li>4326 - WGS 84 (World Geodetic System 1984) | ||
| * <li>3857 - Web Mercator | ||
| * <li>0 - No SRID specified | ||
| * </ul> | ||
| * | ||
| * @return the SRID value | ||
| */ | ||
| int getSRID(); | ||
|
|
||
| /** | ||
| * Returns the Well-Known Text (WKT) representation of the geospatial object. | ||
| * | ||
| * <p>WKT is a human-readable text format for representing geometry data. This provides a | ||
| * complement to the binary WKB format, allowing easy inspection and debugging of geospatial data. | ||
| * | ||
| * @return the WKT string representation | ||
| */ | ||
| String getWKT(); | ||
|
|
||
| /** | ||
| * Returns the data type of the geospatial object. | ||
| * | ||
| * @return the type as a string, either "GEOMETRY" or "GEOGRAPHY" | ||
| */ | ||
| String getType(); | ||
| } | ||
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,4 @@ | ||
| package com.databricks.jdbc.api; | ||
|
|
||
| /** Interface for GEOGRAPHY data types in Databricks JDBC driver. */ | ||
| public interface IGeography extends IDatabricksGeospatial {} |
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,4 @@ | ||
| package com.databricks.jdbc.api; | ||
|
|
||
| /** Interface for GEOMETRY data types in Databricks JDBC driver. */ | ||
| public interface IGeometry extends IDatabricksGeospatial {} |
119 changes: 119 additions & 0 deletions
119
src/main/java/com/databricks/jdbc/api/impl/AbstractDatabricksGeospatial.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,119 @@ | ||
| package com.databricks.jdbc.api.impl; | ||
|
|
||
| import com.databricks.jdbc.api.IDatabricksGeospatial; | ||
| import com.databricks.jdbc.api.impl.converters.WKTConverter; | ||
| import com.databricks.jdbc.exception.DatabricksValidationException; | ||
| import com.databricks.jdbc.log.JdbcLogger; | ||
| import com.databricks.jdbc.log.JdbcLoggerFactory; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Abstract base class for geospatial data types in Databricks JDBC driver. | ||
| * | ||
| * <p>This class provides common functionality for both GEOMETRY and GEOGRAPHY types, including | ||
| * storage of WKT (Well-Known Text) format data and access to both WKT and WKB representations. | ||
| */ | ||
| public abstract class AbstractDatabricksGeospatial implements IDatabricksGeospatial { | ||
|
sreekanth-db marked this conversation as resolved.
|
||
|
|
||
| private static final JdbcLogger LOGGER = | ||
| JdbcLoggerFactory.getLogger(AbstractDatabricksGeospatial.class); | ||
|
|
||
| private final String wkt; | ||
| private final int srid; // Spatial Reference System Identifier | ||
|
|
||
| /** | ||
| * Constructs an AbstractDatabricksGeospatial with the specified WKT and SRID. | ||
| * | ||
| * @param wkt the Well-Known Text representation of the geospatial object | ||
| * @param srid the Spatial Reference System Identifier | ||
| * @throws DatabricksValidationException if the WKT is invalid | ||
| */ | ||
| protected AbstractDatabricksGeospatial(String wkt, int srid) | ||
| throws DatabricksValidationException { | ||
| if (wkt == null || wkt.trim().isEmpty()) { | ||
| LOGGER.error("WKT string cannot be null or empty"); | ||
| throw new DatabricksValidationException("WKT string cannot be null or empty"); | ||
|
sreekanth-db marked this conversation as resolved.
|
||
| } | ||
|
|
||
| this.wkt = wkt.trim(); | ||
| this.srid = srid; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the Well-Known Binary (WKB) representation of the geospatial object. | ||
| * | ||
| * @return the WKB representation as a byte array | ||
| * @throws DatabricksValidationException if WKT to WKB conversion fails | ||
| */ | ||
| @Override | ||
| public byte[] getWKB() throws DatabricksValidationException { | ||
| return WKTConverter.toWKB(wkt); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should consider storing this value as computation can be very expensive
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Storing wkb it in a class variable for reuse. Implemented in #1062 |
||
| } | ||
|
|
||
| /** | ||
| * Returns the Spatial Reference System Identifier (SRID) of the geospatial object. | ||
| * | ||
| * @return the SRID value | ||
| */ | ||
| @Override | ||
| public int getSRID() { | ||
| return srid; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the Well-Known Text (WKT) representation of the geospatial object. | ||
| * | ||
| * @return the WKT string | ||
| */ | ||
| @Override | ||
| public String getWKT() { | ||
| return wkt; | ||
|
sreekanth-db marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Returns a string representation of the geospatial object in EWKT format. | ||
| * | ||
| * @return the EWKT string representation | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| return String.format("SRID=%d;%s", srid, wkt); | ||
|
sreekanth-db marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Checks if this geospatial object is equal to another object. | ||
| * | ||
| * @param obj the object to compare | ||
| * @return true if the objects are equal, false otherwise | ||
| */ | ||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (obj == null || getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| AbstractDatabricksGeospatial that = (AbstractDatabricksGeospatial) obj; | ||
| return srid == that.srid && wkt.equals(that.wkt); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the hash code for this geospatial object. | ||
| * | ||
| * @return the hash code | ||
| */ | ||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(wkt, srid); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the data type of the geospatial object. | ||
| * | ||
| * @return the type as a string, either "GEOMETRY" or "GEOGRAPHY" | ||
| */ | ||
| @Override | ||
| public abstract String getType(); | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
src/main/java/com/databricks/jdbc/api/impl/DatabricksGeography.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,25 @@ | ||
| package com.databricks.jdbc.api.impl; | ||
|
|
||
| import static com.databricks.jdbc.common.util.DatabricksTypeUtil.GEOGRAPHY; | ||
|
|
||
| import com.databricks.jdbc.api.IGeography; | ||
| import com.databricks.jdbc.exception.DatabricksValidationException; | ||
|
|
||
| public class DatabricksGeography extends AbstractDatabricksGeospatial implements IGeography { | ||
|
|
||
| /** | ||
| * Constructs a DatabricksGeography with the specified WKT and SRID. | ||
| * | ||
| * @param wkt the Well-Known Text representation of the geography | ||
| * @param srid the Spatial Reference System Identifier | ||
| * @throws DatabricksValidationException if the WKT is invalid | ||
| */ | ||
| public DatabricksGeography(String wkt, int srid) throws DatabricksValidationException { | ||
|
sreekanth-db marked this conversation as resolved.
|
||
| super(wkt, srid); | ||
| } | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return GEOGRAPHY; | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
src/main/java/com/databricks/jdbc/api/impl/DatabricksGeometry.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,25 @@ | ||
| package com.databricks.jdbc.api.impl; | ||
|
|
||
| import static com.databricks.jdbc.common.util.DatabricksTypeUtil.GEOMETRY; | ||
|
|
||
| import com.databricks.jdbc.api.IGeometry; | ||
| import com.databricks.jdbc.exception.DatabricksValidationException; | ||
|
|
||
| public class DatabricksGeometry extends AbstractDatabricksGeospatial implements IGeometry { | ||
|
|
||
| /** | ||
| * Constructs a DatabricksGeometry with the specified WKT and SRID. | ||
| * | ||
| * @param wkt the Well-Known Text representation of the geometry | ||
| * @param srid the Spatial Reference System Identifier | ||
| * @throws DatabricksValidationException if the WKT is invalid | ||
| */ | ||
| public DatabricksGeometry(String wkt, int srid) throws DatabricksValidationException { | ||
| super(wkt, srid); | ||
| } | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return GEOMETRY; | ||
| } | ||
| } |
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.
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.