Skip to content

Commit

Permalink
fix(ingestion): correct trino datatype handling (#5541)
Browse files Browse the repository at this point in the history
Co-authored-by: Ravindra Lanka <rlanka@acryl.io>
  • Loading branch information
ms32035 and rslanka authored Aug 4, 2022
1 parent 9a3ee1c commit fa42b59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ def resolve_postgres_modified_type(type_string: str) -> Any:


def resolve_trino_modified_type(type_string: str) -> Any:
# for cases like timestamp(3)
if re.match(r"[a-zA-Z]+\([0-9]+\)", type_string):
modified_type_base = re.match(r"([a-zA-Z]+)\([0-9]+\)", type_string).group(1) # type: ignore
# for cases like timestamp(3), decimal(10,0), row(...)
match = re.match(r"([a-zA-Z]+)\(.+\)", type_string)
if match:
modified_type_base: str = match.group(1)
return TRINO_SQL_TYPES_MAP[modified_type_base]
else:
return TRINO_SQL_TYPES_MAP[type_string]
Expand Down Expand Up @@ -337,4 +338,5 @@ def resolve_trino_modified_type(type_string: str) -> Any:
"date": DateType,
"time": TimeType,
"timestamp": TimeType,
"row": RecordType,
}
19 changes: 18 additions & 1 deletion metadata-ingestion/tests/integration/dbt/test_dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,25 @@ def test_dbt_stateful_tests(pytestconfig, tmp_path, mock_time, mock_datahub_grap
@pytest.mark.parametrize(
"data_type, expected_data_type",
[
("timestamp(3)", "timestamp"),
("boolean", "boolean"),
("tinyint", "tinyint"),
("smallint", "smallint"),
("int", "int"),
("integer", "integer"),
("bigint", "bigint"),
("real", "real"),
("double", "double"),
("decimal(10,0)", "decimal"),
("varchar(20)", "varchar"),
("char", "char"),
("varbinary", "varbinary"),
("json", "json"),
("date", "date"),
("time", "time"),
("time(12)", "time"),
("timestamp", "timestamp"),
("timestamp(3)", "timestamp"),
("row(x bigint, y double)", "row"),
],
)
def test_resolve_trino_modified_type(data_type, expected_data_type):
Expand Down

0 comments on commit fa42b59

Please sign in to comment.