Skip to content

Commit

Permalink
Update generator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mycaule authored and Michel Hua committed Nov 9, 2023
1 parent 7948cc2 commit 15ad7de
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions dbt2looker/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
'DECIMAL': 'number',
'CHAR': 'string',
'VARCHAR': 'string',
'VARCHAR(29)': 'string',
'STRING': 'string',
'DATE': 'datetime',
'TIMESTAMP': 'timestamp',
Expand All @@ -213,14 +212,20 @@
]


def normalise_spark_types(column_type: str) -> str:
return re.match(r'^[^\(]*', column_type).group(0)
def normalise_types(adapter_type: models.SupportedDbtAdapters, column_type: str) -> str:
if column_type is None:
return ""
elif (adapter_type == models.SupportedDbtAdapters.spark.value
or adapter_type == models.SupportedDbtAdapters.athena.value):
return re.match(r'^[^\(]*', column_type).group(0)
else:
return column_type


def map_adapter_type_to_looker(adapter_type: models.SupportedDbtAdapters, column_type: str):
normalised_column_type = (normalise_spark_types(column_type) if adapter_type == models.SupportedDbtAdapters.spark.value else column_type or "").upper()
normalised_column_type = normalise_types(adapter_type, column_type).upper()
looker_type = LOOKER_DTYPE_MAP[adapter_type].get(normalised_column_type)
if (column_type is not None) and (looker_type is None):
if looker_type is None:
logging.warning(f'Column type {column_type} not supported for conversion from {adapter_type} to looker. No dimension will be created.')
return looker_type

Expand Down

0 comments on commit 15ad7de

Please sign in to comment.