diff --git a/ingestion/src/metadata/ingestion/source/database/vertica/queries.py b/ingestion/src/metadata/ingestion/source/database/vertica/queries.py index 38e3ad5f453..8bae6f32f1b 100644 --- a/ingestion/src/metadata/ingestion/source/database/vertica/queries.py +++ b/ingestion/src/metadata/ingestion/source/database/vertica/queries.py @@ -21,22 +21,39 @@ import textwrap # So to fetch column comments we need to concat the table_name + projection infix + column name. # Example: querying `v_catalog.comments` we find an object_name for a column in the table vendor_dimension as # `vendor_dimension_super.vendor_name`. Note how this is the `_super` projection. -# Then, our join looks for the match in `vendor_dimension_%.vendor_name`. +# Then, our join looks for the match in `vendor_dimension_super.vendor_name`. +# In case there are more than one projections available for a table then we pick up +# comments from any one projection available for table # Note: This might not suit for all column scenarios, but currently we did not find a better way to join # v_catalog.comments with v_catalog.columns. VERTICA_GET_COLUMNS = textwrap.dedent( """ - SELECT + WITH + column_projection as + (SELECT + column_name, + data_type, + column_default, + is_nullable, + table_name, + table_schema, + proj.projection_name + FROM v_catalog.columns col, + v_catalog.projections proj + where proj.projection_id in (select + min(projection_id) + from v_catalog.projections sub_proj + where col.table_id=sub_proj.anchor_table_id + )) + select column_name, data_type, column_default, is_nullable, - comment - FROM v_catalog.columns col + comment from column_projection col LEFT JOIN v_catalog.comments com ON com.object_type = 'COLUMN' - AND com.object_id = col.table_id - AND com.child_object = col.column_name + AND com.object_name = CONCAT(CONCAT(col.projection_name,'.'),col.column_name) WHERE lower(table_name) = '{table}' AND {schema_condition} UNION ALL