Skip to content

Commit

Permalink
fix(datatypes): handle srid and shape type in geography too
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jul 4, 2024
1 parent 7a10cff commit 8694aad
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions ibis/backends/sql/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
typecode.ENUM16: dt.String,
typecode.FLOAT: dt.Float32,
typecode.FIXEDSTRING: dt.String,
typecode.GEOMETRY: partial(dt.GeoSpatial, geotype="geometry"),
typecode.GEOGRAPHY: partial(dt.GeoSpatial, geotype="geography"),
typecode.HSTORE: partial(dt.Map, dt.string, dt.string),
typecode.INET: dt.INET,
typecode.INT128: partial(dt.Decimal, 38, 0),
Expand Down Expand Up @@ -309,8 +307,16 @@ def _from_sqlglot_GEOMETRY(
return typeclass(geotype="geometry", nullable=cls.default_nullable, srid=srid)

@classmethod
def _from_sqlglot_GEOGRAPHY(cls) -> sge.DataType:
return dt.GeoSpatial(geotype="geography", nullable=cls.default_nullable)
def _from_sqlglot_GEOGRAPHY(
cls, arg: sge.DataTypeParam | None, srid: sge.DataTypeParam | None = None
) -> sge.DataType:
if arg is not None:
typeclass = _geotypes[arg.this]
else:
typeclass = dt.GeoSpatial
if srid is not None:
srid = int(srid.this.this)
return typeclass(geotype="geography", nullable=cls.default_nullable, srid=srid)

@classmethod
def _from_ibis_Interval(cls, dtype: dt.Interval) -> sge.DataType:
Expand Down Expand Up @@ -397,6 +403,8 @@ def _from_ibis_SpecificGeometry(cls, dtype: dt.GeoSpatial):

if (geotype := dtype.geotype) is not None:
this = getattr(typecode, geotype.upper())
else:
this = typecode.GEOMETRY

return sge.DataType(this=this, expressions=expressions)

Expand Down Expand Up @@ -802,7 +810,9 @@ def _from_sqlglot_TIMESTAMPTZ(cls) -> dt.Timestamp:
return dt.Timestamp(timezone="UTC", nullable=cls.default_nullable)

@classmethod
def _from_sqlglot_GEOGRAPHY(cls) -> dt.GeoSpatial:
def _from_sqlglot_GEOGRAPHY(
cls, arg: sge.DataTypeParam | None, srid: sge.DataTypeParam | None = None
) -> dt.GeoSpatial:
return dt.GeoSpatial(
geotype="geography", srid=4326, nullable=cls.default_nullable
)
Expand Down

0 comments on commit 8694aad

Please sign in to comment.