From ecac3224c7db5cce4bdd542ef414428745f04e2a Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Wed, 20 Dec 2023 15:18:45 -0500 Subject: [PATCH] fix(duckdb): allow table creation from expr with geospatial datatypes (#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> --- ibis/backends/base/sqlglot/datatypes.py | 2 ++ ibis/backends/duckdb/tests/test_geospatial.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/ibis/backends/base/sqlglot/datatypes.py b/ibis/backends/base/sqlglot/datatypes.py index bdbe94ddd40a..42c526f4487a 100644 --- a/ibis/backends/base/sqlglot/datatypes.py +++ b/ibis/backends/base/sqlglot/datatypes.py @@ -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) diff --git a/ibis/backends/duckdb/tests/test_geospatial.py b/ibis/backends/duckdb/tests/test_geospatial.py index 00bd5ba9719d..379a1fd8cdd5 100644 --- a/ibis/backends/duckdb/tests/test_geospatial.py +++ b/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 @@ -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()))