Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d0b6879
feat(spec): add source-managed aliases field to Table entity
ulixius9 Aug 19, 2026
4e558d5
fix(ingestion): sort aliases in source hash normalization for stable …
ulixius9 Aug 19, 2026
d309beb
feat(mssql): add sys.synonyms query and synonym result models
ulixius9 Aug 19, 2026
33a1d89
feat(mssql): parse and normalize sys.synonyms base_object_name identi…
ulixius9 Aug 19, 2026
373299f
feat(mssql): add bounded synonym map with consumption tracking
ulixius9 Aug 19, 2026
adf711f
style(ingestion): apply ruff formatting to alias test files
ulixius9 Aug 19, 2026
9b98829
fix(mssql): bound unresolved synonym list and document aliases_for si…
ulixius9 Aug 19, 2026
f7fa06b
feat(ingestion): add get_table_aliases hook to the shared table producer
ulixius9 Aug 19, 2026
d5132ed
fix(ingestion): remove connector-specific vocabulary from get_table_a…
ulixius9 Aug 19, 2026
c03fd86
feat(mssql): discover synonyms up front and attach them as table aliases
ulixius9 Aug 19, 2026
437a84a
test(mssql): cover synonym-sweep routing in _in_scope_database_names/…
ulixius9 Aug 19, 2026
2de39b7
feat(search): index table aliases for exact and partial matching
ulixius9 Aug 19, 2026
9b760d8
fix(service): wire CreateTable.aliases through to the persisted Table…
ulixius9 Aug 19, 2026
75fb66d
fix(service): replace table aliases wholesale on update, don't silent…
ulixius9 Aug 19, 2026
b5d8fe7
test(service): assert table aliases are replaced wholesale across runs
ulixius9 Aug 19, 2026
0b157de
fix(service): use recordListChange for table aliases, not recordChange
ulixius9 Aug 19, 2026
38b98b1
test(service): assert aliases persistence on create, and pin the clea…
ulixius9 Aug 19, 2026
ca33b9a
feat(lineage): resolve alias FQNs to their canonical table
ulixius9 Aug 19, 2026
728f41a
feat(ui): show read-only table aliases on the table detail page
ulixius9 Aug 19, 2026
068871c
test(ui): add Playwright coverage for the table aliases widget
ulixius9 Aug 19, 2026
33397fd
fix(mssql): resolve 3 basedpyright errors from the alias feature
ulixius9 Aug 19, 2026
0ae198a
fix(lineage): stub es_search_from_alias in TestDbUtils to prevent bog…
ulixius9 Aug 19, 2026
e132107
fix(mssql): case-fold SynonymMap's lookup key, not the stored alias FQN
ulixius9 Aug 19, 2026
10f5208
fix(search): wire aliases into the table query and drop the dead boost
ulixius9 Aug 19, 2026
34629b7
fix(migration): backfill the aliases search settings on upgrade
ulixius9 Aug 19, 2026
e1a5067
fix(search): drop ignore_above 256 on aliases.keyword in index mappings
ulixius9 Aug 19, 2026
a1e1bdf
refactor(lineage): remove tautological guard in search_table_entities
ulixius9 Aug 19, 2026
2418c14
docs(ingestion): fix stale source_hash docstrings after aliases sort
ulixius9 Aug 19, 2026
f09033e
feat(ui): show the alias name instead of the full FQN in the Aliases …
ulixius9 Aug 20, 2026
1076ff9
feat(mssql): gate synonym ingestion and alias lineage resolution behi…
ulixius9 Aug 21, 2026
7a777aa
Merge branch 'main' into hangzhou
ulixius9 Sep 1, 2026
b77910a
refactor(migration): move the table aliases search-settings backfill …
ulixius9 Sep 1, 2026
c651cb6
feat(mssql): make includeSynonyms opt-in
ulixius9 Sep 1, 2026
5ee51dd
Update generated TypeScript types and dereferenced schemas
github-actions[bot] Sep 1, 2026
6b3676d
refactor(migration): move the table aliases search-settings backfill …
ulixius9 Sep 2, 2026
2ab34f3
Fix UI checkstyle
ulixius9 Sep 2, 2026
ae9dcec
Merge branch 'main' into hangzhou
ulixius9 Sep 2, 2026
3a534f8
Fix Python checkstyle
ulixius9 Sep 2, 2026
dd02b12
test(ui): add table aliases to the default search settings fixture
ulixius9 Sep 3, 2026
314a7d8
Merge branch 'main' into hangzhou
ulixius9 Sep 3, 2026
d772141
Merge branch 'main' into hangzhou
ulixius9 Sep 3, 2026
4b640ed
Merge branch 'main' into hangzhou
ulixius9 Sep 3, 2026
ff4e8c1
Merge branch 'main' into hangzhou
ulixius9 Sep 7, 2026
ad1702f
Fix UI checkstyle: reduce getWidgetHeight complexity in TableClassBase
ulixius9 Sep 7, 2026
8e424a1
Merge branch 'main' into hangzhou
ShaileshParmar11 Sep 8, 2026
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
60 changes: 60 additions & 0 deletions ingestion/src/metadata/ingestion/lineage/sql_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,38 @@ def get_column_fqn(

search_cache = LRUCache(LRU_CACHE_SIZE)
database_service_type_cache = LRUCache(LRU_CACHE_SIZE)
alias_resolution_cache = LRUCache(LRU_CACHE_SIZE)

# Connection field a connector sets to opt into alias resolution. Read by name
# rather than by service type so any connector exposing alternate names (SQL
# Server synonyms today, Oracle synonyms later) participates without this
# service-agnostic module learning connector names.
ALIAS_OPT_IN_FIELD = "includeSynonyms"


def service_resolves_aliases(metadata: OpenMetadata, service_name: str) -> bool:
"""
Whether this service's connection opts into resolving alternate table names.

Resolving an alias costs an extra exact-match search per unresolved name, so
connectors that cannot produce aliases must not pay for it. Absent field
means no.
"""
if service_name in alias_resolution_cache:
return bool(alias_resolution_cache.get(service_name))

resolves = False
try:
service: DatabaseService | None = metadata.get_by_name(entity=DatabaseService, fqn=service_name)
if service:
resolves = bool(getattr(service.connection.config, ALIAS_OPT_IN_FIELD, False))
except Exception as exc:
logger.debug(traceback.format_exc())
logger.warning("Could not read alias opt-in for service '%s', assuming disabled: %s", service_name, exc)

alias_resolution_cache.put(service_name, resolves)

return resolves


def get_database_service_type(metadata: OpenMetadata, service_name: str) -> str | None:
Expand Down Expand Up @@ -253,6 +285,34 @@ def search_table_entities(
if table_entities:
return table_entities

# An alias name resolves to the canonical table it points at.
# Gated per service so connectors that cannot produce aliases never
# pay for the extra lookup.
if not service_resolves_aliases(metadata, service_name):
continue

alias_fqn = fqn.build(
metadata,
entity_type=Table,
service_name=service_name,
database_name=normalized_db,
schema_name=normalized_schema,
table_name=table,
skip_es_search=True,
)
if alias_fqn:
alias_entities = metadata.es_search_from_alias(
entity_type=Table,
alias_fqn=alias_fqn,
)
if alias_entities:
# LRUCache.put's `key` is typed as `str`, but this cache is keyed by the
# same (service, db, schema, table) tuple as the `search_cache.put` call
# above (line ~251, pre-existing and baselined) -- a real annotation gap,
# not a bug: dict keys accept any hashable value.
search_cache.put(search_tuple, alias_entities) # pyright: ignore[reportArgumentType]
return alias_entities

except Exception as exc:
logger.debug(traceback.format_exc())
logger.error(f"Error searching for table entities for service [{service_name}]: {exc}")
Expand Down
23 changes: 23 additions & 0 deletions ingestion/src/metadata/ingestion/ometa/mixins/es_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,29 @@ def es_search_from_fqn(
fields=fields,
)

def es_search_from_alias(
self,
entity_type: type[T],
alias_fqn: str,
from_count: int = 0,
size: int = 10,
fields: str | None = None,
) -> list[T] | None:
"""
Find entities carrying an exact alternate FQN in their aliases field.

Matches on the keyword subfield only: an alias is resolved for lineage,
where a fuzzy hit would silently attach an edge to the wrong table.
"""
return self._es_search_entity(
entity_type=entity_type,
field_value=alias_fqn,
field_name="aliases.keyword",
from_count=from_count,
size=size,
fields=fields,
)

def es_search_container_by_path(
self,
full_path: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,19 @@ def get_table_extensions(
Method to fetch the extensions of the table
"""

def get_table_aliases(
self,
table_name: str, # pyright: ignore[reportUnusedParameter]
schema_name: str, # pyright: ignore[reportUnusedParameter]
) -> list[str] | None:
"""
Alternate fully qualified SQL names that resolve to this table.

Connectors that expose database-native alternate names for a table
override this. The list is source-managed: it is recomputed from the
source on every run and replaces whatever is stored.
"""

def yield_table(self, table_name_and_type: tuple[str, TableType]) -> Iterable[Either[CreateTableRequest]]:
"""
From topology.
Expand Down Expand Up @@ -579,6 +592,8 @@ def yield_table(self, table_name_and_type: tuple[str, TableType]) -> Iterable[Ei
else None
)

table_aliases = self.get_table_aliases(table_name=table_name, schema_name=schema_name)

table_request = CreateTableRequest(
name=EntityName(table_name),
tableType=table_type,
Expand All @@ -605,6 +620,7 @@ def yield_table(self, table_name_and_type: tuple[str, TableType]) -> Iterable[Ei
owners=self.get_owner_ref(table_name=table_name),
locationPath=self.get_location_path(table_name=table_name, schema_name=schema_name),
extension=self.get_table_extensions(table_name=table_name, table_type=table_type),
aliases=([FullyQualifiedEntityName(alias) for alias in table_aliases] if table_aliases else None),
)

is_partitioned, partition_details = self.get_table_partition_details(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from metadata.generated.schema.entity.data.database import Database
from metadata.generated.schema.entity.data.databaseSchema import DatabaseSchema
from metadata.generated.schema.entity.data.storedProcedure import StoredProcedureCode
from metadata.generated.schema.entity.data.table import Table
from metadata.generated.schema.entity.services.connections.database.mssqlConnection import (
MssqlConnection,
)
Expand All @@ -49,6 +50,10 @@
MSSQL_GET_STORED_PROCEDURE_COMMENTS,
MSSQL_GET_STORED_PROCEDURES,
)
from metadata.ingestion.source.database.mssql.synonyms import (
SynonymMap,
build_synonym_map,
)
from metadata.ingestion.source.database.mssql.utils import (
get_columns,
get_foreign_keys,
Expand Down Expand Up @@ -110,6 +115,7 @@ def __init__(
self.database_desc_map = {}
self.stored_procedure_desc_map = {}
self.encrypted_procedures_cache: dict[tuple[str, str], set[str]] = {}
self.synonym_map = SynonymMap()

@classmethod
def create(cls, config_dict, metadata: OpenMetadata, pipeline_name: str | None = None):
Expand Down Expand Up @@ -249,6 +255,76 @@ def get_database_names(self) -> Iterable[str]:
)
)

def _in_scope_database_names(self) -> list[str]:
"""
In-scope databases for the synonym sweep, resolved without touching the
topology. prepare() runs before get_database_names(), so the filter has
to be reapplied here rather than reused from it.
"""
if not self.service_connection.ingestAllDatabases:
return [self.service_connection.database]

database_names = []
for database_name in self.get_database_names_raw():
database_fqn = fqn.build(
self.metadata,
entity_type=Database,
service_name=self.config.serviceName,
database_name=database_name,
)
if filter_by_database(
self.source_config.databaseFilterPattern,
(database_fqn if self.source_config.useFqnForFiltering else database_name), # pyright: ignore[reportArgumentType]
):
continue
database_names.append(database_name)
return database_names

def _build_table_fqn(self, database_name: str, schema_name: str, table_name: str) -> str:
return fqn.build( # pyright: ignore[reportReturnType]
self.metadata,
entity_type=Table,
service_name=self.config.serviceName,
database_name=database_name,
schema_name=schema_name,
table_name=table_name,
skip_es_search=True,
)

def prepare(self):
"""
Sweep synonyms before the topology runs.

Synonym discovery is optional metadata: a failure here must not abort the
run, so it is logged and ingestion continues with an empty map.
"""
super().prepare()
if not self.service_connection.includeSynonyms:
logger.info("includeSynonyms is disabled; skipping MSSQL synonym discovery")

return
try:
self.synonym_map = build_synonym_map(
engine=self.engine,
database_names=self._in_scope_database_names(),
fqn_builder=self._build_table_fqn,
)
except Exception as exc:
logger.debug(traceback.format_exc())
logger.warning("Could not discover MSSQL synonyms, continuing without aliases: %s", exc)

def get_table_aliases(self, table_name: str, schema_name: str) -> list[str] | None:
"""Aliases from sys.synonyms whose target is the table being produced"""
if self.synonym_map.is_empty():
return None
return self.synonym_map.aliases_for(
self._build_table_fqn(
self.context.get().database, # pyright: ignore[reportAttributeAccessIssue]
schema_name,
table_name,
)
)

def get_stored_procedures(self) -> Iterable[MssqlStoredProcedure]:
"""List Snowflake stored procedures"""
if self.source_config.includeStoredProcedures:
Expand Down Expand Up @@ -318,3 +394,9 @@ def yield_stored_procedure(
stackTrace=traceback.format_exc(),
)
)

def close(self):
"""Report synonyms that never resolved to an ingested table"""
for alias_fqn, reason in self.synonym_map.unresolved():
self.status.warning(alias_fqn, f"Synonym target unresolved: {reason}")
super().close()
Comment on lines +398 to +402
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# limitations under the License.
"""MSSQL models"""

from enum import IntEnum
from enum import Enum, IntEnum

from pydantic import BaseModel, Field

Expand Down Expand Up @@ -38,3 +38,27 @@ class MssqlStoredProcedure(BaseModel):
owner: str | None = Field(None)
language: str = Field(Language.SQL)
definition: str | None = Field(None)


class SynonymUnresolvedReason(str, Enum):
"""Why a discovered synonym could not be attached to a canonical table"""

UNRESOLVED = "Unresolved"
UNSUPPORTED_TARGET_TYPE = "UnsupportedTargetType"
REMOTE_TARGET_UNMAPPED = "RemoteTargetUnmapped"


class MssqlSynonym(BaseModel):
"""A row from sys.synonyms joined to sys.schemas"""

synonym_schema: str = Field(...)
synonym_name: str = Field(...)
base_object_name: str = Field(...)


class MssqlSynonymTarget(BaseModel):
"""The parsed three-part target a synonym resolves to"""

database: str = Field(...)
schema_name: str = Field(...)
table: str = Field(...)
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,15 @@
)

GET_DB_CONFIGS = textwrap.dedent("DBCC USEROPTIONS;")

MSSQL_GET_SYNONYMS = textwrap.dedent(
"""
SELECT
sch.name AS synonym_schema,
syn.name AS synonym_name,
syn.base_object_name AS base_object_name
FROM [{database_name}].sys.synonyms syn
JOIN [{database_name}].sys.schemas sch
ON syn.schema_id = sch.schema_id
"""
)
Loading
Loading