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

TRIVIAL: gooddata-dbt - allow to override LDM ID #376

Merged
1 commit merged into from
Oct 5, 2023
Merged
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
15 changes: 11 additions & 4 deletions gooddata-dbt/gooddata_dbt/dbt/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DbtModelMetaGoodDataTableProps(Base):

@attrs.define(auto_attribs=True, kw_only=True)
class DbtModelMetaGoodDataColumnProps(Base):
id: Optional[str] = None
ldm_type: Optional[str] = None
referenced_table: Optional[str] = None
label_type: Optional[str] = None
Expand Down Expand Up @@ -115,6 +116,12 @@ class DbtModelColumn(DbtModelBase):
data_type: Optional[str]
meta: DbtModelMetaGoodDataColumn = attrs.field(factory=DbtModelMetaGoodDataColumn)

# Enable to override LDM ID for LDM entities derived from columns (attributes, ...)
# TODO - does it work for PK/references in combination with roles?
@property
def ldm_id(self) -> str:
return self.meta.gooddata.id or self.gooddata_ldm_id

def gooddata_is_fact(self) -> bool:
return (self.meta.gooddata.ldm_type == GoodDataLdmTypes.FACT.value) or self.is_number()

Expand Down Expand Up @@ -355,7 +362,7 @@ def make_facts(table: DbtModelTable) -> List[Dict]:
if column.gooddata_is_fact():
facts.append(
{
"id": column.gooddata_ldm_id,
"id": column.ldm_id,
# TODO - all titles filled from dbt descriptions, incorrect! No title in dbt models.
"title": column.gooddata_ldm_title,
"description": column.gooddata_ldm_description,
Expand All @@ -372,7 +379,7 @@ def make_labels(table: DbtModelTable, attribute_column: DbtModelColumn) -> List[
if column.gooddata_is_label(attribute_column.name):
labels.append(
{
"id": column.gooddata_ldm_id,
"id": column.ldm_id,
"title": column.gooddata_ldm_title,
"description": column.gooddata_ldm_description,
"source_column": column.name,
Expand All @@ -389,7 +396,7 @@ def make_attributes(self, table: DbtModelTable) -> List[Dict]:
if column.gooddata_is_attribute():
attributes.append(
{
"id": column.gooddata_ldm_id,
"id": column.ldm_id,
"title": column.gooddata_ldm_title,
"description": column.gooddata_ldm_description,
"source_column": column.name,
Expand All @@ -410,7 +417,7 @@ def make_date_datasets(self, table: DbtModelTable, existing_date_datasets: List[
granularities = DATE_GRANULARITIES
date_datasets.append(
{
"id": column.gooddata_ldm_id,
"id": column.ldm_id,
"title": self.get_ldm_title(column),
"description": column.description,
"tags": [table.gooddata_ldm_title] + column.tags,
Expand Down