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

Driver fail on enums with empty string #147

Closed
afpd opened this issue Oct 7, 2021 · 4 comments · May be fixed by #337
Closed

Driver fail on enums with empty string #147

afpd opened this issue Oct 7, 2021 · 4 comments · May be fixed by #337

Comments

@afpd
Copy link

afpd commented Oct 7, 2021

Describe the bug
Driver fail on Enums with empty string.

  File "/root/venv/lib/python3.9/site-packages/clickhouse_sqlalchemy-0.1.6-py3.9.egg/clickhouse_sqlalchemy/drivers/base.py", line 827, in reflecttable
    rv = super(ClickHouseDialect, self).reflecttable(
  File "/root/venv/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 484, in reflecttable
    return insp.reflecttable(
  File "/root/venv/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 664, in reflecttable
    for col_d in self.get_columns(
  File "/root/venv/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 390, in get_columns
    col_defs = self.dialect.get_columns(
  File "<string>", line 2, in get_columns
  File "/root/venv/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 52, in cache
    ret = fn(self, con, *args, **kw)
  File "/root/venv/lib/python3.9/site-packages/clickhouse_sqlalchemy-0.1.6-py3.9.egg/clickhouse_sqlalchemy/drivers/base.py", line 865, in get_columns
    return [self._get_column_info(row.name, row.type) for row in rows]
  File "/root/venv/lib/python3.9/site-packages/clickhouse_sqlalchemy-0.1.6-py3.9.egg/clickhouse_sqlalchemy/drivers/base.py", line 865, in <listcomp>
    return [self._get_column_info(row.name, row.type) for row in rows]
  File "/root/venv/lib/python3.9/site-packages/clickhouse_sqlalchemy-0.1.6-py3.9.egg/clickhouse_sqlalchemy/drivers/base.py", line 868, in _get_column_info
    col_type = self._get_column_type(name, format_type)
  File "/root/venv/lib/python3.9/site-packages/clickhouse_sqlalchemy-0.1.6-py3.9.egg/clickhouse_sqlalchemy/drivers/base.py", line 911, in _get_column_type
    type_enum = enum.Enum('%s_enum' % name, options)
  File "/usr/lib/python3.9/enum.py", line 362, in __call__
    return cls._create_(
  File "/usr/lib/python3.9/enum.py", line 486, in _create_
    enum_class = metacls.__new__(metacls, class_name, bases, classdict)
  File "/usr/lib/python3.9/enum.py", line 207, in __new__
    raise ValueError('Invalid enum member name: {0}'.format(
ValueError: Invalid enum member name: 

To Reproduce
Populate clickhouse with https://clickhouse.com/docs/en/getting-started/example-datasets/cell-towers/
CREATE TABLE cell_towers
(
radio Enum8('' = 0, 'CDMA' = 1, 'GSM' = 2, 'LTE' = 3, 'NR' = 4, 'UMTS' = 5),
....
)

Install apache superset and try to "Add dataset"

Expected behavior

Should work with an empty string in Enums.

Versions
clickhouse-sqlalchemy latest from git
Python version 3.9.2

@afpd
Copy link
Author

afpd commented Oct 8, 2021

Issue persists with the 21.9.4.35 as well

@afpd
Copy link
Author

afpd commented Oct 8, 2021

I suspect enum.Enum('%s_enum' % name, options) can't build a Enum object if SQL enum contains an empty string, which the case for https://clickhouse.com/docs/en/getting-started/example-datasets/cell-towers/

@qoega
Copy link

qoega commented Nov 18, 2021

It is just about that python can't have empty string as Enum name. There is no easy way to do so, so you need to alter schema and rename '' enum key in ClickHouse.

@xzkostyan
Copy link
Owner

It's Python's Enum limitation. Feel free to make a PR or discuss particular solution for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants