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

Exposure Parsing #38

Merged
merged 129 commits into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
c4ab897
Add .idea to gitignore
Jun 12, 2021
5a463c7
merge changes from read-from-artifacts fork integrating with latest v…
z3z1ma Jun 12, 2021
c2684ab
fix grammatical error and update readme to say semantic type
z3z1ma Jun 13, 2021
cf85f1e
fix error in field lookup key setting and continue to support either …
z3z1ma Jun 13, 2021
2d1d7e0
internally use semantic but support meta refs to special which will b…
z3z1ma Jun 13, 2021
ef7fd20
safe importing of dependent modules in addition to bugfixes, logical …
z3z1ma Jun 13, 2021
24e05e7
added more verbose comments tracking intent as well as ensuring nodes…
z3z1ma Jun 13, 2021
ecb6458
setting fields to PK type is worthy of info logging
z3z1ma Jun 13, 2021
b31b26c
handle cross schema foreign keys with explicit metabase.fk_ref with e…
z3z1ma Jun 13, 2021
3248209
added debug log for validating parsed schema/fields for fk targets an…
z3z1ma Jun 13, 2021
7d7de05
all necessary args added for cli usage. some basic assertions added. …
z3z1ma Jun 13, 2021
4a1bf2e
corrected typo in exclude var and added support for verbosity flag. t…
z3z1ma Jun 13, 2021
c201431
updates to handle aliases when ran via dbt_path (yml parser) ubiquito…
z3z1ma Jun 13, 2021
a7305e7
support for aliased fk refs parsed via parse_ref. backoff of parse re…
z3z1ma Jun 13, 2021
c12cd2b
a blank dict attribute is okay here since we know our refs our clean …
z3z1ma Jun 13, 2021
fb6070c
correct referencing of semantic type and not special
z3z1ma Jun 13, 2021
b550424
arg var renamed back to --database to ensure seamless compatibility/u…
z3z1ma Jun 13, 2021
c4022ac
improve typing ensuring python 3.6+ compatibility, expanduser called …
z3z1ma Jun 13, 2021
a78a93b
explicit Any type hint for consistency
z3z1ma Jun 13, 2021
a241ec0
Use more generic and compatible typing operators. parse ref now guara…
z3z1ma Jun 13, 2021
35e5eff
use mapping for column and express last bit of typing for bool args
z3z1ma Jun 13, 2021
1d9fdd4
re added clarification on semantic types being formerly known as spec…
z3z1ma Jun 13, 2021
cce2f8e
Following best practices, declare default args for lists as none sett…
z3z1ma Jun 13, 2021
fae0cf5
docstrings to reflect default arg is None
z3z1ma Jun 13, 2021
e8c99a1
Merge remote-tracking branch 'upstream/master'
z3z1ma Jun 13, 2021
a7c113e
updates to ensure use of warning instead of warn on logger, added __i…
z3z1ma Jun 13, 2021
cbfc841
simplified typing and ensure type tests pass
z3z1ma Jun 14, 2021
bcb75fb
more typing updates
z3z1ma Jun 14, 2021
c10d482
added mutablemapping types
z3z1ma Jun 14, 2021
0837a5d
explicit type for reader as being either manifest or yml
z3z1ma Jun 14, 2021
3f2842a
update tests to run on updated structure
z3z1ma Jun 14, 2021
9425f67
point to right module for manifest reader
z3z1ma Jun 14, 2021
41bbec8
use same keyword arg as other reader for uniformity
z3z1ma Jun 14, 2021
db3ff70
format and fix req dev pointer
z3z1ma Jun 18, 2021
f08b875
tests include assertions and dummy data from jaffle shop dbt classic …
z3z1ma Jun 18, 2021
4cd79b8
include a compiled manifest.json for test
z3z1ma Jun 18, 2021
e63df93
ensure schema cast to upper for uniformity.
z3z1ma Jun 18, 2021
7c0d7e7
added last upper() call in folder parser.
z3z1ma Jun 18, 2021
20f52b2
move tests to fixtures folder and remove dummy CI tests
z3z1ma Jun 27, 2021
1d0810c
tests point to correct sample proj path
z3z1ma Jun 27, 2021
cf95ba3
maintain expected default for sync and https, normalize help str text…
z3z1ma Jun 27, 2021
1afc759
make verify typing more specific
z3z1ma Jun 27, 2021
3525031
union typing with commas, not pipe
z3z1ma Jun 27, 2021
5e4e35c
remove double import
z3z1ma Jun 27, 2021
9b118aa
let timeout type check as optional setting val if None in func
z3z1ma Jun 27, 2021
9382b86
remove unecessary os path join
z3z1ma Jun 28, 2021
1209734
remove unecessary "" defaults for gets compared to literals
z3z1ma Jun 28, 2021
ef1244d
use f strings for readability
z3z1ma Jun 28, 2021
6f3efa3
removed two end of line periods for uniformity in console help msg
z3z1ma Jun 28, 2021
d2e1cff
fixed unintentional changes to readme
z3z1ma Jun 28, 2021
b8a638f
move ternary to separate statement for cleanliness
z3z1ma Jun 28, 2021
02e5b9b
Merge branch 'master' into master
z3z1ma Jun 29, 2021
069cb12
Merge branch 'master' into master
gouline Jun 29, 2021
462bbe6
update dev req txt to name referred to in setup
z3z1ma Jun 29, 2021
33fb285
fix misnamed test requirements to one specified in CI pipeline
z3z1ma Jun 29, 2021
7035bd0
update integrated str checks to use class model attributes
z3z1ma Jun 29, 2021
f9e2e2d
fix ref to requirements-test
z3z1ma Jun 29, 2021
d043d58
use class attribute to populate variable so we can set to None or str…
z3z1ma Jun 29, 2021
3fa35a3
added some nice debug logging messages to any model passed over in ma…
z3z1ma Jun 29, 2021
a69e753
include sources propagation as provided in yml parser with the benefi…
z3z1ma Jun 29, 2021
44a52c3
since we share so many args, make primary export function agnostic di…
z3z1ma Jul 3, 2021
729a5c1
initial fully functional auto exposure export func built out
z3z1ma Jul 3, 2021
7a44823
added some model fields to support differentiating between source / r…
z3z1ma Jul 3, 2021
3799d92
build dbt ref/source jinja during model parsing as well as logging mo…
z3z1ma Jul 3, 2021
c1e6022
Merge branch 'master' into exposure-parsing
z3z1ma Jul 3, 2021
e0bf3e4
placeholder for dataset query to be base64 encoded in exploratory lin…
z3z1ma Jul 16, 2021
fc142bb
Merge branch 'master' into exposure-parsing
z3z1ma Jul 16, 2021
2ae424c
add assertions for commands, uniform dbt docs url arg
z3z1ma Jul 16, 2021
8cdf6fa
add recursions for extract card capable of extracting saved questions…
z3z1ma Jul 16, 2021
0ba8e28
uniformity in argument dbt_docs -> dbt_docs_url
z3z1ma Jul 16, 2021
5447205
much more detailed documentation provided for metabase analytics.
z3z1ma Jul 16, 2021
af9bd44
added new model_key and ref to unit tests
z3z1ma Jul 17, 2021
fdb8fb6
some typing updates
z3z1ma Jul 17, 2021
0cc5666
Merge branch 'master' into exposure-parsing
z3z1ma Jul 17, 2021
5d384fc
schema arg is unused for now
z3z1ma Jul 17, 2021
e17a9ff
Merge branch 'exposure-parsing' of https://github.com/z3z1ma/dbt-meta…
z3z1ma Jul 17, 2021
9f6f8f4
preparing to update the docs
z3z1ma Jul 17, 2021
e35d65a
add missing argvars for exposure parsing, default output args in work…
z3z1ma Jul 18, 2021
4cd0bf6
remove default schema arg so we propagate down into manifest reader s…
z3z1ma Jul 20, 2021
cd1ff65
remove alpha sorting so we preserve our constructed format
z3z1ma Jul 20, 2021
849a5b7
give folder reader a default schema since it should have a separate i…
z3z1ma Jul 20, 2021
56327ab
properly allow schema agnostic parsing if schema is not passed since …
z3z1ma Jul 20, 2021
82b1f77
Merge branch 'master' into exposures
z3z1ma Jul 21, 2021
8747a67
typing fix for schema arg
z3z1ma Jul 21, 2021
53d69bc
Merge branch 'exposures' of https://github.com/z3z1ma/dbt-metabase in…
z3z1ma Jul 21, 2021
8985d17
remove unused type
z3z1ma Jul 21, 2021
7edd99b
populating mock api for current and future testing
Jul 21, 2021
30b18d3
pre ran jaffle shop with artifacts
Jul 21, 2021
d7513d7
moved mock api to api sub dir to play very nicely with mock client ap…
Jul 21, 2021
46df15e
exposure extractor will return its output dict
Jul 21, 2021
8cf659f
test suite utils for dbt-metabase for recreating any test files
Jul 21, 2021
e53f5d8
unit tests for exposure parser complete
Jul 21, 2021
0edcdea
fixed test to conform to freshly ran manifest on fresh db, old manife…
Jul 21, 2021
2f83e4f
ensure arg to the fresh db name used when compiling artifacts
Jul 21, 2021
7eae924
leave the artifact for user introspection
Jul 21, 2021
e34b0d7
added lookup artifacts generated from api calls
Jul 21, 2021
b61058c
util func to rebuild lookup artifacts
Jul 21, 2021
b5cac02
added unit test for metadata lookups
Jul 21, 2021
12ec457
remove func call at bottom
Jul 21, 2021
bc540ce
updates to include exposure parsing documentation usage
Jul 21, 2021
8800ad3
mock api clean up of user field
Jul 22, 2021
62abf99
simplified personal collection check to use personal id key
Jul 22, 2021
4c0bd7f
removed dbt docs param from exposure parse, and small grammatical fixes
Jul 22, 2021
932d536
removed uneccessary mb prefix
Jul 22, 2021
9ed67b0
overhaul to dbt-metabase cli interface and programmatic interface usi…
Jul 22, 2021
e4399e1
removed extra arg, fixed missing t in command, and tested CLI in prod…
Jul 22, 2021
0264260
use get instead of key because root does not have personal id in keys
Jul 22, 2021
245a0fe
use dbt_models as arg to preserve models as main func name synonymous…
Jul 22, 2021
c926bc5
dropped empty init to lint properly, we have an init in parent and ac…
Jul 22, 2021
51a1047
pass bool to personal collection arg default, re-add init
Jul 22, 2021
6780538
add default to exclude arg
Jul 22, 2021
be312a0
relative imports make more sense here namespace wise and pass linter
Jul 22, 2021
5370c2b
show defaults for command specific optional args
Jul 22, 2021
58d83dc
last bits of updates to readme to match updated programmatic interface
Jul 22, 2021
e01d3bb
fix type in our
Jul 22, 2021
32f409c
more accurate help string
Jul 22, 2021
1ab908b
Merge branch 'master' into exposures
z3z1ma Jul 27, 2021
5d4af9e
rename args prefixing dbt_ and add schema arg back to cli
Jul 27, 2021
fa4ab12
Merge branch 'exposures' of https://github.com/z3z1ma/dbt-metabase in…
Jul 27, 2021
7fd6a5b
name iterable in such a way not conflict with var name in same scope
Jul 27, 2021
c541db7
use DbtConfig as class name, docs_url when in dbt only context, and u…
Jul 30, 2021
8f3e372
all config args now match cli dest args exactly
Jul 30, 2021
9d3e2f4
updated readme to reflect args in programmatic section
Jul 30, 2021
e43c09a
update args to configs to not have prefix, unneeded
Aug 1, 2021
af20200
added const resource version to exposure func, made output path defau…
Aug 1, 2021
34b8a1d
simplify nested if with a force cast so we can call startswith regard…
Aug 1, 2021
c26f713
updated dumper to indent sequences as dbt documents show
Aug 1, 2021
56aca9f
refactor for readability improvements and easier flow tracing
Aug 1, 2021
99b9075
final polishing improvements, documentation, and large readability im…
Aug 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 92 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The main features provided by dbt-metabase are:
* Propagating columns description to Metabase
* Propagating columns semantic types and visibility types to Metabase through the use of dbt meta fields
* Propagating table relationships represented as dbt ``relationships`` column tests
* Extracting dbt model exposures from Metabase and generating YAML files to be included and revisioned with your dbt deployment


Usage
=====
Expand Down Expand Up @@ -110,6 +112,63 @@ Check your Metabase instance by going into Settings > Admin > Data Model, you
will notice that ``ID`` in ``STG_USERS`` is now marked as "Entity Key" and
``GROUP_ID`` is marked as "Foreign Key" pointing to ``ID`` in ``STG_GROUPS``.

Exposure Extraction
-------------------

dbt-metabase also allows us to extract exposures from Metabase. The invocation is almost identical to
our export function with the addition of output name and location args. `dbt exposures`_ let us understand
how our dbt models are exposed in BI which closes the loop between ELT, modelling, and consumption.


.. _`dbt exposures`: https://docs.getdbt.com/docs/building-a-dbt-project/exposures


.. code-block:: shell

dbt-metabase exposures \
--dbt_manifest_path ./target/manifest.json \
--dbt_database business \
--metabase_host metabase.example.com \
--metabase_user [email protected] \
--metabase_password Password123 \
--metabase_database business \
--output_path ./models/ \
--output_name metabase_exposures

Once execution completes, a look at the output ``metabase_exposures.yml`` will
reveal all metabase exposures documented with the documentation, descriptions, creator
emails & names, links to exposures, and even native SQL propagated over from Metabase.

.. code-block:: yaml

exposures:
- name: Number_of_orders_over_time
description: '
### Visualization: Line

A line chart depicting how order volume changes over time

#### Metadata

Metabase Id: __8__

Created On: __2021-07-21T08:01:38.016244Z__'
type: analysis
url: http://your.metabase.com/card/8
maturity: medium
owner:
name: Indiana Jones
email: [email protected]
depends_on:
- ref('orders')
z3z1ma marked this conversation as resolved.
Show resolved Hide resolved

Questions which are native queries will have the SQL propagated to a code block in the documentation's
description for full visibility. This YAML, like the rest of your dbt project can be committed to source
control to understand how exposures change over time. In a production environment, one can trigger
``dbt docs generate`` after ``dbt-metabase exposures`` (or alternatively run the exposure extraction job
on a cadence every X days) in order to keep a dbt docs site fully synchronized with BI. This makes ``dbt docs`` a
useful utility for introspecting the data model from source -> consumption with zero extra/repeated human input.

Reading your dbt project
------------------------

Expand Down Expand Up @@ -260,26 +319,43 @@ line. But if you prefer to call it from your code, here's how to do it:

import dbtmetabase

dbtmetabase.export(
dbt_database=dbt_database,
dbt_manifest_path=dbt_manifest_path,
dbt_path=dbt_path,
# Collect Args the Build Configs #

metabase_config = MetabaseConfig(
metabase_host=metabase_host,
metabase_user=metabase_user,
metabase_password=metabase_password,
metabase_use_http=metabase_use_http,
metabase_verify=metabase_verify,
metabase_database=metabase_database,
metabase_sync_skip=metabase_sync_skip,
metabase_sync_timeout=metabase_sync_timeout,
)

dbt_config = dbtConfig(
dbt_path=dbt_path,
dbt_manifest_path=dbt_manifest_path,
dbt_database=dbt_database,
schema_excludes=schema_excludes,
includes=includes,
excludes=excludes,
)

dbtmetabase.models(
metabase_config=metabase_config,
dbt_config=dbt_config,
dbt_docs_url=dbt_docs,
metabase_database=metabase_database,
metabase_host=metabase_host,
metabase_user=metabase_user,
metabase_password=metabase_password,
metabase_use_http=metabase_use_http,
metabase_verify=metabase_verify,
metabase_sync_skip=metabase_sync_skip,
metabase_sync_timeout=metabase_sync_timeout,
schema=schema,
schema_excludes=schema_excludes,
includes=includes,
excludes=excludes,
include_tags=include_tags,
)

dbtmetabase.exposures(
metabase_config=metabase_config,
dbt_config=dbt_config,
output_path=output_path,
output_name=output_name,
)


Code of Conduct
===============

Expand Down
Loading