# dbt and the data.world Collector

### Note

The latest version of the Collector is 2.128. To view the release notes for this version and all previous versions, please go here.

The dbt collector processes artifacts from your dbt Core project to harvest dbt assets and lineage relationships from dbt transformations.

### How does the dbt collector work?

The collector will harvest metadata from dbt generated files.

The dbt collector will also identify how dbt moves data between tables (i.e., lineage). To accomplish this, the dbt collector needs to parse View SQL. Without specifying the target database information, no lineage relationships between columns specified through views can be harvested. The connection information is passed in via dbt’s profiles.yml file or can be supplied with the data.world YAML file or CLI command.

Note that the collector however does not harvest everything that the target database collector would harvest. For example, Snowflake can harvest profiling, tags, and policies that the dbt collector will not harvest. It is recommended to run both the dbt collector and the target database collector to build a comprehensive data catalog.

### Supported versions of dbt

The collector supports the following dbt versions:

• dbt 1.0.5

• dbt 1.1.0

### Authentication supported

The collector supports the following authentication methods to the target databases:

When authenticating to Snowflake, the collector also supports:

• Username and key pair authentication.

### What is cataloged

The information cataloged by the collector includes metadata for the following dbt resources:

Table 1.

Object

Information cataloged

Analysis

Name, Description, Path, Root path, Package name, Unique ID, Alias, Meta, Raw SQL, Compiled SQL, Enabled, Materialized, Resource type

Model

Name, Description, Path, Root path, Package name,Unique ID, Alias, Meta, Raw SQL, Compiled SQL, Enabled, Materialized, Resource type

Project

Name, Project version

Snapshot

Name, Description, Path, Root path, Package name, Unique ID, Alias, Meta, Raw SQL, Compiled SQL, Enabled, Materialized, Resource type

Seed

Name, Description, Path, Root path, Package name, Unique ID, Alias, Meta, Raw SQL, Compiled SQL, Enabled, Materialized, Resource type

Source

Name, Description, Path, Root path, Package name, Unique ID, Alias, Meta, Raw SQL, Compiled SQL, Enabled, Source name, Resource type

Test

Name, Description, Path, Root path, Package name, Unique ID, Alias, Meta, Raw SQL, Compiled SQL, Enabled, Materialized, Resource type

### Relationships between objects

By default, the harvested metadata includes catalog pages for the following resource types. Each catalog page has a relationship to the other related resource types. If the metadata presentation for this data source has been customized with the help of the data.world Solutions team, you may see other resource pages and relationships.

Table 2.

Resource page

Relationship

Model

• Project containing dbt model

• Tests testing the integrity of model, dbt resources (test, seed, model, snapshot, source) that are upstream of model

• dbt resources (test, seed, model, snapshot, source) that are downstream of model

Project

• Dbt resources (test, seed, model, snapshot, source) contained within project

Snapshot

• Project containing dbt project

• dbt resources (test, seed, model, source) that are upstream of snapshot

• dbt resources (test, seed, model, source) that are downstream of snapshot

Seed

• Project containing dbt project

• dbt resources (test, seed, model, snapshot, source) that are upstream of seed

• dbt resources (test, seed, model, snapshot, source) that are downstream of seed

Source

• Project containing dbt project

• dbt resources (test, seed, model, snapshot) that are downstream of seed

• database table that is the source of data for source

Test

• Project containing dbt project

• dbt model that has its integrity tested by this test

### Lineage for dbt

• Relationships between views and referenced database tables and columns for dbt models materialized as views

• Relationships between dbt resources and the resources that are upstream and downstream (e.g., seeds that are upstream of models, and tests that are downstream of models)

The collector also harvests column-level lineage for the following databases in the dbt collector:

• PostgreSQL

• Redshift

• Snowflake

## Pre-requisites for running the collector

Table 3.

Item

Requirement

Hardware

RAM

8 GB

CPU

2 Ghz processor

Software

Docker

Java Runtime Environment

OpenJDK 17 is supported and available here.

data.world specific objects

Dataset

You must have a ddw-catalogs (or other) dataset set up to hold your catalog files when you are done running the collector.

## Preparing dbt for collectors

Harvesting metadata from dbt artifacts themselves requires that the artifact files be in a filesystem directory for which the user running the collector has at least read access. In order to harvest intra-database (column-level) lineage for dbt models materialized as views, the collector must be provided with a credential to dbt’s target database that has SELECT privileges on those views and tables referenced by those views. This database credential can be supplied via CLI options or obtained from the profiles.yml file.

### Generating dbt metadata artifacts to pass to the collector

• profiles.yml - It is located in the ~/.dbt directory by default. For more information see the dbt connection profiles documentation.

• dbt_project.yml - Is found at the top level of the dbt project.

• catalog.json, manifest.json and run_results.json - These files can be generated by running the command dbt docs generate. More information is available here and here.

### Important

The files catalog.json, manifest.json , and profiles.yml must be in the same directory on the host machine. For example, /artifact_directory.

## Generating the command or YAML file

This section walks you through the process of generating the command or YAML file for running the collector from Windows or Linux or MAC OS.

To generate the command or YAML file:

1. On the Organization profile page, go to the Settings tab > Metadata collectors section.

2. Click the Help me set up a collector button.

3. On the On-prem collector setup prerequisites screen, read the pre-requisites and click Next.

4. On the On which platform will this collector execute? screen, select if you will be running the collector on Windows or Mac OS or Linux. This will determine the format of the YAML and CLI that is generated in the end. Click Next.

5. On the Choose metadata collector type you would like to setup screen, select dbt. Click Next.

6. On the Configure a new on premises dbt Collector screen, set the following properties and click Next.

Table 4.

Field name

Corresponding parameter name

Description

Required?

data.world API token

-t=<apiToken>

--api-token=<apiToken>

The data.world API token to use for authentication. Default is to use an environment variable named ${DW_AUTH_TOKEN}. Yes Output Directory -o=<outputDir> --output=<outputDir> The output directory into which any catalog files should be written. Yes Collection Name -n=<catalogName> -n=<catalogName> The name of the collection where the collector output will be stored. Yes Automatic upload location --upload-location=<uploadLocation> The dataset to which the catalog is to be uploaded. You can specify a simple dataset name to upload to that dataset within the organization's account, or [account/dataset] to upload to a dataset in some other account. Yes data.world API host -H=<apiHost> --api-host=<apiHost> The host for the data.world API. NOTE: This parameter is required for Private instances and single-tenant installations. For example, "api.8bank.data.world" where "8bank" is the name of the single-tenant install. Yes (for single-tenant installations) 7. On the next screen, set the following properties and click Next. Table 5. Field name Corresponding parameter name Description Required? dbt Artifactory Directory -d=<artifactDirectory> --artifact-directory=<artifactDirectory> The directory containing the dbt catalog.json, manifest.json, profiles.yml, dbt_project.yml, and run_results.json. Without run_results.json, the emitted catalog will not contain activity information, but will otherwise be complete. Yes dbt Profile File -P=<profileFile> --profile-file=<profileFile> The file containing profile definitions (defaults to dbt default of .dbt/profiles.yml in the user's home directory) No dbt Profile -p=<profile>--profile=<profile> The dbt profile to use to obtain database location information (defaults to first profile found in profile definitions file) No dbt Target Profile -g=<target> --target=<target> The dbt profile target to use to obtain database location information (defaults to the profile's 'target' value) No 8. On the next screen, first select the Targetdatabase. Options available are: PostgreSQL, Snowflake, Bigquery. You would use these options to override the connection information from the dbt profile file or if the dbt profile file is not provided. For the PostgreSQL database, set the following properties and click Next. Table 6. Field name Corresponding parameter name Description Required? Server --database-server=<databaseServer> The server/host for the target database. No Server port --database-port=<databasePort> The port for the target database. No Database --database=<database> The name of the target database. No Username --database-user=<databaseUser> The user credential to use in connecting to the target database. No Password --database-password=<databasePassword> The password credential to use in connecting to the target database. Default value is environment variable${DW_DBT_PASSWORD}.

No

9. If you selected the Target database as Snowflake, set the following properties and click Next.

Table 7.

Field name

Corresponding parameter name

Description

Required?

Snowflake Account

--snowflake-account=<snowflakeAccount>

The Snowflake account/tenant. You can use --database-server as an alternative.)

No

Server

-s=<server>

--server=<server>

The hostname of the database server to connect to.

No

Server port

-p=<port>

--port=<port>

The port of the database server (if not the default).

No

Snowflake Account

--snowflake-account=<snowflakeAccount>

The Snowflake account/tenan.

You can use --database-server as an alternative.

No

Authentication

Select from one of the following options:

• Authenticate using a private key file

-u=<user>

--user=<user>

The username used to connect to the database.

No

The environment variable of the password used to connect to the database. We recommend that you use an environment variable ${DW_SNOWFLAKE_PASSWORD} for this parameter. No Authenticate using a private key file Snowflake Private Key File --snowflake-private-key-file=<snowflakePrivateKey> The private key file to use for authentication with Snowflake (for example rsa_key.p8). No Snowflake Private Key Password --snowflake-private-key-file-password=<snowflakePrivateKeyFilePassword> The password for the private key file to use for authentication with Snowflake, if the key is encrypted and a password was set. Set it as an environment variable${DW_SNOWFLAKE_PK_PASSWORD}.

No

Database

--database=<database>

The name of the target database.

No

Snowflake Application

--snowflake-application=<snowflakeApplication>

The application connection parameter to use in connecting to the target Snowflake database. Use datadotworld unless otherwise directed.

No

Snowflake Role

----snowflake-role=<snowflakeDatbaseRole>

The role to use in connecting to the target Snowflake database. This is case-insensitive.

No

Snowflake Warehouse

--snowflake-warehouse=<snowflakeDatbaseWarehouse>

The warehouse to use in connecting to the target Snowflake database. This is case-insensitive.

No

10. If you selected the Target database as BigQuery, set the following property and click Next.

Table 8.

Field name

Corresponding parameter name

Description

Required?

BigQuery Account Credentials File

--bigquery-credentials-file=<bigqueryCredentialsFile>

The file containing bigquery service account credentials. This applies only to models with bigquery references.

If provided, the bigquery project id is read from this file, otherwise the bigquery project in the profile file is used.

No

11. On the Finalize your dbt Collector configuration screen, you are notified about the environment variables and directories you need to setup for running the collector. Select if you want to generate a Configuration file( YAML) or Command line arguments (CLI). Click Next.

### Important

You must ensure that you have set up these environment variables and directories before you run the collector.

12. The next screen gives you an option to download the YAML configuration file or copy the CLI command. Click Done. If you are generated a YAML file, click Next.

Sample YAML file.

13. The dbt command screen gives you the command to use for running the collector using the YAML file.

14. You will notice that the YAML/CLI has following additional parameters that are automatically set for you.

Table 9.

Parameter name

Details

Required?

--b=<base>

--base=<base>

The base URI to use as the namespace for any URIs generated.

(Must use this OR --agent)

Yes

(If agent is not provided)

-a=<agent>

--agent=<agent>

--account=<agent>

The CLI and YAML file incudes the base parameter. If you want, you can instead use the agent parameter.

The ID for the data.world account into which you will load this catalog - this is used to generate the namespace for any URIs generated.

(Must include either --agent or --base)

Yes

(if base parameter is not provided)

--site=<site>

This parameter should be set only for Private instances. Do not set it for public instances and single-tenant installations. Required for private instance installations.

Yes (required for private instance installations)

-L

Do not upload the log of the Collector run to the organization account's catalogs dataset or to another location specified with --upload-location(ignored if --upload not specified)

Yes

dwcc:<CollectorVersion>

The version of the collector you want to use (For example, datadotworld/dwcc:2.113)

Yes

15. Add the following parameter if you are using a sparql query to execute to transform the catalog graph emitted by the collector.

• -z=<postProcessSparq>--post-process-sparql=<postProcessSparql>: A file containing a sparql query to execute to transform the catalog graph emitted by the collector.

## Verifying environment variables and directories

1. Verify that you have set up all the required environment variables that were identified by the Collector Wizard before running the collector. Alternatively, you can set these credentials in a credential vault and use a script to retrieve those credentials.

2. Verify that you have set up all the required directories that were identified by the Collector Wizard.

## Running the collector

### Important

Before you begin running the collector make sure you have the correct version of collectors downloaded and available.

### Running collector using YAML file

1. Go to the server where you have setup docker to run the collector.

2. Make sure you have download the correct version of collectors. This version should match the version of the collector specified in the YAML/CLI generated from the collector wizard.

3. Place the YAML file generated from the Collector wizard to the correct directory.

4. From the command line, run the command generated from the application for executing the YAML file.

### Caution

Note that is just a sample command for showing the syntax. You must generate the command specific to your setup from the application UI.

docker run -it --rm --mount type=bind,source=${HOME}/dwcc,target=/dwcc-output \ --mount type=bind,source=${HOME}/dwcc,target=${HOME}/dwcc --mount type=bind,source=${HOME]/artifactDirectory,target=${HOME]/artifactDirectory \ --mount type=bind,source=,target= --mount type=bind,source=creds.json,target=creds.json \ -e DW_AUTH_TOKEN=${DW_AUTH_TOKEN} datadotworld/dwcc:2.124 --config-file=/dwcc-output/config-dbt.yml
5. The collector automatically uploads the file to the specified dataset and you can also find the output at the location you specified while running the collector.

6. At a later point, if you download a newer version of collector from docker, you can edit the collector version in the generated command to run the collector with the newer version.

### Running collector without the YAML file

1. Go to the server where you have setup docker to run the collector.

2. Make sure you have download the version of collectors from here.

3. From the command line, run the command generated from the application. Here is a sample command. The following sample command is generated using BigQuery as the target database. Your command will vary based on the target database you select while generating the command.

### Caution

Note that is just a sample command for showing the syntax. You must generate the command specific to your setup from the application UI.

docker run -it --rm --mount type=bind,source=${HOME}/dwcc,target=/dwcc-output \ --mount type=bind,source=${HOME}/dwcc,target=${HOME}/dwcc --mount type=bind,source=${HOME]/artifactDirectory,target=${HOME]/artifactDirectory \ --mount type=bind,source=,target= --mount type=bind,source=creds.json,target=creds.json \ datadotworld/dwcc:2.124 catalog-dbt --base=https://solutions-8bank-catalog-config.app.linked.data.world/d/ddw-catalogs/ \ --site=solutions --no-log-upload=false --upload=true --api-token=${DW_AUTH_TOKEN} \
--artifact-directory=\${HOME]/artifactDirectory --bigquery-credentials-file=creds.json
4. The collector automatically uploads the file to the specified dataset and you can also find the output at the location you specified while running the collector.

5. At a later point, if you download a newer version of collector from docker, you can edit the collector version in the generated command to run the collector with the newer version.

### Collector runtime and troubleshooting

The catalog collector may run in several seconds to many minutes depending on the size and complexity of the system being crawled. If the catalog collector runs without issues, you should see no output on the terminal, but a new file that matching *.dwec.ttl should be in the directory you specified for the output. If there was an issue connecting or running the catalog collector, there will be either a stack trace or a *.log file. Both of those can be sent to support to investigate if the errors are not clear. A list of common issues and problems encountered when running the collectors is available here.