Area: Ingestion Issues
Sub-Area: dbt / Data Warehouse Container Deduplication
Applies to: OSS + Cloud
Issue
You ingest dbt together with a warehouse source such as BigQuery, Redshift or Snowflake. In the warehouse's browse tree you now see two folders with the same name for one project, database or schema. One folder holds the tables the warehouse connector ingested. The other, smaller folder holds a few tables that dbt knows about. You delete those entities, and after the next run they come back.
You Might Be Asking
- Why do I see two folders for the same BigQuery project or Redshift database?
- Why do the extra tables come back after I delete them?
- Does the dbt connector create its own containers?
- Will stateful ingestion or a hard delete clean them up for good?
Cause
The dbt connector does not create containers. For every dbt source, model, seed and snapshot that exists in the warehouse (everything except ephemeral models, tests and semantic models), dbt writes metadata to the warehouse table's URN. dbt writes a sibling link to the dbt entity. For models, seeds and snapshots, dbt also writes lineage. This is how dbt and warehouse entities are combined in the UI.
When the warehouse connector ingests a table with the same URN, that table gets its container and browse path from the warehouse connector, and it shows up in the right folder. When no warehouse entity has that URN, the entity has no container. DataHub then builds a browse path from the dataset name (for example my-project > my_dataset). Those plain name entries form a second folder next to the real container folder, even though the names match.
This happens when the warehouse connector never ingests the table, or when dbt builds a different URN for it. dbt's URN for a warehouse table is made from target_platform, target_platform_instance, env and the database, schema and table names. It is lowercased unless you set convert_urns_to_lowercase: false. The dbt source reference describes each of these keys. The URN does not match the warehouse connector's when:
- The warehouse recipe does not cover the table. For example, its allow/deny patterns skip the schema where dbt sources are loaded, or the table was dropped.
- Case differs. dbt lowercases URNs by default (
convert_urns_to_lowercase: true). The BigQuery source keeps the original case by default (convert_urns_to_lowercase: false). A BigQuery dataset or table with capital letters then gets two URNs. - Platform instance differs.
target_platform_instancein the dbt recipe must equalplatform_instancein the warehouse recipe. BigQuery is a special case: the BigQuery source does not supportplatform_instance, and BigQuery dataset URNs never include one, so leavetarget_platform_instanceunset for BigQuery. -
envdiffers between the dbt recipe and the warehouse recipe.
Deleting the entities does not fix this. The next dbt run writes to the same URNs again and recreates them. Stateful ingestion does not remove them either. dbt writes these warehouse entities as non-primary work units, which stale entity removal skips, and the warehouse recipe never emitted them.
Solution
- Find out which tables are in the extra folder.
Open a few entities in the extra folder and compare each URN with the URN of the same table in the real folder. If you find no real counterpart, the warehouse recipe does not ingest that table. If the URNs differ only in case, platform instance or env, you have a URN mismatch.
- Make dbt's warehouse URNs match the warehouse recipe.
Set the same values in the dbt recipe that the warehouse recipe uses. See the dbt source reference for each key.
For BigQuery, where the BigQuery recipe keeps the original case:
source:
type: dbt
config:
# ... your existing dbt config ...
target_platform: bigquery
convert_urns_to_lowercase: false # match the BigQuery recipe
env: PROD # same env as the BigQuery recipe
# do not set target_platform_instance for BigQuery
For Redshift, Snowflake and other warehouses that you ingest with a platform_instance:
source:
type: dbt
config:
# ... your existing dbt config ...
target_platform: redshift
target_platform_instance: my-redshift # same value as platform_instance in the Redshift recipe
env: PROD # same env as the Redshift recipe
Keep these values fixed once you pick them. Changing them changes the URNs again.
- Ingest the tables dbt references.
Widen the warehouse recipe's patterns so it covers the schemas dbt reads from and builds into. Once the warehouse connector ingests a table with the same URN, it writes the container and browse path, and the entity moves into the real folder. You don't need to delete anything for these tables.
- Stop dbt from emitting sources you don't ingest.
If the extra entities are dbt sources (raw tables loaded by another tool) that you don't want to ingest from the warehouse, turn off dbt sources. In the same recipe, add skip_sources_in_lineage: true:
source:
type: dbt
config:
# ... your existing dbt config ...
entities_enabled:
sources: "NO"
skip_sources_in_lineage: true
Without skip_sources_in_lineage: true, model lineage keeps pointing at the dbt source URNs that dbt no longer ingests.
With these settings, dbt emits no source entities at all. You lose both the dbt source entities and their warehouse siblings, so dbt source metadata (such as descriptions) no longer reaches DataHub. The settings do not change what dbt emits for models, seeds or snapshots.
- Check the
target_platform_instancebehavior (warehouses with a platform instance only).
This step does not apply to BigQuery, because BigQuery URNs have no platform instance. When you set target_platform_instance, dbt also places warehouse entities that the warehouse connector did not ingest. dbt gives each one the container of an ingested table in the same database and schema. dbt also writes a matching browse path. This is on by default (emit_target_platform_instance_aspects: true). dbt still creates no containers. If the warehouse connector ingested nothing from a schema, the entities in that schema stay directly under the platform instance. The dbt run needs a connection to DataHub to read the existing warehouse containers. The dbt source reference describes this key.
- Delete the leftover entities.
After steps 2 to 5, the entities at the old URNs stay in the extra folder until you delete them. Stateful ingestion will not remove them. Put their URNs in a file (one per line), preview with a dry run, then delete. See Removing Metadata from DataHub.
# Preview: prints the entities and deletes nothing
datahub delete --urn-file ghost_urns.txt --hard --dry-run
# Delete
datahub delete --urn-file ghost_urns.txt --hard
A hard delete removes all rows for the entity and cannot be undone. The CLI asks you to confirm it. If any recipe still emits one of these URNs, the next run recreates that entity, so finish the recipe changes first. The extra folder disappears once no entity is left in it.
Additional Notes
For BigQuery, keep include_data_platform_instance at its default of false. The BigQuery source reference says that turning it on causes redundancy in BigQuery browse paths, because the project ID is already the top-level container.
Anything else that writes lineage for warehouse tables, such as another recipe or a custom emitter, must use the same platform, platform instance, env and case as the warehouse recipe. Otherwise it creates entities in an extra folder the same way.