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

Allow references in documentation #1437

Closed
jdreaver opened this issue May 2, 2019 · 2 comments
Closed

Allow references in documentation #1437

jdreaver opened this issue May 2, 2019 · 2 comments

Comments

@jdreaver
Copy link

jdreaver commented May 2, 2019

Feature

I've only been using dbt for a day, and it is fantastic!

I searched the documentation and existing issues to see if this feature already exists, but I couldn't find it. If something like this already exists, my apologies, and please close this issue!

Feature description

When documenting a model, I'd like to be able to reference other dbt models. For example:

version: 2

models:
  - name: events
    description: A table containing clickstream events from the marketing website

    columns:
        - name: user_id
          description: The ID of the user who recorded the event. Points to the {{ ref('users') }} table.

Note the sentence Points to the {{ ref('users') }} table. Ideally, this would provide two benefits:

  1. This should produce a hyperlink in the documentation from dbt docs generate.
  2. This acts as a check against referencing a model that has been renamed or removed. If a model is renamed/removed, then ideally these references fail so you know where to update your documentation.

I'm not sure calling this function ref() is the best idea. We might want doc_ref() that allows an argument for the model name like ref, but also maybe another argument like a column name:

Points to the {{ doc_ref('users', 'id') }} column in the {{ doc_ref('users') }} table.

Relation to tests

Clearly you can express this relationship via a test:

tests:
    - relationships:
        to: ref('users')
        field: id

A test isn't quite sufficient for two reasons:

  1. A hyperlink isn't produced in the documentation for tests. (This one could be fixed, probably.)
  2. Sometimes a table points to another table, but there might be e.g. missing users, so the test would fail. That is, there might be some events with a user_id but no corresponding users.id. This is not uncommon in the data warehousing world when pulling/combining data from different sources.

Who will this benefit?

Anyone who uses dbt to document their models would benefit from this. It would make dbt's generated documentation more useful by adding hyperlinks to other models inside documentation and by making sure modifying a model doesn't break any upstream hyperlinks to it.

@drewbanin
Copy link
Contributor

Hey @jdreaver - thanks for the feature request! We're already tracking ref hyperlinks in the docs context here: #1334

I think @beckjake or @cmcarthur suggested using href, which I really like :)

You've also mentioned the relationships test here -- can you say more about that? We received a report that Relationships tests weren't rendering as hyperlinks recently, but I wasn't able to reproduce that error. When a relationships test is defined, the column should link back to the parent model in the documentation website:

Screen Shot 2019-04-25 at 1 20 33 PM

Are you seeing something different?

@jdreaver
Copy link
Author

jdreaver commented May 3, 2019

Thanks for the response @drewbanin!

Ah I must have totally messed up my original test for the foreign key hyperlink feature. Womp womp.

I'll go ahead and follow #1334. Thanks for the heads up!

@jdreaver jdreaver closed this as completed May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants