Skip to content

Commit

Permalink
Move CatalogKey, ColumnMetadata, ColumnMap, CatalogTable to dbt-common (
Browse files Browse the repository at this point in the history
#147)

* Move CatalogKey, ColumnMetadata, ColumnMap, CatalogTable to dbt-common

* Add changie
  • Loading branch information
aranke authored Jun 4, 2024
1 parent ddb28aa commit 99d9727
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240603-123631.yaml
Original file line number Diff line number Diff line change
@@ -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"
35 changes: 34 additions & 1 deletion dbt_common/contracts/metadata.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(),
)

0 comments on commit 99d9727

Please sign in to comment.