Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move CatalogKey, ColumnMetadata, ColumnMap, CatalogTable to dbt-common #147

Merged
merged 2 commits into from
Jun 4, 2024
Merged
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
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(),
)
Loading