Skip to content

Commit

Permalink
Renames views; Adds Dependencies view (#14)
Browse files Browse the repository at this point in the history
Renames views;  Adds Dependencies view
  • Loading branch information
tconbeer authored and drewbanin committed Nov 20, 2018
1 parent f714774 commit 95b3138
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ __View Models__

These views are designed to make debugging your Redshift cluster more straightforward. They are, in effect, materializations of the [Diagnostic Queries for Query Tuning](http://docs.aws.amazon.com/redshift/latest/dg/diagnostic-queries-for-query-tuning.html) from Redshift's documentation.

- [queries](models/views/queries.sql): Simplified view of queries, including explain cost, execution times, and queue times.
- [table_stats](models/views/table_stats.sql): Gives insight on tables in your warehouse. Includes information on sort and dist keys, table size on disk, and more.
- [redshift_admin_queries](models/views/redshift_admin_queries.sql): Simplified view of queries, including explain cost, execution times, and queue times.
- [redshift_admin_table_stats](models/views/redshift_admin_table_stats.sql): Gives insight on tables in your warehouse. Includes information on sort and dist keys, table size on disk, and more.
- [redshift_admin_dependencies](models/views/redshift_admin_dependencies.sql): Simplified view of pg_depend, showing any dependent objects (views) for a given source object

These views are designed to make user privilege management more straightforward.
- [users_table_view_privileges](models/views/users_table_view_privileges.sql): Gives insights into which [privileges](https://docs.aws.amazon.com/redshift/latest/dg/r_HAS_TABLE_PRIVILEGE.html) each user has on each table/view.
Expand Down
4 changes: 2 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ source-paths: ["models"]
macro-paths: ["macros"]
test-paths: ["tests"]

profile: redshift_package

models:
redshift:
base:
materialized: ephemeral

introspection:
materialized: ephemeral

views:
materialized: view
9 changes: 9 additions & 0 deletions models/base/pg_depend.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
select
classid
, objid
, objsubid
, refclassid
, refobjid
, refobjsubid
, deptype
from pg_depend
25 changes: 25 additions & 0 deletions models/views/redshift_admin_dependencies.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{# SOURCE: https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_view_dependency.sql #}

select distinct
srcobj.oid as source_oid
, srcnsp.nspname as source_schemaname
, srcobj.relname as source_objectname
, tgtobj.oid as dependent_oid
, tgtnsp.nspname as dependent_schemaname
, tgtobj.relname as dependent_objectname

from

{{ ref('pg_class') }} as srcobj
join {{ ref('pg_depend') }} as srcdep on srcobj.oid = srcdep.refobjid
join {{ ref('pg_depend') }} as tgtdep on srcdep.objid = tgtdep.objid
join {{ ref('pg_class') }} as tgtobj
on tgtdep.refobjid = tgtobj.oid
and srcobj.oid <> tgtobj.oid
left join {{ ref('pg_namespace') }} as srcnsp
on srcobj.relnamespace = srcnsp.oid
left join {{ ref('pg_namespace') }} tgtnsp on tgtobj.relnamespace = tgtnsp.oid

where
tgtdep.deptype = 'i' --dependency_internal
and tgtobj.relkind = 'v' --i=index, v=view, s=sequence
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 95b3138

Please sign in to comment.