reata / sqllineage

SQL Lineage Analysis Tool powered by Python
MIT License
1.34k stars 243 forks source link

clickhouse <rename> not handled #642

Open maciejskorski opened 3 months ago

maciejskorski commented 3 months ago

Describe the bug

Consider this SQL in ClickHouse dialect

-- query.txt
RENAME TABLE my_db.app_log_trivial  TO my_db.app_log_trivial_tmp_old;
RENAME TABLE  my_db.app_log_trivial_tmp TO my_db.app_log_trivial;
DROP TABLE my_db.app_log_trivial_tmp_old;

linted with sqllineage 1.5.3 it gives the error

sqllineage -f query.txt -v
Traceback (most recent call last):
  File "/usr/local/bin/sqllineage", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/sqllineage/cli.py", line 127, in main
    runner.print_table_lineage()
  File "/usr/local/lib/python3.10/dist-packages/sqllineage/runner.py", line 179, in print_table_lineage
    print(str(self))
  File "/usr/local/lib/python3.10/dist-packages/sqllineage/runner.py", line 26, in wrapper
    self._eval()
  File "/usr/local/lib/python3.10/dist-packages/sqllineage/runner.py", line 199, in _eval
    stmt_holder = analyzer.analyze(stmt, session.metadata_provider)
  File "/usr/local/lib/python3.10/dist-packages/sqllineage/core/parser/sqlfluff/analyzer.py", line 52, in analyze
    statement_segments = self._list_specific_statement_segment(sql)
  File "/usr/local/lib/python3.10/dist-packages/sqllineage/core/parser/sqlfluff/analyzer.py", line 92, in _list_specific_statement_segment
    raise InvalidSyntaxException(
sqllineage.exceptions.InvalidSyntaxException: This SQL statement is unparsable, please check potential syntax error for SQL:
RENAME TABLE my_db.app_log_trivial  TO my_db.app_log_trivial_tmp_old;
Line 1, Position 1: Found unparsable section: 'RENAME TABLE my_db.app_log_trivial  TO m...'

indicating that sqllineage does not understand RENAME operator.

Furthermore, the check against the backend linter sqlfluff goes OK.

Expected behavior

RENAME is understood and handled correctly.

Python version (available via python --version)

SQLLineage version (available via sqllineage --version):

Additional context Reproduced in Colab