Skip to content

Commit

Permalink
fix: mermaid complex types (#119)
Browse files Browse the repository at this point in the history
* fix: match outermost parent type with deeper nested types

Simplifying the regex expression.

Previously from `a<b<c d, e f>>` it would ignore `a` and capture `b`, `c d` and `, e f`.
Now it captures `a` and `b<c d, e f>`, which is disregarded as far as
I can see.

* feat: add test_mermaid_column_types

* Revert "fix: match outermost parent type with deeper nested types"

This reverts commit 3b9d1ee.

* Revert "Revert "fix: match outermost parent type with deeper nested types""

This reverts commit 78d2891.

* chore: formatting
  • Loading branch information
cobac authored Jul 17, 2024
1 parent eae4f9b commit 1855328
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dbterd/adapters/targets/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def match_complex_column_type(column_type: str) -> Optional[str]:
Returns:
Optional[str]: Returns root type if input type is nested complex type, otherwise returns `None` for primitive types
"""
pattern = r"(\w+)<(\w+\s+\w+(\s*,\s*\w+\s+\w+)*)>"
pattern = r"(\w+)<.*>"
match = re.match(pattern, column_type)
if match:
return match.group(1)
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/adapters/targets/mermaid/test_mermaid_column_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from dbterd.adapters.targets import mermaid

complex_column_types = [
("string", None),
("struct<string a, string b>", "struct"),
("array<struct<string a, string b>>", "array"),
("array<struct<string a_id, string b_id>>", "array"),
]
column_types = [
("string", "string"),
("struct<string a, string b>", "struct[OMITTED]"),
("array<struct<string a, string b>>", "array[OMITTED]"),
("array<struct<string a_id, string b_id>>", "array[OMITTED]"),
]


@pytest.mark.parametrize("input,expected", complex_column_types)
def test_match_complex_column_type(input, expected):
assert mermaid.match_complex_column_type(input) == expected


@pytest.mark.parametrize("input,expected", column_types)
def test_replace_column_type(input, expected):
assert mermaid.replace_column_type(input) == expected

0 comments on commit 1855328

Please sign in to comment.