Skip to content

Commit

Permalink
fix(ingest/redshift): Remove pg_user table from metadata queries (#7815)
Browse files Browse the repository at this point in the history
  • Loading branch information
treff7es authored Apr 13, 2023
1 parent ce79540 commit 4ec280e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions metadata-ingestion/src/datahub/ingestion/source/redshift/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class RedshiftQuery:
list_schemas: str = """SELECT database_name,
schema_name,
schema_type,
usename as schema_owner_name,
-- setting user_name to null as we don't use it now now and it breaks backward compatibility due to additional permission need
-- usename as schema_owner_name,
null as schema_owner_name,
schema_option,
NULL::varchar(255) as external_database
FROM SVV_REDSHIFT_SCHEMAS as s
inner join pg_catalog.pg_user_info as i on i.usesysid = s.schema_owner
-- inner join pg_catalog.pg_user_info as i on i.usesysid = s.schema_owner
where schema_name !~ '^pg_'
AND schema_name != 'information_schema'
UNION ALL
Expand All @@ -30,11 +32,13 @@ class RedshiftQuery:
WHEN '4' THEN 'REDSHIFT'
ELSE 'OTHER'
END as schema_type,
usename as schema_owner_name,
-- setting user_name to null as we don't use it now now and it breaks backward compatibility due to additional permission need
-- usename as schema_owner_name,
null as schema_owner_name,
esoptions as schema_option,
databasename as external_database
FROM SVV_EXTERNAL_SCHEMAS as s
inner join pg_catalog.pg_user_info as i on i.usesysid = s.esowner
-- inner join pg_catalog.pg_user_info as i on i.usesysid = s.esowner
ORDER BY database_name,
SCHEMA_NAME;
"""
Expand All @@ -57,7 +61,9 @@ class RedshiftQuery:
WHEN 8 THEN 'ALL'
END AS "diststyle",
c.relowner AS "owner_id",
u.usename AS "owner_name",
-- setting user_name to null as we don't use it now now and it breaks backward compatibility due to additional permission need
-- u.usename AS "owner_name",
null as "owner_name",
TRIM(TRAILING ';' FROM pg_catalog.pg_get_viewdef (c.oid,TRUE)) AS "view_definition",
pg_catalog.array_to_string(c.relacl,'\n') AS "privileges",
NULL as "location",
Expand All @@ -70,7 +76,7 @@ class RedshiftQuery:
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_class_info as ci on c.oid = ci.reloid
LEFT JOIN pg_catalog.pg_description pgd ON pgd.objsubid = 0 AND pgd.objoid = c.oid
JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
-- JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
WHERE c.relkind IN ('r','v','m','S','f')
AND n.nspname !~ '^pg_'
AND n.nspname != 'information_schema'
Expand Down Expand Up @@ -383,14 +389,14 @@ def list_insert_create_queries_sql(
stl_insert as si
join SVV_TABLE_INFO sti on
sti.table_id = tbl
left join pg_user pu on
pu.usesysid = si.userid
left join svl_user_info sui on
si.userid = sui.usesysid
left join stl_query sq on
si.query = sq.query
left join stl_load_commits slc on
slc.query = si.query
where
pu.usename <> 'rdsdb'
sui.usename <> 'rdsdb'
and sq.aborted = 0
and slc.query IS NULL
and cluster = '{db_name}'
Expand Down

0 comments on commit 4ec280e

Please sign in to comment.