Skip to content
Open
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
5 changes: 2 additions & 3 deletions converters/gooddata/src/ossie_gooddata/ossie_to_gooddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,20 @@ def _convert_ossie_dataset(
pk_columns = set(ds.get("primary_key", []))

for field_def in fields:
field_name = field_def["name"]
is_dimension = field_def.get("dimension") is not None

if is_dimension:
attr = _convert_to_attribute(field_def, ds_name)
attributes.append(attr)
if field_name in pk_columns:
if attr.source_column in pk_columns:
grain_ids.append(attr.id)
else:
# Check MAQL expression to determine if fact or attribute
maql_type = _detect_type_from_maql(field_def)
if maql_type == "attribute":
attr = _convert_to_attribute(field_def, ds_name)
attributes.append(attr)
if field_name in pk_columns:
if attr.source_column in pk_columns:
grain_ids.append(attr.id)
else:
facts.append(_convert_to_fact(field_def, ds_name))
Expand Down
44 changes: 44 additions & 0 deletions converters/gooddata/tests/test_ossie_to_gooddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,50 @@ def test_grain_from_primary_key(ossie_tpcds_dict: dict):
assert len(grain_ids) == 2


@pytest.mark.parametrize(
"field",
[
{
"name": "customer_key",
"expression": {"dialects": [{"dialect": "ANSI_SQL", "expression": "customer_id"}]},
"dimension": {},
},
{
"name": "customer_key",
"expression": {
"dialects": [
{"dialect": "ANSI_SQL", "expression": "customer_id"},
{"dialect": "MAQL", "expression": "{label/customers.customer_key}"},
]
},
},
],
ids=["dimension", "maql-attribute"],
)
def test_grain_uses_source_column_for_aliased_attribute(field: dict):
"""Verify physical primary keys select aliased GoodData grain attributes."""
model = {
"semantic_model": [
{
"name": "m",
"datasets": [
{
"name": "customers",
"source": "db.s.customers",
"primary_key": ["customer_id"],
"fields": [field],
}
],
}
]
}

customer = ossie_to_gooddata(model).ldm.datasets[0]

assert customer.attributes[0].source_column == "customer_id"
assert [grain.id for grain in customer.grain] == ["attr.customers.customer_key"]


def test_relationships_become_references(ossie_tpcds_dict: dict):
"""Verify Ossie relationships become GoodData references."""
result = ossie_to_gooddata(ossie_tpcds_dict)
Expand Down