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

support dbx adapter #50

Merged
merged 2 commits into from
Oct 7, 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
40 changes: 39 additions & 1 deletion tests/yoda_dbt2looker/core/test_core_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ def test_lookml_dimension_groups_from_model(self, mock_map_adapter_type_to_looke
mock_column_2.data_type = "date"
mock_dbt_model.columns = {"col1": mock_column_1, "col2": mock_column_2}

mock_map_adapter_type_to_looker.side_effect = ["timestamp", "timestamp", "datetime", "datetime"]
mock_map_adapter_type_to_looker.side_effect = [
"timestamp",
"timestamp",
"datetime",
"datetime",
"timestamp",
"timestamp",
"datetime",
"datetime",
]
mock_lookml_date_time_dimension_group.return_value = "datetime_group"

result = generator.lookml_dimension_groups_from_model(mock_dbt_model, SupportedDbtAdapters.spark.value)
Expand All @@ -89,6 +98,18 @@ def test_lookml_dimension_groups_from_model(self, mock_map_adapter_type_to_looke
mock_lookml_date_time_dimension_group.assert_has_calls(
[call(mock_column_1, SupportedDbtAdapters.spark), call(mock_column_2, SupportedDbtAdapters.spark)])

result = generator.lookml_dimension_groups_from_model(
mock_dbt_model, SupportedDbtAdapters.databricks.value
)

assert result == ["datetime_group", "datetime_group"]
mock_lookml_date_time_dimension_group.assert_has_calls(
[
call(mock_column_1, SupportedDbtAdapters.databricks),
call(mock_column_2, SupportedDbtAdapters.databricks),
]
)

@patch('yoda_dbt2looker.core.generator.map_adapter_type_to_looker')
def test_lookml_dimensions_from_model(self, mock_map_adapter_type_to_looker):
mock_dbt_model = MagicMock(spec=DbtModel)
Expand Down Expand Up @@ -118,3 +139,20 @@ def test_lookml_dimensions_from_model(self, mock_map_adapter_type_to_looker):
assert result == [expected_dimension]
mock_map_adapter_type_to_looker.assert_has_calls([call(SupportedDbtAdapters.spark, "integer")
, call(SupportedDbtAdapters.spark, "integer")])
result = generator.lookml_dimensions_from_model(
mock_dbt_model, SupportedDbtAdapters.databricks
)

expected_dimension = {
"name": "test_column",
"type": "number",
"sql": "${TABLE}.test_column",
"description": "test column",
}
assert result == [expected_dimension]
mock_map_adapter_type_to_looker.assert_has_calls(
[
call(SupportedDbtAdapters.databricks, "integer"),
call(SupportedDbtAdapters.databricks, "integer"),
]
)
22 changes: 21 additions & 1 deletion yoda_dbt2looker/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@
"timestamp": "timestamp",
"date": "datetime",
},
"databricks": {
"byte": "number",
"short": "number",
"integer": "number",
"int": "number",
"bigint": "number",
"smallint": "number",
"long": "number",
"float": "number",
"double": "number",
"decimal": "number",
"string": "string",
"varchar": "string",
"char": "string",
"boolean": "yesno",
"timestamp": "timestamp",
"date": "datetime",
},
}

looker_date_time_types = ["datetime", "timestamp"]
Expand Down Expand Up @@ -203,7 +221,9 @@ def map_adapter_type_to_looker(
return None
normalised_column_type = (
normalise_spark_types(column_type)
if adapter_type == models.SupportedDbtAdapters.spark.value
if adapter_type in
[models.SupportedDbtAdapters.spark.value,
models.SupportedDbtAdapters.databricks.value]
else column_type
)
looker_type = LOOKER_DTYPE_MAP[adapter_type].get(normalised_column_type)
Expand Down
1 change: 1 addition & 0 deletions yoda_dbt2looker/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SupportedDbtAdapters(str, Enum):
redshift = "redshift"
snowflake = "snowflake"
spark = "spark"
databricks = "databricks"


# Lookml types
Expand Down
Loading