Skip to content
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

Handle Postgres data type Enum in the sqlglot and in the ibis #617

Open
grieve54706 opened this issue Jun 18, 2024 · 1 comment
Open

Handle Postgres data type Enum in the sqlglot and in the ibis #617

grieve54706 opened this issue Jun 18, 2024 · 1 comment
Labels
bug Something isn't working ibis

Comments

@grieve54706
Copy link
Contributor

If you select a table with a data type that is enum in the Postgres, ibis will create a view and get the schema of the view.
Ibis get data_type from pg_attribute is enum_operation. Ibis will put this text into sqlglot to parse to DataType. But the enum_operation is not in the sqlglot.expressions.DataType.

   File "/app/model/connector.py", line 29, in query
     return self.connection.sql(rewritten_sql, dialect="trino").to_pandas()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/app/.venv/lib/python3.11/site-packages/ibis/backends/sql/__init__.py", line 200, in sql
     schema = self._get_schema_using_query(query)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/app/.venv/lib/python3.11/site-packages/ibis/backends/postgres/__init__.py", line 610, in _get_schema_using_query
     return self.get_schema(name)
            ^^^^^^^^^^^^^^^^^^^^^
   File "/app/.venv/lib/python3.11/site-packages/ibis/backends/postgres/__init__.py", line 588, in get_schema
     {
   File "/app/.venv/lib/python3.11/site-packages/ibis/backends/postgres/__init__.py", line 589, in <dictcomp>
     col: type_mapper.from_string(typestr, nullable=nullable)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/app/.venv/lib/python3.11/site-packages/ibis/backends/sql/datatypes.py", line 426, in from_string
     sgtype = sg.parse_one(text, into=sge.DataType, read=cls.dialect)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/app/.venv/lib/python3.11/site-packages/sqlglot/__init__.py", line 137, in parse_one
     result = dialect.parse_into(into, sql, **opts)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/app/.venv/lib/python3.11/site-packages/sqlglot/dialects/dialect.py", line 511, in parse_into
     return self.parser(**opts).parse_into(expression_type, self.tokenize(sql), sql)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/app/.venv/lib/python3.11/site-packages/sqlglot/parser.py", line 1210, in parse_into
     raise ParseError(
 sqlglot.errors.ParseError: Failed to parse 'enum_operation' into <class 'sqlglot.expressions.DataType'>

May we fix the enum_operation to be enum in the ibis.

@grieve54706 grieve54706 added bug Something isn't working ibis labels Jun 18, 2024
@grieve54706
Copy link
Contributor Author

Follow ibis-project/ibis#9295

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ibis
Projects
None yet
Development

No branches or pull requests

1 participant