Skip to content

fix(datatype): convert from sqlglot VARCHAR(MAX) correctly #11202

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions ibis/backends/sql/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,29 @@ def _from_sqlglot_VARCHAR(
nullable=nullable,
)

_from_sqlglot_NVARCHAR = _from_sqlglot_NCHAR = _from_sqlglot_CHAR = (
_from_sqlglot_FIXEDSTRING
) = _from_sqlglot_VARCHAR
@classmethod
def _from_sqlglot_NVARCHAR(
cls, length: sge.DataTypeParam | None = None, nullable: bool | None = None
) -> dt.String:
return cls._from_sqlglot_VARCHAR(length, nullable=nullable)

@classmethod
def _from_sqlglot_NCHAR(
cls, length: sge.DataTypeParam | None = None, nullable: bool | None = None
) -> dt.String:
return cls._from_sqlglot_VARCHAR(length, nullable=nullable)

@classmethod
def _from_sqlglot_CHAR(
cls, length: sge.DataTypeParam | None = None, nullable: bool | None = None
) -> dt.String:
return cls._from_sqlglot_VARCHAR(length, nullable=nullable)

@classmethod
def _from_sqlglot_FIXEDSTRING(
cls, length: sge.DataTypeParam | None = None, nullable: bool | None = None
) -> dt.String:
return cls._from_sqlglot_VARCHAR(length, nullable=nullable)

@classmethod
def _from_sqlglot_MAP(
Expand Down Expand Up @@ -470,6 +490,10 @@ def _from_ibis_SpecificGeometry(cls, dtype: dt.GeoSpatial):
this = getattr(typecode, dtype.geotype.upper())
return sge.DataType(this=this, expressions=expressions)

# warning: this does early binding, so if you call eg `PostgresType._from_ibis_Point`
# this will resolve to `SqlglotType._from_ibis_SpecificGeometry`, not
# `PostgresType._from_ibis_SpecificGeometry`.
# At this point, not a problem, but be careful if you override this in subclasses.
_from_ibis_Point = _from_ibis_LineString = _from_ibis_Polygon = (
_from_ibis_MultiLineString
) = _from_ibis_MultiPoint = _from_ibis_MultiPolygon = _from_ibis_SpecificGeometry
Expand Down
Loading