From 02c1f9ac94062c1fe1b11ef9642ba6cd887f8f0e Mon Sep 17 00:00:00 2001 From: Pere Miquel Brull Date: Sun, 29 Jan 2023 08:58:43 +0100 Subject: [PATCH] Update view definition from Vertica dialect (#9980) --- .../ingestion/source/database/vertica/metadata.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ingestion/src/metadata/ingestion/source/database/vertica/metadata.py b/ingestion/src/metadata/ingestion/source/database/vertica/metadata.py index b36d6fc8a7d..411711d08c7 100644 --- a/ingestion/src/metadata/ingestion/source/database/vertica/metadata.py +++ b/ingestion/src/metadata/ingestion/source/database/vertica/metadata.py @@ -215,6 +215,19 @@ def _get_column_info( # pylint: disable=too-many-locals,too-many-branches,too-m def get_view_definition( self, connection, view_name, schema=None, **kw ): # pylint: disable=unused-argument,unused-argument + """ + If we create a view as: + CREATE VIEW vendor_dimension_v AS + SELECT vendor_key, vendor_name + FROM public.vendor_dimension_new; + Then the VIEW_DEFINITION statement from V_CATALOG.VIEWS + will only contain the SELECT query: + SELECT vendor_key, vendor_name + FROM public.vendor_dimension_new; + We will add the `CREATE VIEW XYZ AS` piece + to ensure that the column lineage and target table + can be properly inferred. + """ if schema is not None: schema_condition = f"lower(table_schema) = '{schema.lower()}'" else: @@ -229,7 +242,7 @@ def get_view_definition( ) rows = list(connection.execute(sql_query)) if len(rows) >= 1: - return rows[0][0] + return f"CREATE VIEW {view_name} AS {rows[0][0]}" return None