diff --git a/.changes/unreleased/Under the Hood-20240603-123631.yaml b/.changes/unreleased/Under the Hood-20240603-123631.yaml new file mode 100644 index 00000000..18a649df --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240603-123631.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Move CatalogKey, ColumnMetadata, ColumnMap, CatalogTable to dbt-common +time: 2024-06-03T12:36:31.542118+02:00 +custom: + Author: aranke + Issue: "147" diff --git a/dbt_common/contracts/metadata.py b/dbt_common/contracts/metadata.py index bc738796..d71e79a7 100644 --- a/dbt_common/contracts/metadata.py +++ b/dbt_common/contracts/metadata.py @@ -1,7 +1,8 @@ from dataclasses import dataclass -from typing import Dict, Optional, Union +from typing import Dict, Optional, Union, NamedTuple from dbt_common.dataclass_schema import dbtClassMixin +from dbt_common.utils.formatting import lowercase @dataclass @@ -24,3 +25,35 @@ class TableMetadata(dbtClassMixin): database: Optional[str] = None comment: Optional[str] = None owner: Optional[str] = None + + +CatalogKey = NamedTuple( + "CatalogKey", [("database", Optional[str]), ("schema", str), ("name", str)] +) + + +@dataclass +class ColumnMetadata(dbtClassMixin): + type: str + index: int + name: str + comment: Optional[str] = None + + +ColumnMap = Dict[str, ColumnMetadata] + + +@dataclass +class CatalogTable(dbtClassMixin): + metadata: TableMetadata + columns: ColumnMap + stats: StatsDict + # the same table with two unique IDs will just be listed two times + unique_id: Optional[str] = None + + def key(self) -> CatalogKey: + return CatalogKey( + lowercase(self.metadata.database), + self.metadata.schema.lower(), + self.metadata.name.lower(), + )