Skip to content

Commit

Permalink
fix(duckdb): allow table creation from expr with geospatial datatypes (
Browse files Browse the repository at this point in the history
…#7818)

I thought, initially, that WKB_BLOB should be mapped on to something
like dt.GeoSpatial, but that leads to a situation where we try to call
AsWKB on an existing WKB column, and DuckDB does not like that.

Mapping it as binary works and the created columns are still correctly
detected as geometry:geospatial.


Co-authored-by: Phillip Cloud <417981+cpcloud@users.noreply.github.com>
  • Loading branch information
gforsyth and cpcloud committed Dec 20, 2023
1 parent 066d3fc commit ecac322
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ibis/backends/base/sqlglot/datatypes.py
Expand Up @@ -354,6 +354,8 @@ class DuckDBType(SqlglotType):
default_decimal_scale = 3
default_interval_precision = "us"

unknown_type_strings = FrozenDict({"wkb_blob": dt.binary})

@classmethod
def _from_sqlglot_TIMESTAMP(cls) -> dt.Timestamp:
return dt.Timestamp(scale=6, nullable=cls.default_nullable)
Expand Down
13 changes: 13 additions & 0 deletions ibis/backends/duckdb/tests/test_geospatial.py
@@ -1,5 +1,7 @@
from __future__ import annotations

from operator import methodcaller

import numpy.testing as npt
import pandas.testing as tm
import pyarrow as pa
Expand Down Expand Up @@ -210,3 +212,14 @@ def test_geospatial_convert(geotable, gdf):
gtm.assert_geoseries_equal(
geo_ll.to_pandas(), gdf_ll, check_less_precise=True, check_crs=False
)


def test_create_table_geospatial_types(geotable, con):
name = ibis.util.gen_name("geotable")

# con = ibis.get_backend(geotable)

t = con.create_table(name, geotable, temp=True)

assert t.op().name in con.list_tables()
assert any(map(methodcaller("is_geospatial"), t.schema().values()))

0 comments on commit ecac322

Please sign in to comment.