starrocks icon indicating copy to clipboard operation
starrocks copied to clipboard

can not use python client to reflect the table

Open asdfsx opened this issue 1 year ago • 1 comments

I use the following code to reflect table

from sqlalchemy import create_engine, text, Table, MetaData
engine = create_engine("starrocks://[email protected]:61031/default_catalog.graph", echo=True)
with engine.connect() as conn:
    metadata = MetaData()
    metadata.reflect(bind=conn)

but got the following error

2024-10-21 07:09:52,531 INFO sqlalchemy.engine.Engine SELECT DATABASE()
2024-10-21 07:09:52,531 INFO sqlalchemy.engine.Engine [raw sql] {}
2024-10-21 07:09:52,610 INFO sqlalchemy.engine.Engine SHOW VARIABLES LIKE 'sql_mode'
2024-10-21 07:09:52,611 INFO sqlalchemy.engine.Engine [raw sql] {}
2024-10-21 07:09:52,643 INFO sqlalchemy.engine.Engine SHOW VARIABLES LIKE 'lower_case_table_names'
2024-10-21 07:09:52,643 INFO sqlalchemy.engine.Engine [raw sql] {}
2024-10-21 07:09:52,711 INFO sqlalchemy.engine.Engine SHOW FULL TABLES FROM `graph`
2024-10-21 07:09:52,711 INFO sqlalchemy.engine.Engine [raw sql] {}
2024-10-21 07:09:52,751 INFO sqlalchemy.engine.Engine SHOW CREATE TABLE `data_quality_task_result`
2024-10-21 07:09:52,751 INFO sqlalchemy.engine.Engine [raw sql] {}
Traceback (most recent call last):
  File "/app/mlxtend/main.py", line 60, in <module>
    main()
  File "/app/mlxtend/main.py", line 57, in main
    export_tmp_rel_http_mysql(conn, output_path)
  File "/app/mlxtend/main.py", line 34, in export_tmp_rel_http_mysql
    metadata.reflect(bind=conn)
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 4901, in reflect
    Table(name, self, **reflect_opts)
  File "<string>", line 2, in __new__
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 375, in warned
    return fn(*args, **kwargs)
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 618, in __new__
    with util.safe_reraise():
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 614, in __new__
    table._init(name, metadata, *args, **kw)
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 689, in _init
    self._autoload(
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 724, in _autoload
    conn_insp.reflect_table(
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/engine/reflection.py", line 757, in reflect_table
    tbl_opts = self.get_table_options(
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/engine/reflection.py", line 398, in get_table_options
    return self.dialect.get_table_options(
  File "<string>", line 2, in get_table_options
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/engine/reflection.py", line 55, in cache
    ret = fn(self, con, *args, **kw)
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/dialects/mysql/base.py", line 2828, in get_table_options
    parsed_state = self._parsed_state_or_create(
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/dialects/mysql/base.py", line 3085, in _parsed_state_or_create
    return self._setup_parser(
  File "<string>", line 2, in _setup_parser
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/engine/reflection.py", line 55, in cache
    ret = fn(self, con, *args, **kw)
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/sqlalchemy/dialects/mysql/base.py", line 3121, in _setup_parser
    return parser.parse(sql, charset)
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/starrocks/reflection.py", line 58, in parse
    self._parse_table_options(re.split(r"\r?\n", show_create.rsplit(') ')[-1]), state)
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/starrocks/reflection.py", line 223, in _parse_table_options
    skip_lines = self._parse_partition_desc(lines, index, state)
  File "/app/mlxtend/.venv/lib/python3.10/site-packages/starrocks/reflection.py", line 301, in _parse_partition_desc
    state.table_options["%s_%s" % (self.dialect.name, "partition_by")] = m.group("partition")
IndexError: no such group

I thought the problem is caused by the regex

self._re_partition = _re_compile(r"(?:.*)?PARTITION(?:.*)")

It doesn't define a group named partition

maybe the regex should be

self._re_partition = _re_compile(r"PARTITION BY (?P<partition>.*)")

asdfsx avatar Oct 21 '24 07:10 asdfsx

this bug is similar to #45149 @jaogoy

asdfsx avatar Oct 21 '24 07:10 asdfsx

We have marked this issue as stale because it has been inactive for 6 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to StarRocks!

github-actions[bot] avatar Apr 21 '25 11:04 github-actions[bot]

@asdfsx It should be fixed by https://github.com/StarRocks/starrocks/pull/56673, you can check it.

jaogoy avatar Jul 28 '25 08:07 jaogoy