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

dbt 1.0 #27

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Support for `dbt==1.0.*`

### Removed
- Support for `dbt<1`

## [0.1.10] - 2022-03-03
### Changed
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
![GitHub last commit](https://img.shields.io/github/last-commit/slidoapp/dbt-coverage)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/dbt-coverage)
![PyPI - Format](https://img.shields.io/pypi/format/dbt-coverage)
![dbt versions](https://img.shields.io/badge/dbt-1.0-blue)
<a href="https://github.com/slidoapp/dbt-coverage/blob/main/LICENSE.md"><img alt="License: MIT" src="https://img.shields.io/github/license/slidoapp/dbt-coverage"></a>
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fslidoapp%2Fdbt-coverage.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fslidoapp%2Fdbt-coverage?ref=badge_shield)


_One-stop-shop for docs and test coverage of [`dbt`](https://github.com/dbt-labs/dbt) projects._

Optimized for dbt 1.0, see [full support matrix](#supported-dbt-versions).

## Why do I need something like this?

_**[`dbt-coverage`](https://github.com/slidoapp/dbt-coverage) is to [`dbt`](https://github.com/dbt-labs/dbt) what [`coverage.py`](https://github.com/nedbat/coveragepy) and [`interrogate`](https://interrogate.readthedocs.io/en/latest/) are to Python.**_
Expand Down Expand Up @@ -142,6 +145,17 @@ $ dbt-coverage compute doc --cov-report after.json --cov-fail-compare before.jso
$ dbt-coverage compare after.json before.json # Generate a detailed coverage delta report
```

## Supported `dbt` versions

Different version of `dbt-coverage` support different versions of `dbt`. Here is
the support matrix.

| `dbt` | `dbt-coverage` |
|-------------|----------------|
| <0.20 | not tested |
| 0.20 - 0.21 | 0.1 |
| 1.0 | 0.2 |

## Related packages

- https://github.com/mikaelene/dbt-test-coverage
Expand Down
19 changes: 17 additions & 2 deletions dbt_coverage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

logging.basicConfig(level=logging.INFO)

SUPPORTED_MANIFEST_SCHEMA_VERSION = 'https://schemas.getdbt.com/dbt/manifest/v4.json'

app = typer.Typer(help="Compute coverage of dbt-managed data warehouses.")


Expand Down Expand Up @@ -116,7 +118,7 @@ def _parse_tests(cls, manifest_nodes: Dict[str, Dict]) -> Dict[str, Dict[str, Li
"""Parses tests from manifest.json nodes.

The logic is taken from the dbt-docs official source code:
https://github.com/dbt-labs/dbt-docs/blob/da84e95ab9febde3127ed28ff698516b2a610532/src/app/services/project_service.js#L149-L215
https://github.com/dbt-labs/dbt-docs/blob/02731092389b18d69649fdc322d969b5d5b61b20/src/app/services/project_service.js#L155-L221
"""

id_to_table_name = {table_id: cls._full_table_name(table)
Expand All @@ -125,7 +127,7 @@ def _parse_tests(cls, manifest_nodes: Dict[str, Dict]) -> Dict[str, Dict[str, Li

tests = {}
for node in manifest_nodes.values():
if node['resource_type'] != 'test' or 'schema' not in node['tags']:
if node['resource_type'] != 'test' or 'test_metadata' not in node:
continue

depends_on = node['depends_on']['nodes']
Expand Down Expand Up @@ -486,6 +488,17 @@ def _new_miss_summary_row(self):
return buf.getvalue()


def check_manifest_version(manifest_json):
manifest_version = manifest_json['metadata']['dbt_schema_version']
if manifest_version != SUPPORTED_MANIFEST_SCHEMA_VERSION:
logging.warning(
"Unsupported manifest.json version %s, unexpected behavior can occur. Supported "
"version: %s. See "
"https://github.com/slidoapp/dbt-coverage/tree/main#supported-dbt-versions for more "
"details.", manifest_version, SUPPORTED_MANIFEST_SCHEMA_VERSION
)


def load_catalog(project_dir: Path) -> Catalog:
with open(project_dir / 'target/catalog.json') as f:
catalog_json = json.load(f)
Expand All @@ -502,6 +515,8 @@ def load_manifest(project_dir: Path) -> Manifest:
with open(project_dir / 'target/manifest.json') as f:
manifest_json = json.load(f)

check_manifest_version(manifest_json)

manifest_nodes = {**manifest_json['sources'], **manifest_json['nodes']}
manifest = Manifest.from_nodes(manifest_nodes)

Expand Down