-
Notifications
You must be signed in to change notification settings - Fork 662
Closed
Labels
bugIncorrect behavior inside of ibisIncorrect behavior inside of ibismssqlThe Microsoft SQL Server backendThe Microsoft SQL Server backend
Description
What happened?
After upgrading from 10.2.0 to 10.5.0 the dtype NVARCHAR(MAX)
fails on mssql (likely also others are affected). previously this got resolved to a String()
type.
The recently added handling of this type leads to a failure since in sql/datatypes.py:219
length.this.this
yields 'MAX' which can not be places into an int()
statement.
@classmethod
def _from_sqlglot_VARCHAR(
cls, length: sge.DataTypeParam | None = None, nullable: bool | None = None
) -> dt.String:
return dt.String(
length=int(length.this.this) if length is not None else None,
nullable=nullable,
)
to make it work i've forked and fixed it like so:
@classmethod
def _from_sqlglot_VARCHAR(
cls, length: sge.DataTypeParam | None = None, nullable: bool | None = None
) -> dt.String:
if length is not None and length.this.this == "MAX":
length = None
return dt.String(
length=int(length.this.this) if length is not None else None,
nullable=nullable,
)
i guess the following is even a bit nicer as it avoids the redundancy around None checks
@classmethod
def _from_sqlglot_VARCHAR(
cls, length: sge.DataTypeParam | None = None, nullable: bool | None = None
) -> dt.String:
length_value = None
if length is not None and length.this.this != "MAX":
length_value = int(length.this.this)
return dt.String(
length=length_value,
nullable=nullable,
)
What version of ibis are you using?
Ibis 10.5.0
python 3.11.11
What backend(s) are you using, if any?
No response
Relevant log output
File ".venv/lib/python3.11/site-packages/ibis/backends/sql/__init__.py", line 179, in sql
schema = self._get_schema_using_query(query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/ibis/backends/mssql/__init__.py", line 369, in _get_schema_using_query
newtyp = self.compiler.type_mapper.from_string(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/ibis/backends/sql/datatypes.py", line 195, in from_string
return cls.to_ibis(sgtype, nullable=nullable)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/ibis/backends/sql/datatypes.py", line 161, in to_ibis
dtype = method(*typ.expressions, nullable=nullable)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/ibis/backends/sql/datatypes.py", line 219, in _from_sqlglot_VARCHAR
length=int(length.this.this) if length is not None else None,
^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'MAX'
Code of Conduct
- I agree to follow this project's Code of Conduct
JonaGeishauser
Metadata
Metadata
Assignees
Labels
bugIncorrect behavior inside of ibisIncorrect behavior inside of ibismssqlThe Microsoft SQL Server backendThe Microsoft SQL Server backend
Type
Projects
Status
done