Fix #4924: Clickhouse view lineage (#4929)

* Fix: Clickhouse view lineage

* Fix: Clickhouse view lineage

* Fix: Clickhouse view lineage
This commit is contained in:
Milan Bariya 2022-05-13 16:11:43 +05:30 committed by GitHub
parent 4ef1f4b729
commit 55b6fca9c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,9 @@ from sqlalchemy import util as sa_util
from sqlalchemy.engine import reflection
from sqlalchemy.util import warn
from metadata.generated.schema.entity.services.connections.database.clickhouseConnection import (
ClickhouseConnection,
)
from metadata.generated.schema.entity.services.connections.metadata.openMetadataConnection import (
OpenMetadataConnection,
)
@ -136,15 +139,23 @@ def get_table_comment(self, connection, table_name, schema=None, **kw):
return {"text": None}
@reflection.cache
def get_view_definition(self, connection, view_name, schema=None, **kw):
try:
query = f"select create_table_query from system.tables where engine = 'View' and name='{view_name}' and database='{schema}'"
result = connection.execute(query)
view_definition = result.fetchone()
return view_definition[0] if view_definition else ""
except Exception:
return ""
ClickHouseDialect.get_unique_constraints = get_unique_constraints
ClickHouseDialect.get_pk_constraint = get_pk_constraint
ClickHouseDialect._get_column_type = _get_column_type
ClickHouseDialect.get_table_comment = get_table_comment
RequestsTransport.execute = execute
from metadata.generated.schema.entity.services.connections.database.clickhouseConnection import (
ClickhouseConnection,
)
ClickHouseDialect.get_view_definition = get_view_definition
class ClickhouseSource(SQLSource):