MINOR: Snowflake View Definition Fallback (#21296)

This commit is contained in:
Mayur Singal 2025-05-20 15:18:34 +05:30 committed by GitHub
parent 7a6465c038
commit 2fd0606cdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

@ -414,6 +414,10 @@ FROM information_schema.views
WHERE view_definition is not null
"""
SNOWFLAKE_GET_VIEW_DDL = """
SELECT GET_DDL('VIEW','{view_name}') AS \"text\"
"""
SNOWFLAKE_GET_STREAM_DEFINITION = """
SELECT GET_DDL('STREAM','{stream_name}') AS \"text\"
"""

View File

@ -41,6 +41,7 @@ from metadata.ingestion.source.database.snowflake.queries import (
SNOWFLAKE_GET_STREAM_NAMES,
SNOWFLAKE_GET_TABLE_DDL,
SNOWFLAKE_GET_TRANSIENT_NAMES,
SNOWFLAKE_GET_VIEW_DDL,
SNOWFLAKE_GET_VIEW_DEFINITION,
SNOWFLAKE_GET_VIEW_NAMES,
SNOWFLAKE_GET_WITHOUT_TRANSIENT_TABLE_NAMES,
@ -286,13 +287,29 @@ def get_stream_names(self, connection, schema, **kw):
def get_view_definition(
self, connection, table_name, schema=None, **kw
): # pylint: disable=unused-argument
return get_view_definition_wrapper(
view_definition = get_view_definition_wrapper(
self,
connection,
table_name=table_name,
schema=schema,
query=SNOWFLAKE_GET_VIEW_DEFINITION,
)
if view_definition:
return view_definition
# If the view definition is not found via optimized query,
# we need to get the view definition from the view ddl
schema = schema or self.default_schema_name
view_name = f"{schema}.{table_name}" if schema else table_name
cursor = connection.execute(SNOWFLAKE_GET_VIEW_DDL.format(view_name=view_name))
try:
result = cursor.fetchone()
if result:
return result[0]
except Exception:
pass
return None
@reflection.cache