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

Provide test name and kwargs in test nodes in the manifest #1154

Closed
foundinblank opened this issue Nov 27, 2018 · 3 comments · Fixed by #1816
Closed

Provide test name and kwargs in test nodes in the manifest #1154

foundinblank opened this issue Nov 27, 2018 · 3 comments · Fixed by #1816
Labels
dbt-docs [dbt feature] documentation site, powered by metadata artifacts enhancement New feature or request

Comments

@foundinblank
Copy link

Feature

Feature description

In the documentation website, the columns box shows three different types of built-in schema tests: P, U, N (primary key, unique, not_null). But not for the fourth built-in schema test, accepted_values. It also doesn't show any custom schema tests.

Who will this benefit?

Anyone who uses accepted_values and was expecting to see it in their docs site! For custom schema tests, a single letter would need to be defined...or just stuff the name of it into the Tests column. 🙂

Link to code: https://github.com/fishtown-analytics/dbt-docs/blob/master/src/app/docs/model.html#L126-L134

@drewbanin drewbanin added this to the Wilt Chamberlain milestone Nov 28, 2018
@drewbanin drewbanin added the dbt-docs [dbt feature] documentation site, powered by metadata artifacts label Dec 5, 2018
@drewbanin
Copy link
Contributor

drewbanin commented Mar 23, 2019

This is prioritized for our Wilt Chamberlain release.

If you want to feel sad, have a look at the code responsible for rendering column tests in the docs site. The docs site needs to parse test attributes out of generated test names because dbt is not currently encoding this information in the manifest in a structured way.

In order to delete all of this code, as well as support accepted_values tests, we should add a structured dict to test nodes with the following information:

  1. the name of the test macro
  2. the arguments supplied to the test macro (represented as a dictionary)

The docs site is going to need to semantically know what unique, not_null, etc mean, but I think that's acceptable for now.

In the future, I'd like to make schema tests capable of generating their own descriptions. This would help us render custom schema test information in the docs site. Out of scope for this particular issue, but worth keeping in mind.

Feature spec:

Include a test_definition: (or similar) field in test nodes which contains:

  • the test type
  • the kwargs provided to the test

eg:

{
  "name": "unique_stg_close_opportunities_opportunity_id"
  "raw_sql": "{{ test_unique(model=ref('stg_close_opportunities'), column_name='opportunity_id') }}",
  ...
  "test_definition": {
    "test_type": "schema",
    "test": "unique",
    "options": {
      "model": "ref('stg_close_opportunities')"
      "column_name": "opportunity_id"
    }
  }
}

I think ideally, the model option shown here would read as stg_close_opportunities, not ref('stg_close_opportunities'), but I suspect that might be difficult to implement at the present time. Either one is going to be usable (and much better than what we have now!) in the dbt Docs code.

This will enable us to add accepted values to the docs site, as well as clean up some really gnarly code around relationships tests.

For custom data tests, that field should look like:

{
  "name": "unique_stg_close_opportunities_opportunity_id"
  "raw_sql": "select 1 as id",
  ...
  "test_definition": {
    "test_type": "data"
  }
}

@drewbanin
Copy link
Contributor

Kicking this out of Wilt Chamberlain and into Louisa May Alcott

@drewbanin drewbanin changed the title Add accepted_values and custom schema tests to docs site Provide test name and kwargs in test nodes in the manifest Sep 27, 2019
@drewbanin drewbanin added the enhancement New feature or request label Sep 27, 2019
beckjake added a commit that referenced this issue Oct 10, 2019
…nclude-name-kwargs

add test metadata for schema tests, add test tests (#1154)
@drewbanin
Copy link
Contributor

fyi the corresponding fix for this in the autogenerated docs site was merged and will be live in 0.15.0

Thanks for the initial request - hope you're doing well @foundinblank :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dbt-docs [dbt feature] documentation site, powered by metadata artifacts enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants