Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support materialized views in get_columns_in_relation #9433

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dbeatty10
Copy link
Contributor

@dbeatty10 dbeatty10 commented Jan 24, 2024

resolves #9419

Important

The contents of this PR should be compared with #7459 since they both touch on the same code and could easily overwrite each other. Ideally, both of them will functional tests so that one doesn't undo the other by accident.

Problem

As described in #9419 (comment), the information_schema.columns view in postgres includes these:

  • o[r]dinary table, [v]iew, [f]oreign table, [p]artitioned table

But it does not include:

  • [m]aterialized view

Solution

Two things:

  1. 531446e Add the full definition of the information_schema.columns view into dbt-postgres.
  2. afaca63 Add 'm'::"char" to the definition so that MVs are included.

Definition of the information_schema.columns view

To get the full text definition of this view, run the following:

select definition 
from pg_catalog.pg_views 
where schemaname = 'information_schema' 
  and viewname = 'columns'

The output is a fairly gnarly query as seen in 531446e

To do

After a quick search, I couldn't find any relevant tests for adapter.get_columns_in_relation, so we'll probably want some that cover all the different types of relations:

  • ephemeral
  • table
  • view
  • materialized view

The tests would basically just need to:

  1. Define a relation with a column or two.
  2. Build it.
  3. Make sure that those columns are returned by adapter.get_columns_in_relation.

I'm assuming that ephemeral will either raise an exception or return nothing, but we'll want to add applicable tests either way.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • 👈 This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc)

@cla-bot cla-bot bot added the cla:yes label Jan 24, 2024
Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2f2e0ce) 87.85% compared to head (01de40f) 87.83%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9433      +/-   ##
==========================================
- Coverage   87.85%   87.83%   -0.03%     
==========================================
  Files         150      150              
  Lines       21915    21915              
==========================================
- Hits        19253    19248       -5     
- Misses       2662     2667       +5     
Flag Coverage Δ
integration 85.28% <ø> (-0.03%) ⬇️
unit 62.39% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] postgres get_columns_in_relation does not include MVs
1 participant