Skip to content

Commit 8f557ed

Browse files
chaimtowlas
andauthored
add spark types (#27)
* add spark types * use dbt relation name Co-authored-by: oliverlaslett <[email protected]>
1 parent 831c23b commit 8f557ed

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
Recent and upcoming changes to dbt2looker
44

55
## 0.8.3
6+
### Added
7+
- Support for spark adapter (@chaimt)
8+
69
### Changed
710
- Updated with support for dbt2looker (@chaimt)
11+
- Lookml views now populate their "sql_table_name" using the dbt relation name
812

913
## 0.8.2
1014
### Changed

dbt2looker/generator.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import re
23

34
import lkml
45

@@ -154,6 +155,21 @@
154155
'TIME WITHOUT TIME ZONE': 'string',
155156
# TIMETZ not supported
156157
# TIME WITH TIME ZONE not supported
158+
},
159+
'spark': {
160+
'byte': 'number',
161+
'short': 'number',
162+
'integer': 'number',
163+
'long': 'number',
164+
'float': 'number',
165+
'double': 'number',
166+
'decimal': 'number',
167+
'string': 'string',
168+
'varchar': 'string',
169+
'char': 'string',
170+
'boolean': 'yesno',
171+
'timestamp': 'timestamp',
172+
'date': 'datetime',
157173
}
158174
}
159175

@@ -172,8 +188,13 @@
172188
]
173189

174190

191+
def normalise_spark_types(column_type: str) -> str:
192+
return re.match(r'^[^\(]*', column_type)
193+
194+
175195
def map_adapter_type_to_looker(adapter_type: models.SupportedDbtAdapters, column_type: str):
176-
looker_type = LOOKER_DTYPE_MAP[adapter_type].get(column_type)
196+
normalised_column_type = normalise_spark_types(column_type) if adapter_type == models.SupportedDbtAdapters.spark.value else column_type
197+
looker_type = LOOKER_DTYPE_MAP[adapter_type].get(normalised_column_type)
177198
if (column_type is not None) and (looker_type is None):
178199
logging.warning(f'Column type {column_type} not supported for conversion from {adapter_type} to looker. No dimension will be created.')
179200
return looker_type
@@ -282,7 +303,7 @@ def lookml_view_from_dbt_model(model: models.DbtModel, adapter_type: models.Supp
282303
lookml = {
283304
'view': {
284305
'name': model.name,
285-
'sql_table_name': f'{model.database}.{model.db_schema}.{model.name}',
306+
'sql_table_name': model.relation_name,
286307
'dimension_groups': lookml_dimension_groups_from_model(model, adapter_type),
287308
'dimensions': lookml_dimensions_from_model(model, adapter_type),
288309
'measures': lookml_measures_from_model(model),

dbt2looker/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class SupportedDbtAdapters(str, Enum):
1818
postgres = 'postgres'
1919
redshift = 'redshift'
2020
snowflake = 'snowflake'
21+
spark = 'spark'
2122

2223

2324
# Lookml types
@@ -152,7 +153,7 @@ class DbtModelMeta(Dbt2LookerModelMeta):
152153

153154
class DbtModel(DbtNode):
154155
resource_type: Literal['model']
155-
database: str
156+
relation_name: str
156157
db_schema: str = Field(..., alias='schema')
157158
name: str
158159
description: str
@@ -187,7 +188,6 @@ class DbtManifest(BaseModel):
187188

188189
class DbtCatalogNodeMetadata(BaseModel):
189190
type: str
190-
database: str
191191
db_schema: str = Field(..., alias='schema')
192192
name: str
193193
comment: Optional[str]

dbt2looker/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def parse_typed_models(raw_manifest: dict, raw_catalog: dict, tag: Optional[str]
8787
if model.unique_id not in catalog_nodes:
8888
logging.warning(
8989
f'Model {model.unique_id} not found in catalog. No looker view will be generated. '
90-
f'Check if model has materialized in {adapter_type} at {model.database}.{model.db_schema}.{model.name}')
90+
f'Check if model has materialized in {adapter_type} at {model.relation_name}')
9191

9292
# Update dbt models with data types from catalog
9393
dbt_typed_models = [

0 commit comments

Comments
 (0)