Skip to content

Commit

Permalink
fix(type): revert change from data_type to type in column attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
matanmichaely committed Sep 2, 2024
1 parent 27b658e commit 8e0fa3a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions tests/yoda_dbt2looker/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test__generate_dimensions_column_enabled_not_scalar_type_returns_empty_list(
model.columns = {"col1": column}
column.meta.dimension.enabled = True
data_type = MagicMock()
column.type = data_type
column.data_type = data_type
map_adapter_type_to_looker_mock.return_value = "date"
adapter_type = MagicMock()
assert generator._generate_dimensions(model, adapter_type) == []
Expand All @@ -73,7 +73,7 @@ def test__generate_dimensions_column_enabled_has_sql_returns_dimension(
model.columns = {"col1": column}
column.meta.dimension.enabled = True
data_type = MagicMock()
column.type = data_type
column.data_type = data_type
map_adapter_type_to_looker_mock.return_value = "number"
adapter_type = MagicMock()
column.meta.dimension.name = "col1"
Expand Down Expand Up @@ -106,7 +106,7 @@ def test__generate_dimensions_column_enabled_no_sql_returns_dimension(
model.columns = {"col1": column}
column.meta.dimension.enabled = True
data_type = MagicMock()
column.type = data_type
column.data_type = data_type
map_adapter_type_to_looker_mock.return_value = "number"
adapter_type = MagicMock()
column.meta.dimension.name = None
Expand Down Expand Up @@ -139,7 +139,7 @@ def test__generate_dimensions_column_enabled_is_primary_key_returns_dimension(
model.columns = {"col1": column}
column.meta.dimension.enabled = True
data_type = MagicMock()
column.type = data_type
column.data_type = data_type
map_adapter_type_to_looker_mock.return_value = "number"
adapter_type = MagicMock()
column.meta.dimension.name = None
Expand Down Expand Up @@ -174,7 +174,7 @@ def test__generate_dimensions_column_enabled_is_primary_key_returns_dimension_co
model.columns = {"col1": column}
column.meta.dimension.enabled = True
data_type = MagicMock()
column.type = data_type
column.data_type = data_type
map_adapter_type_to_looker_mock.return_value = "number"
adapter_type = MagicMock()
column.meta.dimension.name = None
Expand Down Expand Up @@ -210,7 +210,7 @@ def test__generate_dimensions_column_enabled_col_has_value_format_name_but_not_n
model.columns = {"col1": column}
column.meta.dimension.enabled = True
data_type = MagicMock()
column.type = data_type
column.data_type = data_type
map_adapter_type_to_looker_mock.return_value = "yesno"
adapter_type = MagicMock()
column.meta.dimension.name = None
Expand Down Expand Up @@ -244,7 +244,7 @@ def test__generate_dimensions_column_enabled_col_has_value_format_name(
model.columns = {"col1": column}
column.meta.dimension.enabled = True
data_type = MagicMock()
column.type = data_type
column.data_type = data_type
map_adapter_type_to_looker_mock.return_value = "number"
adapter_type = MagicMock()
column.meta.dimension.name = None
Expand Down
14 changes: 7 additions & 7 deletions yoda_dbt2looker/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def lookml_date_time_dimension_group(
"type": "time",
"sql": column.meta.dimension.sql or f"${{TABLE}}.{column.name}",
"description": column.meta.dimension.description or column.description,
"datatype": map_adapter_type_to_looker(adapter_type, column.type),
"datatype": map_adapter_type_to_looker(adapter_type, column.data_type),
"timeframes": [
"raw",
"time",
Expand All @@ -244,7 +244,7 @@ def lookml_date_dimension_group(
"type": "time",
"sql": column.meta.dimension.sql or f"${{TABLE}}.{column.name}",
"description": column.meta.dimension.description or column.description,
"datatype": map_adapter_type_to_looker(adapter_type, column.type),
"datatype": map_adapter_type_to_looker(adapter_type, column.data_type),
"timeframes": ["raw", "date", "week", "month", "quarter", "year"],
}

Expand All @@ -255,14 +255,14 @@ def lookml_dimension_groups_from_model(
date_times = [
lookml_date_time_dimension_group(column, adapter_type)
for column in model.columns.values()
if map_adapter_type_to_looker(adapter_type, column.type)
if map_adapter_type_to_looker(adapter_type, column.data_type)
in looker_date_time_types
]
dates = [
lookml_date_dimension_group(column, adapter_type)
for column in model.columns.values()
if column.meta.dimension.enabled
and map_adapter_type_to_looker(adapter_type, column.type)
and map_adapter_type_to_looker(adapter_type, column.data_type)
in looker_date_types
]

Expand All @@ -289,15 +289,15 @@ def _generate_dimensions(model: models.DbtModel, adapter_type):
return [
{
"name": column.meta.dimension.name or column.name,
"type": map_adapter_type_to_looker(adapter_type, column.type),
"type": map_adapter_type_to_looker(adapter_type, column.data_type),
"sql": column.meta.dimension.sql or f"${{TABLE}}.{column.name}",
"description": column.meta.dimension.description or column.description,
**({"primary_key": "yes"} if model.meta.primary_key == column.name else {}),
**(
{"value_format_name": column.meta.dimension.value_format_name.value}
if (
column.meta.dimension.value_format_name
and map_adapter_type_to_looker(adapter_type, column.type)
and map_adapter_type_to_looker(adapter_type, column.data_type)
== "number"
)
else {}
Expand All @@ -308,7 +308,7 @@ def _generate_dimensions(model: models.DbtModel, adapter_type):
}
for column in model.columns.values()
if column.meta.dimension.enabled
and map_adapter_type_to_looker(adapter_type, column.type)
and map_adapter_type_to_looker(adapter_type, column.data_type)
in looker_scalar_types
]

Expand Down
2 changes: 1 addition & 1 deletion yoda_dbt2looker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class DbtModelColumnMeta(Dbt2LookerMeta):
class DbtModelColumn(BaseModel):
name: str
description: str
type: Optional[str]
data_type: Optional[str]
meta: DbtModelColumnMeta


Expand Down
2 changes: 1 addition & 1 deletion yoda_dbt2looker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def parse_exposures(raw_manifest: dict, tag=None) -> List[models.DbtExposure]:

def check_models_for_missing_column_types(dbt_typed_models: List[models.DbtModel]):
for model in dbt_typed_models:
if all([col.type is None for col in model.columns.values()]):
if all([col.data_type is None for col in model.columns.values()]):
logging.debug(
"Model %s has no typed columns, no dimensions will be generated. %s",
model.unique_id,
Expand Down

0 comments on commit 8e0fa3a

Please sign in to comment.