Skip to content

Commit a9c894b

Browse files
committed
Add support for in-core GEOMETRY type (1.5)
This is a backport of the PR duckdb#577 to `v1.5-variegata` stable branch. The in-built `GEOMETRY` type was added in 1.5 in addtion to the spatial types/functions that exist in the `duckdb-spatial` extension. This PR adds support for the new type treating it the same way (as `BLOB`) as the original `GEOMETRY` type from the spatial extension was treated. Testing: spatial test is effective for the new type, but is currently disabled until the `duckdb-spatial` (that was unavailable for some time) is enabled again in core CI builds.
1 parent 7f35d5e commit a9c894b

7 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/jni/duckdb_java.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ jobject ProcessVector(JNIEnv *env, Connection *conn_ref, Vector &vec, idx_t row_
622622
break;
623623
}
624624
case LogicalTypeId::BLOB:
625+
case LogicalTypeId::GEOMETRY:
625626
varlen_data = env->NewObjectArray(row_count, J_ByteArray, nullptr);
626627

627628
for (idx_t row_idx = 0; row_idx < row_count; row_idx++) {

src/main/java/org/duckdb/DuckDBColumnType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ public enum DuckDBColumnType {
3737
ARRAY,
3838
UNKNOWN,
3939
UNION,
40-
VARIANT;
40+
VARIANT,
41+
GEOMETRY;
4142
}

src/main/java/org/duckdb/DuckDBResultSet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public String getString(int columnIndex) throws SQLException {
211211
DuckDBColumnType sqlType = meta.column_types[columnIndex - 1];
212212
switch (sqlType) {
213213
case BLOB:
214+
case GEOMETRY:
214215
case LIST:
215216
case STRUCT:
216217
case MAP:

src/main/java/org/duckdb/DuckDBResultSetMetaData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public static int type_to_int(DuckDBColumnType type) {
167167
case BIT:
168168
return Types.BIT;
169169
case BLOB:
170+
case GEOMETRY:
170171
return Types.BLOB;
171172
default:
172173
return Types.OTHER;
@@ -356,6 +357,7 @@ public int getPrecision(int column) throws SQLException {
356357
return 35;
357358
case VARCHAR:
358359
case BLOB:
360+
case GEOMETRY:
359361
return Integer.MAX_VALUE;
360362
default:
361363
return 0;

src/main/java/org/duckdb/DuckDBVector.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Object getObject(int idx) throws SQLException {
117117
case JSON:
118118
return getJsonObject(idx);
119119
case BLOB:
120+
case GEOMETRY:
120121
return getBlob(idx);
121122
case UUID:
122123
return getUuid(idx);
@@ -315,7 +316,7 @@ Blob getBlob(int idx) throws SQLException {
315316
if (check_and_null(idx)) {
316317
return null;
317318
}
318-
if (isType(DuckDBColumnType.BLOB)) {
319+
if (isType(DuckDBColumnType.BLOB) || isType(DuckDBColumnType.GEOMETRY)) {
319320
return new DuckDBResultSet.DuckDBBlobResult(ByteBuffer.wrap((byte[]) varlen_data[idx]));
320321
}
321322

@@ -327,7 +328,7 @@ byte[] getBytes(int idx) throws SQLException {
327328
return null;
328329
}
329330

330-
if (isType(DuckDBColumnType.BLOB)) {
331+
if (isType(DuckDBColumnType.BLOB) || isType(DuckDBColumnType.GEOMETRY)) {
331332
return (byte[]) varlen_data[idx];
332333
}
333334

src/test/java/org/duckdb/TestDuckDBJDBC.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,9 +2246,9 @@ public static void main(String[] args) throws Exception {
22462246
statusCode = runTests(args, TestDuckDBJDBC.class, TestAppender.class, TestAppenderCollection.class,
22472247
TestAppenderCollection2D.class, TestAppenderComposite.class,
22482248
TestSingleValueAppender.class, TestBatch.class, TestBindings.class, TestClosure.class,
2249-
TestExtensionTypes.class, TestMetadata.class, TestNoLib.class,
2250-
/* TestSpatial.class, */ TestParameterMetadata.class, TestPrepare.class,
2251-
TestResults.class, TestSessionInit.class, TestTimestamp.class, TestVariant.class);
2249+
TestExtensionTypes.class, TestMetadata.class, TestNoLib.class, /* TestSpatial.class,*/
2250+
TestParameterMetadata.class, TestPrepare.class, TestResults.class,
2251+
TestSessionInit.class, TestTimestamp.class, TestVariant.class);
22522252
}
22532253
System.exit(statusCode);
22542254
}

src/test/java/org/duckdb/TestSpatial.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,8 @@ public static void test_spatial_GEOMETRY() throws Exception {
279279
stmt.executeUpdate("INSTALL spatial");
280280
stmt.executeUpdate("LOAD spatial");
281281

282-
byte[] geometryBytes =
283-
new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
284-
-51, -52, -52, -52, -52, -116, 68, 64, -102, -103, -103, -103, -103, 25, 69, 64};
282+
byte[] geometryBytes = new byte[] {1, 1, 0, 0, 0, -51, -52, -52, -52, -52, -116,
283+
68, 64, -102, -103, -103, -103, -103, 25, 69, 64};
285284

286285
// GEOMETRY literal
287286
try (ResultSet rs = stmt.executeQuery("SELECT ST_GeomFromText('POINT(41.1 42.2)')")) {

0 commit comments

Comments
 (0)