Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# BigQuery daily shard families use stable logical tables with recorded execution sources

- **Status:** Accepted
- **Revisions:** v1 2026-11-03 (initial) · v2 2026-11-04 (a missed scoped name takes its one case variant)
- **Revisions:** v1 2026-11-03 (initial) · v2 2026-11-04 (a missed scoped name takes its one case variant) · v3 2026-11-25 (a dbt wildcard source feeds lineage from every table it reads)
- **Deciders:** OpenMetadata maintainers
- **Guard:** `test_bigquery_sharding.py`, `test_resolver.py`, `TableShardingIT`, `TableSharding.spec.ts`
- **Related:** #36867, #37077; ADR:2026-11-03-source-lifecycle-merges-earliest-creation-and-latest-activity
Expand Down Expand Up @@ -90,3 +90,23 @@ table that matches it case-insensitively, and none when several do (`Account` an
exist). The family is tried first, as a shard name misses its exact name by design. Guard:
`test_resolver.py::test_bigquery_lowercased_reference_resolves_to_its_one_case_variant`,
`test_resolver.py::test_bigquery_reference_matching_two_case_variants_resolves_to_none`.

## Amendment: a dbt wildcard source feeds lineage from every table it reads (v3, 2026-11-25)

A dbt source whose identifier ends in `*` (GA4's `events_*`) is a BigQuery wildcard table, and
BigQuery reads every table its prefix matches: the `events_` family, `events_intraday_`, and any
ordinary `events_…` table. When the configured service's resolver declares
`supports_wildcard_tables` (only BigQuery does), a model's data model keeps the wildcard FQN as an
upstream instead of looking it up as one table, and dbt lineage expands it into one edge per match.
The expansion searches where every other dbt node is looked up: the `catalogMapping` database in the
configured service and then in any service (ADR:2026-10-14-dbt-catalog-mapping-resolves-engine-database-names),
then the manifest database, in any service too when `searchAcrossDatabases` is set. An unmatched
wildcard gets no edge, is reported, and still lets the model override; it is never looked up as a
single table. An incomplete match (over the
100-candidate limit, date-constrained, or tables in more than one service) is reported, and both of
that model's lineage stages (dbt dependencies and SQL) add their edges without overriding, so the
wildcard's earlier edges survive and new parents still link. Each wildcard is expanded once per run. A test or
an exposure attaches to one table, so it never expands a wildcard; other engines keep the
identifier literal. Guard: the `test_dbt_wildcard_source_*` and
`test_dbt_incomplete_wildcard_source_*` tests in `test_resolver.py`, and
`test_dbt.py::TestDbtSourceIdentifiers` (literal identifiers elsewhere, and the data-model wiring).
3 changes: 3 additions & 0 deletions ingestion/src/metadata/entity_resolution/table_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class TableLookup(Enum):
class TableBindingResolution:
"""Resolve references using the standard catalog namespace."""

# Whether a table name ending in `*` names every table it matches, as BigQuery's does
supports_wildcard_tables = False

def __init__(self, metadata: OpenMetadata, engine: EntityResolver | None = None):
self.metadata = metadata
self.engine = engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def _resolve_shard_family(resolver, service: str, reference: TableReference, fie


class BigQueryTableBindingResolution(DefaultTableBindingResolution):
supports_wildcard_tables = True

def resolve(
self,
reference: TableReference,
Expand Down
158 changes: 135 additions & 23 deletions ingestion/src/metadata/ingestion/source/database/dbt/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
from metadata.utils.entity_link import get_table_fqn
from metadata.utils.filters import filter_by_tag
from metadata.utils.logger import ingestion_logger
from metadata.utils.lru_cache import LRU_CACHE_SIZE, LRUCache
from metadata.utils.tag_utils import get_ometa_tag_and_classification, get_tag_labels
from metadata.utils.time_utils import datetime_to_timestamp

Expand Down Expand Up @@ -889,6 +890,7 @@ def yield_data_models(self, dbt_objects: DbtObjects) -> Iterable[Either[DataMode
Yield the data models
"""
self.reported_unresolved_upstreams.clear()
self.wildcard_expansions.clear()
if self.source_config.dbtConfigSource and dbt_objects.dbt_manifest:
logger.debug("Parsing DBT Data Models")
manifest_entities = {
Expand Down Expand Up @@ -1025,7 +1027,9 @@ def yield_data_models(self, dbt_objects: DbtObjects) -> Iterable[Either[DataMode
if manifest_node.meta:
dbt_table_tags_list.extend(self.process_dbt_meta(manifest_node.meta, table_fqn) or [])

upstream_nodes = self.parse_upstream_nodes_with_names(manifest_entities, manifest_node)
upstream_nodes = self.parse_upstream_nodes_with_names(
manifest_entities, manifest_node, expand_wildcard_sources=True
)
data_model_link = DataModelLink(
table_entity=table_entity,
upstream_table_ids={node.fqn: node.table_id for node in upstream_nodes if node.table_id},
Expand Down Expand Up @@ -1087,12 +1091,16 @@ def parse_upstream_nodes(self, manifest_entities, dbt_node):
"""
return [node.fqn for node in self.parse_upstream_nodes_with_names(manifest_entities, dbt_node)]

def parse_upstream_nodes_with_names(self, manifest_entities, dbt_node):
def parse_upstream_nodes_with_names(self, manifest_entities, dbt_node, *, expand_wildcard_sources: bool = False):
"""
Method to fetch the upstream nodes as UpstreamNode entries.

The dbt names are kept alongside the FQN because the FQN is built from the model
alias, while dbt ``ref()`` expressions carry the model name.

``expand_wildcard_sources`` keeps a wildcard source (BigQuery ``events_*``) as an upstream,
so lineage reaches every table it reads; tests and exposures attach to one table and
leave it out.
"""
upstream_nodes = []
if (
Expand Down Expand Up @@ -1133,7 +1141,31 @@ def parse_upstream_nodes_with_names(self, manifest_entities, dbt_node):
# check if the node is an ephemeral node
# Recursively store the upstream of the ephemeral node in the upstream list
if check_ephemeral_node(parent_node):
upstream_nodes.extend(self.parse_upstream_nodes_with_names(manifest_entities, parent_node))
upstream_nodes.extend(
self.parse_upstream_nodes_with_names(
manifest_entities, parent_node, expand_wildcard_sources=expand_wildcard_sources
)
)
elif (
expand_wildcard_sources
and parent_resource_type == DbtCommonEnum.SOURCE.value
and table_name.endswith("*")
and get_table_binding_resolution(
self.metadata, self.config.serviceName
).supports_wildcard_tables
and (
wildcard_fqn := self._build_table_fqn(
get_corrected_name(parent_database),
get_corrected_name(parent_schema),
table_name,
literal_table_name=True,
)
)
):
# A wildcard table reads every table it matches, and no table is named with a `*`;
# create_dbt_lineage expands it into one edge per match.
# ADR:2026-11-03-bigquery-daily-shards-use-stable-logical-tables
upstream_nodes.append(build_upstream_node(parent_node, wildcard_fqn))
else:
parent_fqn = self._build_table_fqn(
database_name=get_corrected_name(parent_database),
Expand Down Expand Up @@ -1307,44 +1339,123 @@ def parse_exposure_node(self, exposure_spec) -> Optional[Any]: # noqa: UP045

return entity

def create_dbt_lineage(self, data_model_link: DataModelLink) -> Iterable[Either[AddLineageRequest]]:
@cached_property
def wildcard_expansions(self) -> LRUCache[tuple[Table, ...] | None]:
"""A run's wildcard expansions, shared by the lineage stages of every model reading them."""
return LRUCache(LRU_CACHE_SIZE)

@staticmethod
def _wildcard_upstreams(data_model_link: DataModelLink) -> list[str]:
"""
Method to process DBT lineage from upstream nodes
Upstreams kept as a wildcard to expand. A source whose identifier really contains a `*` on an
engine without wildcard tables resolved to its table, so it carries an id and is not one.
"""
to_entity: Table = data_model_link.table_entity
logger.debug(f"Processing DBT lineage for: {to_entity.fullyQualifiedName.root}")
return [
upstream
for upstream in data_model_link.datamodel.upstream or []
if upstream not in data_model_link.upstream_table_ids
and len(parts := fqn.split(upstream)) == 4
and "*" in parts[3]
]

wildcard_targets = {}
def _overrides_lineage(self, data_model_link: DataModelLink) -> bool:
"""
Whether this run may replace a model's dbt lineage. Not while a wildcard upstream's match is
incomplete: replacing would delete the edges it could not confirm, so the run only adds edges.
"""
return bool(self.source_config.overrideLineage) and all(
self._wildcard_upstream_tables(upstream) is not None
for upstream in self._wildcard_upstreams(data_model_link)
)

def _wildcard_upstream_tables(self, upstream: str) -> tuple[Table, ...] | None:
"""Every table a wildcard upstream reads, or None when the match is incomplete; once per run."""
try:
for upstream in data_model_link.datamodel.upstream or []:
parts = fqn.split(upstream)
if len(parts) == 4 and "*" in parts[3]:
matches = get_table_binding_resolution(self.metadata, parts[0]).resolve(
TableReference(parts[1], parts[2], parts[3]), service_name=parts[0], lookup=TableLookup.SEARCH
)
if matches:
wildcard_targets[upstream] = matches
return self.wildcard_expansions.get(upstream)
except KeyError:
pass
tables: tuple[Table, ...] | None
try:
tables = self._resolve_wildcard_upstream(fqn.split(upstream))
if not tables:
self.status.warning(
upstream,
f"dbt lineage edge dropped: no table in OpenMetadata matches the wildcard source '{upstream}'",
)
except Exception as exc:
logger.debug(traceback.format_exc())
tables = None
self.status.warning(
model_str(to_entity.fullyQualifiedName), f"dbt lineage incomplete; preserving prior lineage: {exc}"
upstream, f"dbt lineage incomplete for wildcard source '{upstream}'; preserving prior lineage: {exc}"
)
return
self.wildcard_expansions.put(upstream, tables)
return tables

def _resolve_wildcard_upstream(self, parts: list[str]) -> tuple[Table, ...]:
"""
Every table a wildcard upstream reads, looked up in the order every other dbt node uses: the
catalogMapping database in the configured service, then in any service
(ADR:2026-10-14-dbt-catalog-mapping-resolves-engine-database-names), then the manifest
database, in any service too when searchAcrossDatabases is set.
"""
service_name, database, schema, table_name = parts
database = None if database == "*" else database
mapped_database = self.catalog_mapping.get(database.casefold()) if database else None
lookups: list[tuple[str, str | None]] = (
[(service_name, mapped_database), ("*", mapped_database)] if mapped_database else []
)
lookups.append((service_name, database))
if self.source_config.searchAcrossDatabases:
lookups.append(("*", database))
resolution = get_table_binding_resolution(self.metadata, service_name)
matches: tuple[Table, ...] = ()
for lookup_service, lookup_database in lookups:
matches = resolution.resolve(
TableReference(lookup_database, schema, table_name),
service_name=lookup_service,
lookup=TableLookup.SEARCH,
)
services = sorted({fqn.split(model_str(table.fullyQualifiedName))[0] for table in matches})
if len(services) > 1:
raise ValueError(f"its tables are ingested under several services {services}")
if matches:
break
return matches

def create_dbt_lineage(self, data_model_link: DataModelLink) -> Iterable[Either[AddLineageRequest]]:
"""
Method to process DBT lineage from upstream nodes
"""
to_entity: Table = data_model_link.table_entity
logger.debug(f"Processing DBT lineage for: {to_entity.fullyQualifiedName.root}")

# A wildcard upstream links only the tables its expansion finds; any other lookup would take
# whichever single table the pattern hits first
wildcard_targets = {
upstream: self._wildcard_upstream_tables(upstream) for upstream in self._wildcard_upstreams(data_model_link)
}
override_lineage = self._overrides_lineage(data_model_link)

resolved = data_model_link.upstream_table_ids
for upstream_node in data_model_link.datamodel.upstream or []:
try:
if upstream_node in wildcard_targets:
for upstream_table in wildcard_targets[upstream_node]:
for upstream_table in wildcard_targets[upstream_node] or ():
yield Either(
right=OMetaLineageRequest(
lineage_request=AddLineageRequest(
edge=EntitiesEdge(
fromEntity=EntityReference(id=upstream_table.id, type="table"),
toEntity=EntityReference(id=to_entity.id, type="table"),
lineageDetails=LineageDetails(source=LineageSource.DbtLineage),
lineageDetails=LineageDetails(
source=LineageSource.DbtLineage,
sqlQuery=SqlQuery(data_model_link.datamodel.sql.root)
if data_model_link.datamodel.sql
else None,
),
)
),
override_lineage=self.source_config.overrideLineage,
override_lineage=override_lineage,
)
)
continue
Expand Down Expand Up @@ -1374,7 +1485,7 @@ def create_dbt_lineage(self, data_model_link: DataModelLink) -> Iterable[Either[
yield Either(
right=OMetaLineageRequest(
lineage_request=lineage_request,
override_lineage=self.source_config.overrideLineage,
override_lineage=override_lineage,
)
)
elif upstream_node not in self.reported_unresolved_upstreams:
Expand Down Expand Up @@ -1421,12 +1532,13 @@ def create_dbt_query_lineage(self, data_model_link: DataModelLink) -> Iterable[E
timeout_seconds=self.source_config.parsingTimeoutLimit,
lineage_source=LineageSource.DbtLineage,
)
override_lineage = self._overrides_lineage(data_model_link)
for lineage in lineages or []:
if lineage.right is not None:
yield Either(
right=OMetaLineageRequest(
lineage_request=lineage.right,
override_lineage=self.source_config.overrideLineage,
override_lineage=override_lineage,
)
)
else:
Expand Down
Loading
Loading